panel.c 61 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438
  1. /*
  2. * Front panel driver for Linux
  3. * Copyright (C) 2000-2008, Willy Tarreau <w@1wt.eu>
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License
  7. * as published by the Free Software Foundation; either version
  8. * 2 of the License, or (at your option) any later version.
  9. *
  10. * This code drives an LCD module (/dev/lcd), and a keypad (/dev/keypad)
  11. * connected to a parallel printer port.
  12. *
  13. * The LCD module may either be an HD44780-like 8-bit parallel LCD, or a 1-bit
  14. * serial module compatible with Samsung's KS0074. The pins may be connected in
  15. * any combination, everything is programmable.
  16. *
  17. * The keypad consists in a matrix of push buttons connecting input pins to
  18. * data output pins or to the ground. The combinations have to be hard-coded
  19. * in the driver, though several profiles exist and adding new ones is easy.
  20. *
  21. * Several profiles are provided for commonly found LCD+keypad modules on the
  22. * market, such as those found in Nexcom's appliances.
  23. *
  24. * FIXME:
  25. * - the initialization/deinitialization process is very dirty and should
  26. * be rewritten. It may even be buggy.
  27. *
  28. * TODO:
  29. * - document 24 keys keyboard (3 rows of 8 cols, 32 diodes + 2 inputs)
  30. * - make the LCD a part of a virtual screen of Vx*Vy
  31. * - make the inputs list smp-safe
  32. * - change the keyboard to a double mapping : signals -> key_id -> values
  33. * so that applications can change values without knowing signals
  34. *
  35. */
  36. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  37. #include <linux/module.h>
  38. #include <linux/types.h>
  39. #include <linux/errno.h>
  40. #include <linux/signal.h>
  41. #include <linux/sched.h>
  42. #include <linux/spinlock.h>
  43. #include <linux/interrupt.h>
  44. #include <linux/miscdevice.h>
  45. #include <linux/slab.h>
  46. #include <linux/ioport.h>
  47. #include <linux/fcntl.h>
  48. #include <linux/init.h>
  49. #include <linux/delay.h>
  50. #include <linux/kernel.h>
  51. #include <linux/ctype.h>
  52. #include <linux/parport.h>
  53. #include <linux/list.h>
  54. #include <linux/notifier.h>
  55. #include <linux/reboot.h>
  56. #include <generated/utsrelease.h>
  57. #include <linux/io.h>
  58. #include <linux/uaccess.h>
  59. #define LCD_MINOR 156
  60. #define KEYPAD_MINOR 185
  61. #define PANEL_VERSION "0.9.5"
  62. #define LCD_MAXBYTES 256 /* max burst write */
  63. #define KEYPAD_BUFFER 64
  64. /* poll the keyboard this every second */
  65. #define INPUT_POLL_TIME (HZ / 50)
  66. /* a key starts to repeat after this times INPUT_POLL_TIME */
  67. #define KEYPAD_REP_START (10)
  68. /* a key repeats this times INPUT_POLL_TIME */
  69. #define KEYPAD_REP_DELAY (2)
  70. /* keep the light on this times INPUT_POLL_TIME for each flash */
  71. #define FLASH_LIGHT_TEMPO (200)
  72. /* converts an r_str() input to an active high, bits string : 000BAOSE */
  73. #define PNL_PINPUT(a) ((((unsigned char)(a)) ^ 0x7F) >> 3)
  74. #define PNL_PBUSY 0x80 /* inverted input, active low */
  75. #define PNL_PACK 0x40 /* direct input, active low */
  76. #define PNL_POUTPA 0x20 /* direct input, active high */
  77. #define PNL_PSELECD 0x10 /* direct input, active high */
  78. #define PNL_PERRORP 0x08 /* direct input, active low */
  79. #define PNL_PBIDIR 0x20 /* bi-directional ports */
  80. /* high to read data in or-ed with data out */
  81. #define PNL_PINTEN 0x10
  82. #define PNL_PSELECP 0x08 /* inverted output, active low */
  83. #define PNL_PINITP 0x04 /* direct output, active low */
  84. #define PNL_PAUTOLF 0x02 /* inverted output, active low */
  85. #define PNL_PSTROBE 0x01 /* inverted output */
  86. #define PNL_PD0 0x01
  87. #define PNL_PD1 0x02
  88. #define PNL_PD2 0x04
  89. #define PNL_PD3 0x08
  90. #define PNL_PD4 0x10
  91. #define PNL_PD5 0x20
  92. #define PNL_PD6 0x40
  93. #define PNL_PD7 0x80
  94. #define PIN_NONE 0
  95. #define PIN_STROBE 1
  96. #define PIN_D0 2
  97. #define PIN_D1 3
  98. #define PIN_D2 4
  99. #define PIN_D3 5
  100. #define PIN_D4 6
  101. #define PIN_D5 7
  102. #define PIN_D6 8
  103. #define PIN_D7 9
  104. #define PIN_AUTOLF 14
  105. #define PIN_INITP 16
  106. #define PIN_SELECP 17
  107. #define PIN_NOT_SET 127
  108. #define LCD_FLAG_S 0x0001
  109. #define LCD_FLAG_ID 0x0002
  110. #define LCD_FLAG_B 0x0004 /* blink on */
  111. #define LCD_FLAG_C 0x0008 /* cursor on */
  112. #define LCD_FLAG_D 0x0010 /* display on */
  113. #define LCD_FLAG_F 0x0020 /* large font mode */
  114. #define LCD_FLAG_N 0x0040 /* 2-rows mode */
  115. #define LCD_FLAG_L 0x0080 /* backlight enabled */
  116. /* LCD commands */
  117. #define LCD_CMD_DISPLAY_CLEAR 0x01 /* Clear entire display */
  118. #define LCD_CMD_ENTRY_MODE 0x04 /* Set entry mode */
  119. #define LCD_CMD_CURSOR_INC 0x02 /* Increment cursor */
  120. #define LCD_CMD_DISPLAY_CTRL 0x08 /* Display control */
  121. #define LCD_CMD_DISPLAY_ON 0x04 /* Set display on */
  122. #define LCD_CMD_CURSOR_ON 0x02 /* Set cursor on */
  123. #define LCD_CMD_BLINK_ON 0x01 /* Set blink on */
  124. #define LCD_CMD_SHIFT 0x10 /* Shift cursor/display */
  125. #define LCD_CMD_DISPLAY_SHIFT 0x08 /* Shift display instead of cursor */
  126. #define LCD_CMD_SHIFT_RIGHT 0x04 /* Shift display/cursor to the right */
  127. #define LCD_CMD_FUNCTION_SET 0x20 /* Set function */
  128. #define LCD_CMD_DATA_LEN_8BITS 0x10 /* Set data length to 8 bits */
  129. #define LCD_CMD_TWO_LINES 0x08 /* Set to two display lines */
  130. #define LCD_CMD_FONT_5X10_DOTS 0x04 /* Set char font to 5x10 dots */
  131. #define LCD_CMD_SET_CGRAM_ADDR 0x40 /* Set char generator RAM address */
  132. #define LCD_CMD_SET_DDRAM_ADDR 0x80 /* Set display data RAM address */
  133. #define LCD_ESCAPE_LEN 24 /* max chars for LCD escape command */
  134. #define LCD_ESCAPE_CHAR 27 /* use char 27 for escape command */
  135. #define NOT_SET -1
  136. /* macros to simplify use of the parallel port */
  137. #define r_ctr(x) (parport_read_control((x)->port))
  138. #define r_dtr(x) (parport_read_data((x)->port))
  139. #define r_str(x) (parport_read_status((x)->port))
  140. #define w_ctr(x, y) (parport_write_control((x)->port, (y)))
  141. #define w_dtr(x, y) (parport_write_data((x)->port, (y)))
  142. /* this defines which bits are to be used and which ones to be ignored */
  143. /* logical or of the output bits involved in the scan matrix */
  144. static __u8 scan_mask_o;
  145. /* logical or of the input bits involved in the scan matrix */
  146. static __u8 scan_mask_i;
  147. enum input_type {
  148. INPUT_TYPE_STD,
  149. INPUT_TYPE_KBD,
  150. };
  151. enum input_state {
  152. INPUT_ST_LOW,
  153. INPUT_ST_RISING,
  154. INPUT_ST_HIGH,
  155. INPUT_ST_FALLING,
  156. };
  157. struct logical_input {
  158. struct list_head list;
  159. __u64 mask;
  160. __u64 value;
  161. enum input_type type;
  162. enum input_state state;
  163. __u8 rise_time, fall_time;
  164. __u8 rise_timer, fall_timer, high_timer;
  165. union {
  166. struct { /* valid when type == INPUT_TYPE_STD */
  167. void (*press_fct)(int);
  168. void (*release_fct)(int);
  169. int press_data;
  170. int release_data;
  171. } std;
  172. struct { /* valid when type == INPUT_TYPE_KBD */
  173. /* strings can be non null-terminated */
  174. char press_str[sizeof(void *) + sizeof(int)];
  175. char repeat_str[sizeof(void *) + sizeof(int)];
  176. char release_str[sizeof(void *) + sizeof(int)];
  177. } kbd;
  178. } u;
  179. };
  180. static LIST_HEAD(logical_inputs); /* list of all defined logical inputs */
  181. /* physical contacts history
  182. * Physical contacts are a 45 bits string of 9 groups of 5 bits each.
  183. * The 8 lower groups correspond to output bits 0 to 7, and the 9th group
  184. * corresponds to the ground.
  185. * Within each group, bits are stored in the same order as read on the port :
  186. * BAPSE (busy=4, ack=3, paper empty=2, select=1, error=0).
  187. * So, each __u64 is represented like this :
  188. * 0000000000000000000BAPSEBAPSEBAPSEBAPSEBAPSEBAPSEBAPSEBAPSEBAPSE
  189. * <-----unused------><gnd><d07><d06><d05><d04><d03><d02><d01><d00>
  190. */
  191. /* what has just been read from the I/O ports */
  192. static __u64 phys_read;
  193. /* previous phys_read */
  194. static __u64 phys_read_prev;
  195. /* stabilized phys_read (phys_read|phys_read_prev) */
  196. static __u64 phys_curr;
  197. /* previous phys_curr */
  198. static __u64 phys_prev;
  199. /* 0 means that at least one logical signal needs be computed */
  200. static char inputs_stable;
  201. /* these variables are specific to the keypad */
  202. static struct {
  203. bool enabled;
  204. } keypad;
  205. static char keypad_buffer[KEYPAD_BUFFER];
  206. static int keypad_buflen;
  207. static int keypad_start;
  208. static char keypressed;
  209. static wait_queue_head_t keypad_read_wait;
  210. /* lcd-specific variables */
  211. static struct {
  212. bool enabled;
  213. bool initialized;
  214. bool must_clear;
  215. int height;
  216. int width;
  217. int bwidth;
  218. int hwidth;
  219. int charset;
  220. int proto;
  221. int light_tempo;
  222. /* TODO: use union here? */
  223. struct {
  224. int e;
  225. int rs;
  226. int rw;
  227. int cl;
  228. int da;
  229. int bl;
  230. } pins;
  231. /* contains the LCD config state */
  232. unsigned long int flags;
  233. /* Contains the LCD X and Y offset */
  234. struct {
  235. unsigned long int x;
  236. unsigned long int y;
  237. } addr;
  238. /* Current escape sequence and it's length or -1 if outside */
  239. struct {
  240. char buf[LCD_ESCAPE_LEN + 1];
  241. int len;
  242. } esc_seq;
  243. } lcd;
  244. /* Needed only for init */
  245. static int selected_lcd_type = NOT_SET;
  246. /*
  247. * Bit masks to convert LCD signals to parallel port outputs.
  248. * _d_ are values for data port, _c_ are for control port.
  249. * [0] = signal OFF, [1] = signal ON, [2] = mask
  250. */
  251. #define BIT_CLR 0
  252. #define BIT_SET 1
  253. #define BIT_MSK 2
  254. #define BIT_STATES 3
  255. /*
  256. * one entry for each bit on the LCD
  257. */
  258. #define LCD_BIT_E 0
  259. #define LCD_BIT_RS 1
  260. #define LCD_BIT_RW 2
  261. #define LCD_BIT_BL 3
  262. #define LCD_BIT_CL 4
  263. #define LCD_BIT_DA 5
  264. #define LCD_BITS 6
  265. /*
  266. * each bit can be either connected to a DATA or CTRL port
  267. */
  268. #define LCD_PORT_C 0
  269. #define LCD_PORT_D 1
  270. #define LCD_PORTS 2
  271. static unsigned char lcd_bits[LCD_PORTS][LCD_BITS][BIT_STATES];
  272. /*
  273. * LCD protocols
  274. */
  275. #define LCD_PROTO_PARALLEL 0
  276. #define LCD_PROTO_SERIAL 1
  277. #define LCD_PROTO_TI_DA8XX_LCD 2
  278. /*
  279. * LCD character sets
  280. */
  281. #define LCD_CHARSET_NORMAL 0
  282. #define LCD_CHARSET_KS0074 1
  283. /*
  284. * LCD types
  285. */
  286. #define LCD_TYPE_NONE 0
  287. #define LCD_TYPE_CUSTOM 1
  288. #define LCD_TYPE_OLD 2
  289. #define LCD_TYPE_KS0074 3
  290. #define LCD_TYPE_HANTRONIX 4
  291. #define LCD_TYPE_NEXCOM 5
  292. /*
  293. * keypad types
  294. */
  295. #define KEYPAD_TYPE_NONE 0
  296. #define KEYPAD_TYPE_OLD 1
  297. #define KEYPAD_TYPE_NEW 2
  298. #define KEYPAD_TYPE_NEXCOM 3
  299. /*
  300. * panel profiles
  301. */
  302. #define PANEL_PROFILE_CUSTOM 0
  303. #define PANEL_PROFILE_OLD 1
  304. #define PANEL_PROFILE_NEW 2
  305. #define PANEL_PROFILE_HANTRONIX 3
  306. #define PANEL_PROFILE_NEXCOM 4
  307. #define PANEL_PROFILE_LARGE 5
  308. /*
  309. * Construct custom config from the kernel's configuration
  310. */
  311. #define DEFAULT_PARPORT 0
  312. #define DEFAULT_PROFILE PANEL_PROFILE_LARGE
  313. #define DEFAULT_KEYPAD_TYPE KEYPAD_TYPE_OLD
  314. #define DEFAULT_LCD_TYPE LCD_TYPE_OLD
  315. #define DEFAULT_LCD_HEIGHT 2
  316. #define DEFAULT_LCD_WIDTH 40
  317. #define DEFAULT_LCD_BWIDTH 40
  318. #define DEFAULT_LCD_HWIDTH 64
  319. #define DEFAULT_LCD_CHARSET LCD_CHARSET_NORMAL
  320. #define DEFAULT_LCD_PROTO LCD_PROTO_PARALLEL
  321. #define DEFAULT_LCD_PIN_E PIN_AUTOLF
  322. #define DEFAULT_LCD_PIN_RS PIN_SELECP
  323. #define DEFAULT_LCD_PIN_RW PIN_INITP
  324. #define DEFAULT_LCD_PIN_SCL PIN_STROBE
  325. #define DEFAULT_LCD_PIN_SDA PIN_D0
  326. #define DEFAULT_LCD_PIN_BL PIN_NOT_SET
  327. #ifdef CONFIG_PANEL_PARPORT
  328. #undef DEFAULT_PARPORT
  329. #define DEFAULT_PARPORT CONFIG_PANEL_PARPORT
  330. #endif
  331. #ifdef CONFIG_PANEL_PROFILE
  332. #undef DEFAULT_PROFILE
  333. #define DEFAULT_PROFILE CONFIG_PANEL_PROFILE
  334. #endif
  335. #if DEFAULT_PROFILE == 0 /* custom */
  336. #ifdef CONFIG_PANEL_KEYPAD
  337. #undef DEFAULT_KEYPAD_TYPE
  338. #define DEFAULT_KEYPAD_TYPE CONFIG_PANEL_KEYPAD
  339. #endif
  340. #ifdef CONFIG_PANEL_LCD
  341. #undef DEFAULT_LCD_TYPE
  342. #define DEFAULT_LCD_TYPE CONFIG_PANEL_LCD
  343. #endif
  344. #ifdef CONFIG_PANEL_LCD_HEIGHT
  345. #undef DEFAULT_LCD_HEIGHT
  346. #define DEFAULT_LCD_HEIGHT CONFIG_PANEL_LCD_HEIGHT
  347. #endif
  348. #ifdef CONFIG_PANEL_LCD_WIDTH
  349. #undef DEFAULT_LCD_WIDTH
  350. #define DEFAULT_LCD_WIDTH CONFIG_PANEL_LCD_WIDTH
  351. #endif
  352. #ifdef CONFIG_PANEL_LCD_BWIDTH
  353. #undef DEFAULT_LCD_BWIDTH
  354. #define DEFAULT_LCD_BWIDTH CONFIG_PANEL_LCD_BWIDTH
  355. #endif
  356. #ifdef CONFIG_PANEL_LCD_HWIDTH
  357. #undef DEFAULT_LCD_HWIDTH
  358. #define DEFAULT_LCD_HWIDTH CONFIG_PANEL_LCD_HWIDTH
  359. #endif
  360. #ifdef CONFIG_PANEL_LCD_CHARSET
  361. #undef DEFAULT_LCD_CHARSET
  362. #define DEFAULT_LCD_CHARSET CONFIG_PANEL_LCD_CHARSET
  363. #endif
  364. #ifdef CONFIG_PANEL_LCD_PROTO
  365. #undef DEFAULT_LCD_PROTO
  366. #define DEFAULT_LCD_PROTO CONFIG_PANEL_LCD_PROTO
  367. #endif
  368. #ifdef CONFIG_PANEL_LCD_PIN_E
  369. #undef DEFAULT_LCD_PIN_E
  370. #define DEFAULT_LCD_PIN_E CONFIG_PANEL_LCD_PIN_E
  371. #endif
  372. #ifdef CONFIG_PANEL_LCD_PIN_RS
  373. #undef DEFAULT_LCD_PIN_RS
  374. #define DEFAULT_LCD_PIN_RS CONFIG_PANEL_LCD_PIN_RS
  375. #endif
  376. #ifdef CONFIG_PANEL_LCD_PIN_RW
  377. #undef DEFAULT_LCD_PIN_RW
  378. #define DEFAULT_LCD_PIN_RW CONFIG_PANEL_LCD_PIN_RW
  379. #endif
  380. #ifdef CONFIG_PANEL_LCD_PIN_SCL
  381. #undef DEFAULT_LCD_PIN_SCL
  382. #define DEFAULT_LCD_PIN_SCL CONFIG_PANEL_LCD_PIN_SCL
  383. #endif
  384. #ifdef CONFIG_PANEL_LCD_PIN_SDA
  385. #undef DEFAULT_LCD_PIN_SDA
  386. #define DEFAULT_LCD_PIN_SDA CONFIG_PANEL_LCD_PIN_SDA
  387. #endif
  388. #ifdef CONFIG_PANEL_LCD_PIN_BL
  389. #undef DEFAULT_LCD_PIN_BL
  390. #define DEFAULT_LCD_PIN_BL CONFIG_PANEL_LCD_PIN_BL
  391. #endif
  392. #endif /* DEFAULT_PROFILE == 0 */
  393. /* global variables */
  394. /* Device single-open policy control */
  395. static atomic_t lcd_available = ATOMIC_INIT(1);
  396. static atomic_t keypad_available = ATOMIC_INIT(1);
  397. static struct pardevice *pprt;
  398. static int keypad_initialized;
  399. static void (*lcd_write_cmd)(int);
  400. static void (*lcd_write_data)(int);
  401. static void (*lcd_clear_fast)(void);
  402. static DEFINE_SPINLOCK(pprt_lock);
  403. static struct timer_list scan_timer;
  404. MODULE_DESCRIPTION("Generic parallel port LCD/Keypad driver");
  405. static int parport = DEFAULT_PARPORT;
  406. module_param(parport, int, 0000);
  407. MODULE_PARM_DESC(parport, "Parallel port index (0=lpt1, 1=lpt2, ...)");
  408. static int profile = DEFAULT_PROFILE;
  409. module_param(profile, int, 0000);
  410. MODULE_PARM_DESC(profile,
  411. "1=16x2 old kp; 2=serial 16x2, new kp; 3=16x2 hantronix; "
  412. "4=16x2 nexcom; default=40x2, old kp");
  413. static int keypad_type = NOT_SET;
  414. module_param(keypad_type, int, 0000);
  415. MODULE_PARM_DESC(keypad_type,
  416. "Keypad type: 0=none, 1=old 6 keys, 2=new 6+1 keys, 3=nexcom 4 keys");
  417. static int lcd_type = NOT_SET;
  418. module_param(lcd_type, int, 0000);
  419. MODULE_PARM_DESC(lcd_type,
  420. "LCD type: 0=none, 1=compiled-in, 2=old, 3=serial ks0074, 4=hantronix, 5=nexcom");
  421. static int lcd_height = NOT_SET;
  422. module_param(lcd_height, int, 0000);
  423. MODULE_PARM_DESC(lcd_height, "Number of lines on the LCD");
  424. static int lcd_width = NOT_SET;
  425. module_param(lcd_width, int, 0000);
  426. MODULE_PARM_DESC(lcd_width, "Number of columns on the LCD");
  427. static int lcd_bwidth = NOT_SET; /* internal buffer width (usually 40) */
  428. module_param(lcd_bwidth, int, 0000);
  429. MODULE_PARM_DESC(lcd_bwidth, "Internal LCD line width (40)");
  430. static int lcd_hwidth = NOT_SET; /* hardware buffer width (usually 64) */
  431. module_param(lcd_hwidth, int, 0000);
  432. MODULE_PARM_DESC(lcd_hwidth, "LCD line hardware address (64)");
  433. static int lcd_charset = NOT_SET;
  434. module_param(lcd_charset, int, 0000);
  435. MODULE_PARM_DESC(lcd_charset, "LCD character set: 0=standard, 1=KS0074");
  436. static int lcd_proto = NOT_SET;
  437. module_param(lcd_proto, int, 0000);
  438. MODULE_PARM_DESC(lcd_proto,
  439. "LCD communication: 0=parallel (//), 1=serial, 2=TI LCD Interface");
  440. /*
  441. * These are the parallel port pins the LCD control signals are connected to.
  442. * Set this to 0 if the signal is not used. Set it to its opposite value
  443. * (negative) if the signal is negated. -MAXINT is used to indicate that the
  444. * pin has not been explicitly specified.
  445. *
  446. * WARNING! no check will be performed about collisions with keypad !
  447. */
  448. static int lcd_e_pin = PIN_NOT_SET;
  449. module_param(lcd_e_pin, int, 0000);
  450. MODULE_PARM_DESC(lcd_e_pin,
  451. "# of the // port pin connected to LCD 'E' signal, with polarity (-17..17)");
  452. static int lcd_rs_pin = PIN_NOT_SET;
  453. module_param(lcd_rs_pin, int, 0000);
  454. MODULE_PARM_DESC(lcd_rs_pin,
  455. "# of the // port pin connected to LCD 'RS' signal, with polarity (-17..17)");
  456. static int lcd_rw_pin = PIN_NOT_SET;
  457. module_param(lcd_rw_pin, int, 0000);
  458. MODULE_PARM_DESC(lcd_rw_pin,
  459. "# of the // port pin connected to LCD 'RW' signal, with polarity (-17..17)");
  460. static int lcd_cl_pin = PIN_NOT_SET;
  461. module_param(lcd_cl_pin, int, 0000);
  462. MODULE_PARM_DESC(lcd_cl_pin,
  463. "# of the // port pin connected to serial LCD 'SCL' signal, with polarity (-17..17)");
  464. static int lcd_da_pin = PIN_NOT_SET;
  465. module_param(lcd_da_pin, int, 0000);
  466. MODULE_PARM_DESC(lcd_da_pin,
  467. "# of the // port pin connected to serial LCD 'SDA' signal, with polarity (-17..17)");
  468. static int lcd_bl_pin = PIN_NOT_SET;
  469. module_param(lcd_bl_pin, int, 0000);
  470. MODULE_PARM_DESC(lcd_bl_pin,
  471. "# of the // port pin connected to LCD backlight, with polarity (-17..17)");
  472. /* Deprecated module parameters - consider not using them anymore */
  473. static int lcd_enabled = NOT_SET;
  474. module_param(lcd_enabled, int, 0000);
  475. MODULE_PARM_DESC(lcd_enabled, "Deprecated option, use lcd_type instead");
  476. static int keypad_enabled = NOT_SET;
  477. module_param(keypad_enabled, int, 0000);
  478. MODULE_PARM_DESC(keypad_enabled, "Deprecated option, use keypad_type instead");
  479. static const unsigned char *lcd_char_conv;
  480. /* for some LCD drivers (ks0074) we need a charset conversion table. */
  481. static const unsigned char lcd_char_conv_ks0074[256] = {
  482. /* 0|8 1|9 2|A 3|B 4|C 5|D 6|E 7|F */
  483. /* 0x00 */ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  484. /* 0x08 */ 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
  485. /* 0x10 */ 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
  486. /* 0x18 */ 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
  487. /* 0x20 */ 0x20, 0x21, 0x22, 0x23, 0xa2, 0x25, 0x26, 0x27,
  488. /* 0x28 */ 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
  489. /* 0x30 */ 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  490. /* 0x38 */ 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f,
  491. /* 0x40 */ 0xa0, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47,
  492. /* 0x48 */ 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f,
  493. /* 0x50 */ 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
  494. /* 0x58 */ 0x58, 0x59, 0x5a, 0xfa, 0xfb, 0xfc, 0x1d, 0xc4,
  495. /* 0x60 */ 0x96, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67,
  496. /* 0x68 */ 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f,
  497. /* 0x70 */ 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77,
  498. /* 0x78 */ 0x78, 0x79, 0x7a, 0xfd, 0xfe, 0xff, 0xce, 0x20,
  499. /* 0x80 */ 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
  500. /* 0x88 */ 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,
  501. /* 0x90 */ 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97,
  502. /* 0x98 */ 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f,
  503. /* 0xA0 */ 0x20, 0x40, 0xb1, 0xa1, 0x24, 0xa3, 0xfe, 0x5f,
  504. /* 0xA8 */ 0x22, 0xc8, 0x61, 0x14, 0x97, 0x2d, 0xad, 0x96,
  505. /* 0xB0 */ 0x80, 0x8c, 0x82, 0x83, 0x27, 0x8f, 0x86, 0xdd,
  506. /* 0xB8 */ 0x2c, 0x81, 0x6f, 0x15, 0x8b, 0x8a, 0x84, 0x60,
  507. /* 0xC0 */ 0xe2, 0xe2, 0xe2, 0x5b, 0x5b, 0xae, 0xbc, 0xa9,
  508. /* 0xC8 */ 0xc5, 0xbf, 0xc6, 0xf1, 0xe3, 0xe3, 0xe3, 0xe3,
  509. /* 0xD0 */ 0x44, 0x5d, 0xa8, 0xe4, 0xec, 0xec, 0x5c, 0x78,
  510. /* 0xD8 */ 0xab, 0xa6, 0xe5, 0x5e, 0x5e, 0xe6, 0xaa, 0xbe,
  511. /* 0xE0 */ 0x7f, 0xe7, 0xaf, 0x7b, 0x7b, 0xaf, 0xbd, 0xc8,
  512. /* 0xE8 */ 0xa4, 0xa5, 0xc7, 0xf6, 0xa7, 0xe8, 0x69, 0x69,
  513. /* 0xF0 */ 0xed, 0x7d, 0xa8, 0xe4, 0xec, 0x5c, 0x5c, 0x25,
  514. /* 0xF8 */ 0xac, 0xa6, 0xea, 0xef, 0x7e, 0xeb, 0xb2, 0x79,
  515. };
  516. static const char old_keypad_profile[][4][9] = {
  517. {"S0", "Left\n", "Left\n", ""},
  518. {"S1", "Down\n", "Down\n", ""},
  519. {"S2", "Up\n", "Up\n", ""},
  520. {"S3", "Right\n", "Right\n", ""},
  521. {"S4", "Esc\n", "Esc\n", ""},
  522. {"S5", "Ret\n", "Ret\n", ""},
  523. {"", "", "", ""}
  524. };
  525. /* signals, press, repeat, release */
  526. static const char new_keypad_profile[][4][9] = {
  527. {"S0", "Left\n", "Left\n", ""},
  528. {"S1", "Down\n", "Down\n", ""},
  529. {"S2", "Up\n", "Up\n", ""},
  530. {"S3", "Right\n", "Right\n", ""},
  531. {"S4s5", "", "Esc\n", "Esc\n"},
  532. {"s4S5", "", "Ret\n", "Ret\n"},
  533. {"S4S5", "Help\n", "", ""},
  534. /* add new signals above this line */
  535. {"", "", "", ""}
  536. };
  537. /* signals, press, repeat, release */
  538. static const char nexcom_keypad_profile[][4][9] = {
  539. {"a-p-e-", "Down\n", "Down\n", ""},
  540. {"a-p-E-", "Ret\n", "Ret\n", ""},
  541. {"a-P-E-", "Esc\n", "Esc\n", ""},
  542. {"a-P-e-", "Up\n", "Up\n", ""},
  543. /* add new signals above this line */
  544. {"", "", "", ""}
  545. };
  546. static const char (*keypad_profile)[4][9] = old_keypad_profile;
  547. static DECLARE_BITMAP(bits, LCD_BITS);
  548. static void lcd_get_bits(unsigned int port, int *val)
  549. {
  550. unsigned int bit, state;
  551. for (bit = 0; bit < LCD_BITS; bit++) {
  552. state = test_bit(bit, bits) ? BIT_SET : BIT_CLR;
  553. *val &= lcd_bits[port][bit][BIT_MSK];
  554. *val |= lcd_bits[port][bit][state];
  555. }
  556. }
  557. static void init_scan_timer(void);
  558. /* sets data port bits according to current signals values */
  559. static int set_data_bits(void)
  560. {
  561. int val;
  562. val = r_dtr(pprt);
  563. lcd_get_bits(LCD_PORT_D, &val);
  564. w_dtr(pprt, val);
  565. return val;
  566. }
  567. /* sets ctrl port bits according to current signals values */
  568. static int set_ctrl_bits(void)
  569. {
  570. int val;
  571. val = r_ctr(pprt);
  572. lcd_get_bits(LCD_PORT_C, &val);
  573. w_ctr(pprt, val);
  574. return val;
  575. }
  576. /* sets ctrl & data port bits according to current signals values */
  577. static void panel_set_bits(void)
  578. {
  579. set_data_bits();
  580. set_ctrl_bits();
  581. }
  582. /*
  583. * Converts a parallel port pin (from -25 to 25) to data and control ports
  584. * masks, and data and control port bits. The signal will be considered
  585. * unconnected if it's on pin 0 or an invalid pin (<-25 or >25).
  586. *
  587. * Result will be used this way :
  588. * out(dport, in(dport) & d_val[2] | d_val[signal_state])
  589. * out(cport, in(cport) & c_val[2] | c_val[signal_state])
  590. */
  591. static void pin_to_bits(int pin, unsigned char *d_val, unsigned char *c_val)
  592. {
  593. int d_bit, c_bit, inv;
  594. d_val[0] = 0;
  595. c_val[0] = 0;
  596. d_val[1] = 0;
  597. c_val[1] = 0;
  598. d_val[2] = 0xFF;
  599. c_val[2] = 0xFF;
  600. if (pin == 0)
  601. return;
  602. inv = (pin < 0);
  603. if (inv)
  604. pin = -pin;
  605. d_bit = 0;
  606. c_bit = 0;
  607. switch (pin) {
  608. case PIN_STROBE: /* strobe, inverted */
  609. c_bit = PNL_PSTROBE;
  610. inv = !inv;
  611. break;
  612. case PIN_D0...PIN_D7: /* D0 - D7 = 2 - 9 */
  613. d_bit = 1 << (pin - 2);
  614. break;
  615. case PIN_AUTOLF: /* autofeed, inverted */
  616. c_bit = PNL_PAUTOLF;
  617. inv = !inv;
  618. break;
  619. case PIN_INITP: /* init, direct */
  620. c_bit = PNL_PINITP;
  621. break;
  622. case PIN_SELECP: /* select_in, inverted */
  623. c_bit = PNL_PSELECP;
  624. inv = !inv;
  625. break;
  626. default: /* unknown pin, ignore */
  627. break;
  628. }
  629. if (c_bit) {
  630. c_val[2] &= ~c_bit;
  631. c_val[!inv] = c_bit;
  632. } else if (d_bit) {
  633. d_val[2] &= ~d_bit;
  634. d_val[!inv] = d_bit;
  635. }
  636. }
  637. /* sleeps that many milliseconds with a reschedule */
  638. static void long_sleep(int ms)
  639. {
  640. if (in_interrupt())
  641. mdelay(ms);
  642. else
  643. schedule_timeout_interruptible(msecs_to_jiffies(ms));
  644. }
  645. /*
  646. * send a serial byte to the LCD panel. The caller is responsible for locking
  647. * if needed.
  648. */
  649. static void lcd_send_serial(int byte)
  650. {
  651. int bit;
  652. /*
  653. * the data bit is set on D0, and the clock on STROBE.
  654. * LCD reads D0 on STROBE's rising edge.
  655. */
  656. for (bit = 0; bit < 8; bit++) {
  657. clear_bit(LCD_BIT_CL, bits); /* CLK low */
  658. panel_set_bits();
  659. if (byte & 1) {
  660. set_bit(LCD_BIT_DA, bits);
  661. } else {
  662. clear_bit(LCD_BIT_DA, bits);
  663. }
  664. panel_set_bits();
  665. udelay(2); /* maintain the data during 2 us before CLK up */
  666. set_bit(LCD_BIT_CL, bits); /* CLK high */
  667. panel_set_bits();
  668. udelay(1); /* maintain the strobe during 1 us */
  669. byte >>= 1;
  670. }
  671. }
  672. /* turn the backlight on or off */
  673. static void lcd_backlight(int on)
  674. {
  675. if (lcd.pins.bl == PIN_NONE)
  676. return;
  677. /* The backlight is activated by setting the AUTOFEED line to +5V */
  678. spin_lock_irq(&pprt_lock);
  679. if (on)
  680. set_bit(LCD_BIT_BL, bits);
  681. else
  682. clear_bit(LCD_BIT_BL, bits);
  683. panel_set_bits();
  684. spin_unlock_irq(&pprt_lock);
  685. }
  686. /* send a command to the LCD panel in serial mode */
  687. static void lcd_write_cmd_s(int cmd)
  688. {
  689. spin_lock_irq(&pprt_lock);
  690. lcd_send_serial(0x1F); /* R/W=W, RS=0 */
  691. lcd_send_serial(cmd & 0x0F);
  692. lcd_send_serial((cmd >> 4) & 0x0F);
  693. udelay(40); /* the shortest command takes at least 40 us */
  694. spin_unlock_irq(&pprt_lock);
  695. }
  696. /* send data to the LCD panel in serial mode */
  697. static void lcd_write_data_s(int data)
  698. {
  699. spin_lock_irq(&pprt_lock);
  700. lcd_send_serial(0x5F); /* R/W=W, RS=1 */
  701. lcd_send_serial(data & 0x0F);
  702. lcd_send_serial((data >> 4) & 0x0F);
  703. udelay(40); /* the shortest data takes at least 40 us */
  704. spin_unlock_irq(&pprt_lock);
  705. }
  706. /* send a command to the LCD panel in 8 bits parallel mode */
  707. static void lcd_write_cmd_p8(int cmd)
  708. {
  709. spin_lock_irq(&pprt_lock);
  710. /* present the data to the data port */
  711. w_dtr(pprt, cmd);
  712. udelay(20); /* maintain the data during 20 us before the strobe */
  713. set_bit(LCD_BIT_E, bits);
  714. clear_bit(LCD_BIT_RS, bits);
  715. clear_bit(LCD_BIT_RW, bits);
  716. set_ctrl_bits();
  717. udelay(40); /* maintain the strobe during 40 us */
  718. clear_bit(LCD_BIT_E, bits);
  719. set_ctrl_bits();
  720. udelay(120); /* the shortest command takes at least 120 us */
  721. spin_unlock_irq(&pprt_lock);
  722. }
  723. /* send data to the LCD panel in 8 bits parallel mode */
  724. static void lcd_write_data_p8(int data)
  725. {
  726. spin_lock_irq(&pprt_lock);
  727. /* present the data to the data port */
  728. w_dtr(pprt, data);
  729. udelay(20); /* maintain the data during 20 us before the strobe */
  730. set_bit(LCD_BIT_E, bits);
  731. set_bit(LCD_BIT_RS, bits);
  732. clear_bit(LCD_BIT_RW, bits);
  733. set_ctrl_bits();
  734. udelay(40); /* maintain the strobe during 40 us */
  735. clear_bit(LCD_BIT_E, bits);
  736. set_ctrl_bits();
  737. udelay(45); /* the shortest data takes at least 45 us */
  738. spin_unlock_irq(&pprt_lock);
  739. }
  740. /* send a command to the TI LCD panel */
  741. static void lcd_write_cmd_tilcd(int cmd)
  742. {
  743. spin_lock_irq(&pprt_lock);
  744. /* present the data to the control port */
  745. w_ctr(pprt, cmd);
  746. udelay(60);
  747. spin_unlock_irq(&pprt_lock);
  748. }
  749. /* send data to the TI LCD panel */
  750. static void lcd_write_data_tilcd(int data)
  751. {
  752. spin_lock_irq(&pprt_lock);
  753. /* present the data to the data port */
  754. w_dtr(pprt, data);
  755. udelay(60);
  756. spin_unlock_irq(&pprt_lock);
  757. }
  758. static void lcd_gotoxy(void)
  759. {
  760. lcd_write_cmd(LCD_CMD_SET_DDRAM_ADDR
  761. | (lcd.addr.y ? lcd.hwidth : 0)
  762. /*
  763. * we force the cursor to stay at the end of the
  764. * line if it wants to go farther
  765. */
  766. | ((lcd.addr.x < lcd.bwidth) ? lcd.addr.x &
  767. (lcd.hwidth - 1) : lcd.bwidth - 1));
  768. }
  769. static void lcd_print(char c)
  770. {
  771. if (lcd.addr.x < lcd.bwidth) {
  772. if (lcd_char_conv)
  773. c = lcd_char_conv[(unsigned char)c];
  774. lcd_write_data(c);
  775. lcd.addr.x++;
  776. }
  777. /* prevents the cursor from wrapping onto the next line */
  778. if (lcd.addr.x == lcd.bwidth)
  779. lcd_gotoxy();
  780. }
  781. /* fills the display with spaces and resets X/Y */
  782. static void lcd_clear_fast_s(void)
  783. {
  784. int pos;
  785. lcd.addr.x = 0;
  786. lcd.addr.y = 0;
  787. lcd_gotoxy();
  788. spin_lock_irq(&pprt_lock);
  789. for (pos = 0; pos < lcd.height * lcd.hwidth; pos++) {
  790. lcd_send_serial(0x5F); /* R/W=W, RS=1 */
  791. lcd_send_serial(' ' & 0x0F);
  792. lcd_send_serial((' ' >> 4) & 0x0F);
  793. /* the shortest data takes at least 40 us */
  794. udelay(40);
  795. }
  796. spin_unlock_irq(&pprt_lock);
  797. lcd.addr.x = 0;
  798. lcd.addr.y = 0;
  799. lcd_gotoxy();
  800. }
  801. /* fills the display with spaces and resets X/Y */
  802. static void lcd_clear_fast_p8(void)
  803. {
  804. int pos;
  805. lcd.addr.x = 0;
  806. lcd.addr.y = 0;
  807. lcd_gotoxy();
  808. spin_lock_irq(&pprt_lock);
  809. for (pos = 0; pos < lcd.height * lcd.hwidth; pos++) {
  810. /* present the data to the data port */
  811. w_dtr(pprt, ' ');
  812. /* maintain the data during 20 us before the strobe */
  813. udelay(20);
  814. set_bit(LCD_BIT_E, bits);
  815. set_bit(LCD_BIT_RS, bits);
  816. clear_bit(LCD_BIT_RW, bits);
  817. set_ctrl_bits();
  818. /* maintain the strobe during 40 us */
  819. udelay(40);
  820. clear_bit(LCD_BIT_E, bits);
  821. set_ctrl_bits();
  822. /* the shortest data takes at least 45 us */
  823. udelay(45);
  824. }
  825. spin_unlock_irq(&pprt_lock);
  826. lcd.addr.x = 0;
  827. lcd.addr.y = 0;
  828. lcd_gotoxy();
  829. }
  830. /* fills the display with spaces and resets X/Y */
  831. static void lcd_clear_fast_tilcd(void)
  832. {
  833. int pos;
  834. lcd.addr.x = 0;
  835. lcd.addr.y = 0;
  836. lcd_gotoxy();
  837. spin_lock_irq(&pprt_lock);
  838. for (pos = 0; pos < lcd.height * lcd.hwidth; pos++) {
  839. /* present the data to the data port */
  840. w_dtr(pprt, ' ');
  841. udelay(60);
  842. }
  843. spin_unlock_irq(&pprt_lock);
  844. lcd.addr.x = 0;
  845. lcd.addr.y = 0;
  846. lcd_gotoxy();
  847. }
  848. /* clears the display and resets X/Y */
  849. static void lcd_clear_display(void)
  850. {
  851. lcd_write_cmd(LCD_CMD_DISPLAY_CLEAR);
  852. lcd.addr.x = 0;
  853. lcd.addr.y = 0;
  854. /* we must wait a few milliseconds (15) */
  855. long_sleep(15);
  856. }
  857. static void lcd_init_display(void)
  858. {
  859. lcd.flags = ((lcd.height > 1) ? LCD_FLAG_N : 0)
  860. | LCD_FLAG_D | LCD_FLAG_C | LCD_FLAG_B;
  861. long_sleep(20); /* wait 20 ms after power-up for the paranoid */
  862. /* 8bits, 1 line, small fonts; let's do it 3 times */
  863. lcd_write_cmd(LCD_CMD_FUNCTION_SET | LCD_CMD_DATA_LEN_8BITS);
  864. long_sleep(10);
  865. lcd_write_cmd(LCD_CMD_FUNCTION_SET | LCD_CMD_DATA_LEN_8BITS);
  866. long_sleep(10);
  867. lcd_write_cmd(LCD_CMD_FUNCTION_SET | LCD_CMD_DATA_LEN_8BITS);
  868. long_sleep(10);
  869. /* set font height and lines number */
  870. lcd_write_cmd(LCD_CMD_FUNCTION_SET | LCD_CMD_DATA_LEN_8BITS
  871. | ((lcd.flags & LCD_FLAG_F) ? LCD_CMD_FONT_5X10_DOTS : 0)
  872. | ((lcd.flags & LCD_FLAG_N) ? LCD_CMD_TWO_LINES : 0)
  873. );
  874. long_sleep(10);
  875. /* display off, cursor off, blink off */
  876. lcd_write_cmd(LCD_CMD_DISPLAY_CTRL);
  877. long_sleep(10);
  878. lcd_write_cmd(LCD_CMD_DISPLAY_CTRL /* set display mode */
  879. | ((lcd.flags & LCD_FLAG_D) ? LCD_CMD_DISPLAY_ON : 0)
  880. | ((lcd.flags & LCD_FLAG_C) ? LCD_CMD_CURSOR_ON : 0)
  881. | ((lcd.flags & LCD_FLAG_B) ? LCD_CMD_BLINK_ON : 0)
  882. );
  883. lcd_backlight((lcd.flags & LCD_FLAG_L) ? 1 : 0);
  884. long_sleep(10);
  885. /* entry mode set : increment, cursor shifting */
  886. lcd_write_cmd(LCD_CMD_ENTRY_MODE | LCD_CMD_CURSOR_INC);
  887. lcd_clear_display();
  888. }
  889. /*
  890. * These are the file operation function for user access to /dev/lcd
  891. * This function can also be called from inside the kernel, by
  892. * setting file and ppos to NULL.
  893. *
  894. */
  895. static inline int handle_lcd_special_code(void)
  896. {
  897. /* LCD special codes */
  898. int processed = 0;
  899. char *esc = lcd.esc_seq.buf + 2;
  900. int oldflags = lcd.flags;
  901. /* check for display mode flags */
  902. switch (*esc) {
  903. case 'D': /* Display ON */
  904. lcd.flags |= LCD_FLAG_D;
  905. processed = 1;
  906. break;
  907. case 'd': /* Display OFF */
  908. lcd.flags &= ~LCD_FLAG_D;
  909. processed = 1;
  910. break;
  911. case 'C': /* Cursor ON */
  912. lcd.flags |= LCD_FLAG_C;
  913. processed = 1;
  914. break;
  915. case 'c': /* Cursor OFF */
  916. lcd.flags &= ~LCD_FLAG_C;
  917. processed = 1;
  918. break;
  919. case 'B': /* Blink ON */
  920. lcd.flags |= LCD_FLAG_B;
  921. processed = 1;
  922. break;
  923. case 'b': /* Blink OFF */
  924. lcd.flags &= ~LCD_FLAG_B;
  925. processed = 1;
  926. break;
  927. case '+': /* Back light ON */
  928. lcd.flags |= LCD_FLAG_L;
  929. processed = 1;
  930. break;
  931. case '-': /* Back light OFF */
  932. lcd.flags &= ~LCD_FLAG_L;
  933. processed = 1;
  934. break;
  935. case '*':
  936. /* flash back light using the keypad timer */
  937. if (scan_timer.function) {
  938. if (lcd.light_tempo == 0 &&
  939. ((lcd.flags & LCD_FLAG_L) == 0))
  940. lcd_backlight(1);
  941. lcd.light_tempo = FLASH_LIGHT_TEMPO;
  942. }
  943. processed = 1;
  944. break;
  945. case 'f': /* Small Font */
  946. lcd.flags &= ~LCD_FLAG_F;
  947. processed = 1;
  948. break;
  949. case 'F': /* Large Font */
  950. lcd.flags |= LCD_FLAG_F;
  951. processed = 1;
  952. break;
  953. case 'n': /* One Line */
  954. lcd.flags &= ~LCD_FLAG_N;
  955. processed = 1;
  956. break;
  957. case 'N': /* Two Lines */
  958. lcd.flags |= LCD_FLAG_N;
  959. break;
  960. case 'l': /* Shift Cursor Left */
  961. if (lcd.addr.x > 0) {
  962. /* back one char if not at end of line */
  963. if (lcd.addr.x < lcd.bwidth)
  964. lcd_write_cmd(LCD_CMD_SHIFT);
  965. lcd.addr.x--;
  966. }
  967. processed = 1;
  968. break;
  969. case 'r': /* shift cursor right */
  970. if (lcd.addr.x < lcd.width) {
  971. /* allow the cursor to pass the end of the line */
  972. if (lcd.addr.x < (lcd.bwidth - 1))
  973. lcd_write_cmd(LCD_CMD_SHIFT |
  974. LCD_CMD_SHIFT_RIGHT);
  975. lcd.addr.x++;
  976. }
  977. processed = 1;
  978. break;
  979. case 'L': /* shift display left */
  980. lcd_write_cmd(LCD_CMD_SHIFT | LCD_CMD_DISPLAY_SHIFT);
  981. processed = 1;
  982. break;
  983. case 'R': /* shift display right */
  984. lcd_write_cmd(LCD_CMD_SHIFT | LCD_CMD_DISPLAY_SHIFT |
  985. LCD_CMD_SHIFT_RIGHT);
  986. processed = 1;
  987. break;
  988. case 'k': { /* kill end of line */
  989. int x;
  990. for (x = lcd.addr.x; x < lcd.bwidth; x++)
  991. lcd_write_data(' ');
  992. /* restore cursor position */
  993. lcd_gotoxy();
  994. processed = 1;
  995. break;
  996. }
  997. case 'I': /* reinitialize display */
  998. lcd_init_display();
  999. processed = 1;
  1000. break;
  1001. case 'G': {
  1002. /* Generator : LGcxxxxx...xx; must have <c> between '0'
  1003. * and '7', representing the numerical ASCII code of the
  1004. * redefined character, and <xx...xx> a sequence of 16
  1005. * hex digits representing 8 bytes for each character.
  1006. * Most LCDs will only use 5 lower bits of the 7 first
  1007. * bytes.
  1008. */
  1009. unsigned char cgbytes[8];
  1010. unsigned char cgaddr;
  1011. int cgoffset;
  1012. int shift;
  1013. char value;
  1014. int addr;
  1015. if (!strchr(esc, ';'))
  1016. break;
  1017. esc++;
  1018. cgaddr = *(esc++) - '0';
  1019. if (cgaddr > 7) {
  1020. processed = 1;
  1021. break;
  1022. }
  1023. cgoffset = 0;
  1024. shift = 0;
  1025. value = 0;
  1026. while (*esc && cgoffset < 8) {
  1027. shift ^= 4;
  1028. if (*esc >= '0' && *esc <= '9') {
  1029. value |= (*esc - '0') << shift;
  1030. } else if (*esc >= 'A' && *esc <= 'Z') {
  1031. value |= (*esc - 'A' + 10) << shift;
  1032. } else if (*esc >= 'a' && *esc <= 'z') {
  1033. value |= (*esc - 'a' + 10) << shift;
  1034. } else {
  1035. esc++;
  1036. continue;
  1037. }
  1038. if (shift == 0) {
  1039. cgbytes[cgoffset++] = value;
  1040. value = 0;
  1041. }
  1042. esc++;
  1043. }
  1044. lcd_write_cmd(LCD_CMD_SET_CGRAM_ADDR | (cgaddr * 8));
  1045. for (addr = 0; addr < cgoffset; addr++)
  1046. lcd_write_data(cgbytes[addr]);
  1047. /* ensures that we stop writing to CGRAM */
  1048. lcd_gotoxy();
  1049. processed = 1;
  1050. break;
  1051. }
  1052. case 'x': /* gotoxy : LxXXX[yYYY]; */
  1053. case 'y': /* gotoxy : LyYYY[xXXX]; */
  1054. if (!strchr(esc, ';'))
  1055. break;
  1056. while (*esc) {
  1057. if (*esc == 'x') {
  1058. esc++;
  1059. if (kstrtoul(esc, 10, &lcd.addr.x) < 0)
  1060. break;
  1061. } else if (*esc == 'y') {
  1062. esc++;
  1063. if (kstrtoul(esc, 10, &lcd.addr.y) < 0)
  1064. break;
  1065. } else {
  1066. break;
  1067. }
  1068. }
  1069. lcd_gotoxy();
  1070. processed = 1;
  1071. break;
  1072. }
  1073. /* TODO: This indent party here got ugly, clean it! */
  1074. /* Check whether one flag was changed */
  1075. if (oldflags != lcd.flags) {
  1076. /* check whether one of B,C,D flags were changed */
  1077. if ((oldflags ^ lcd.flags) &
  1078. (LCD_FLAG_B | LCD_FLAG_C | LCD_FLAG_D))
  1079. /* set display mode */
  1080. lcd_write_cmd(LCD_CMD_DISPLAY_CTRL
  1081. | ((lcd.flags & LCD_FLAG_D)
  1082. ? LCD_CMD_DISPLAY_ON : 0)
  1083. | ((lcd.flags & LCD_FLAG_C)
  1084. ? LCD_CMD_CURSOR_ON : 0)
  1085. | ((lcd.flags & LCD_FLAG_B)
  1086. ? LCD_CMD_BLINK_ON : 0));
  1087. /* check whether one of F,N flags was changed */
  1088. else if ((oldflags ^ lcd.flags) & (LCD_FLAG_F | LCD_FLAG_N))
  1089. lcd_write_cmd(LCD_CMD_FUNCTION_SET
  1090. | LCD_CMD_DATA_LEN_8BITS
  1091. | ((lcd.flags & LCD_FLAG_F)
  1092. ? LCD_CMD_TWO_LINES : 0)
  1093. | ((lcd.flags & LCD_FLAG_N)
  1094. ? LCD_CMD_FONT_5X10_DOTS
  1095. : 0));
  1096. /* check whether L flag was changed */
  1097. else if ((oldflags ^ lcd.flags) & (LCD_FLAG_L)) {
  1098. if (lcd.flags & (LCD_FLAG_L))
  1099. lcd_backlight(1);
  1100. else if (lcd.light_tempo == 0)
  1101. /*
  1102. * switch off the light only when the tempo
  1103. * lighting is gone
  1104. */
  1105. lcd_backlight(0);
  1106. }
  1107. }
  1108. return processed;
  1109. }
  1110. static void lcd_write_char(char c)
  1111. {
  1112. /* first, we'll test if we're in escape mode */
  1113. if ((c != '\n') && lcd.esc_seq.len >= 0) {
  1114. /* yes, let's add this char to the buffer */
  1115. lcd.esc_seq.buf[lcd.esc_seq.len++] = c;
  1116. lcd.esc_seq.buf[lcd.esc_seq.len] = 0;
  1117. } else {
  1118. /* aborts any previous escape sequence */
  1119. lcd.esc_seq.len = -1;
  1120. switch (c) {
  1121. case LCD_ESCAPE_CHAR:
  1122. /* start of an escape sequence */
  1123. lcd.esc_seq.len = 0;
  1124. lcd.esc_seq.buf[lcd.esc_seq.len] = 0;
  1125. break;
  1126. case '\b':
  1127. /* go back one char and clear it */
  1128. if (lcd.addr.x > 0) {
  1129. /*
  1130. * check if we're not at the
  1131. * end of the line
  1132. */
  1133. if (lcd.addr.x < lcd.bwidth)
  1134. /* back one char */
  1135. lcd_write_cmd(LCD_CMD_SHIFT);
  1136. lcd.addr.x--;
  1137. }
  1138. /* replace with a space */
  1139. lcd_write_data(' ');
  1140. /* back one char again */
  1141. lcd_write_cmd(LCD_CMD_SHIFT);
  1142. break;
  1143. case '\014':
  1144. /* quickly clear the display */
  1145. lcd_clear_fast();
  1146. break;
  1147. case '\n':
  1148. /*
  1149. * flush the remainder of the current line and
  1150. * go to the beginning of the next line
  1151. */
  1152. for (; lcd.addr.x < lcd.bwidth; lcd.addr.x++)
  1153. lcd_write_data(' ');
  1154. lcd.addr.x = 0;
  1155. lcd.addr.y = (lcd.addr.y + 1) % lcd.height;
  1156. lcd_gotoxy();
  1157. break;
  1158. case '\r':
  1159. /* go to the beginning of the same line */
  1160. lcd.addr.x = 0;
  1161. lcd_gotoxy();
  1162. break;
  1163. case '\t':
  1164. /* print a space instead of the tab */
  1165. lcd_print(' ');
  1166. break;
  1167. default:
  1168. /* simply print this char */
  1169. lcd_print(c);
  1170. break;
  1171. }
  1172. }
  1173. /*
  1174. * now we'll see if we're in an escape mode and if the current
  1175. * escape sequence can be understood.
  1176. */
  1177. if (lcd.esc_seq.len >= 2) {
  1178. int processed = 0;
  1179. if (!strcmp(lcd.esc_seq.buf, "[2J")) {
  1180. /* clear the display */
  1181. lcd_clear_fast();
  1182. processed = 1;
  1183. } else if (!strcmp(lcd.esc_seq.buf, "[H")) {
  1184. /* cursor to home */
  1185. lcd.addr.x = 0;
  1186. lcd.addr.y = 0;
  1187. lcd_gotoxy();
  1188. processed = 1;
  1189. }
  1190. /* codes starting with ^[[L */
  1191. else if ((lcd.esc_seq.len >= 3) &&
  1192. (lcd.esc_seq.buf[0] == '[') &&
  1193. (lcd.esc_seq.buf[1] == 'L')) {
  1194. processed = handle_lcd_special_code();
  1195. }
  1196. /* LCD special escape codes */
  1197. /*
  1198. * flush the escape sequence if it's been processed
  1199. * or if it is getting too long.
  1200. */
  1201. if (processed || (lcd.esc_seq.len >= LCD_ESCAPE_LEN))
  1202. lcd.esc_seq.len = -1;
  1203. } /* escape codes */
  1204. }
  1205. static ssize_t lcd_write(struct file *file,
  1206. const char __user *buf, size_t count, loff_t *ppos)
  1207. {
  1208. const char __user *tmp = buf;
  1209. char c;
  1210. for (; count-- > 0; (*ppos)++, tmp++) {
  1211. if (!in_interrupt() && (((count + 1) & 0x1f) == 0))
  1212. /*
  1213. * let's be a little nice with other processes
  1214. * that need some CPU
  1215. */
  1216. schedule();
  1217. if (get_user(c, tmp))
  1218. return -EFAULT;
  1219. lcd_write_char(c);
  1220. }
  1221. return tmp - buf;
  1222. }
  1223. static int lcd_open(struct inode *inode, struct file *file)
  1224. {
  1225. if (!atomic_dec_and_test(&lcd_available))
  1226. return -EBUSY; /* open only once at a time */
  1227. if (file->f_mode & FMODE_READ) /* device is write-only */
  1228. return -EPERM;
  1229. if (lcd.must_clear) {
  1230. lcd_clear_display();
  1231. lcd.must_clear = false;
  1232. }
  1233. return nonseekable_open(inode, file);
  1234. }
  1235. static int lcd_release(struct inode *inode, struct file *file)
  1236. {
  1237. atomic_inc(&lcd_available);
  1238. return 0;
  1239. }
  1240. static const struct file_operations lcd_fops = {
  1241. .write = lcd_write,
  1242. .open = lcd_open,
  1243. .release = lcd_release,
  1244. .llseek = no_llseek,
  1245. };
  1246. static struct miscdevice lcd_dev = {
  1247. .minor = LCD_MINOR,
  1248. .name = "lcd",
  1249. .fops = &lcd_fops,
  1250. };
  1251. /* public function usable from the kernel for any purpose */
  1252. static void panel_lcd_print(const char *s)
  1253. {
  1254. const char *tmp = s;
  1255. int count = strlen(s);
  1256. if (lcd.enabled && lcd.initialized) {
  1257. for (; count-- > 0; tmp++) {
  1258. if (!in_interrupt() && (((count + 1) & 0x1f) == 0))
  1259. /*
  1260. * let's be a little nice with other processes
  1261. * that need some CPU
  1262. */
  1263. schedule();
  1264. lcd_write_char(*tmp);
  1265. }
  1266. }
  1267. }
  1268. /* initialize the LCD driver */
  1269. static void lcd_init(void)
  1270. {
  1271. switch (selected_lcd_type) {
  1272. case LCD_TYPE_OLD:
  1273. /* parallel mode, 8 bits */
  1274. lcd.proto = LCD_PROTO_PARALLEL;
  1275. lcd.charset = LCD_CHARSET_NORMAL;
  1276. lcd.pins.e = PIN_STROBE;
  1277. lcd.pins.rs = PIN_AUTOLF;
  1278. lcd.width = 40;
  1279. lcd.bwidth = 40;
  1280. lcd.hwidth = 64;
  1281. lcd.height = 2;
  1282. break;
  1283. case LCD_TYPE_KS0074:
  1284. /* serial mode, ks0074 */
  1285. lcd.proto = LCD_PROTO_SERIAL;
  1286. lcd.charset = LCD_CHARSET_KS0074;
  1287. lcd.pins.bl = PIN_AUTOLF;
  1288. lcd.pins.cl = PIN_STROBE;
  1289. lcd.pins.da = PIN_D0;
  1290. lcd.width = 16;
  1291. lcd.bwidth = 40;
  1292. lcd.hwidth = 16;
  1293. lcd.height = 2;
  1294. break;
  1295. case LCD_TYPE_NEXCOM:
  1296. /* parallel mode, 8 bits, generic */
  1297. lcd.proto = LCD_PROTO_PARALLEL;
  1298. lcd.charset = LCD_CHARSET_NORMAL;
  1299. lcd.pins.e = PIN_AUTOLF;
  1300. lcd.pins.rs = PIN_SELECP;
  1301. lcd.pins.rw = PIN_INITP;
  1302. lcd.width = 16;
  1303. lcd.bwidth = 40;
  1304. lcd.hwidth = 64;
  1305. lcd.height = 2;
  1306. break;
  1307. case LCD_TYPE_CUSTOM:
  1308. /* customer-defined */
  1309. lcd.proto = DEFAULT_LCD_PROTO;
  1310. lcd.charset = DEFAULT_LCD_CHARSET;
  1311. /* default geometry will be set later */
  1312. break;
  1313. case LCD_TYPE_HANTRONIX:
  1314. /* parallel mode, 8 bits, hantronix-like */
  1315. default:
  1316. lcd.proto = LCD_PROTO_PARALLEL;
  1317. lcd.charset = LCD_CHARSET_NORMAL;
  1318. lcd.pins.e = PIN_STROBE;
  1319. lcd.pins.rs = PIN_SELECP;
  1320. lcd.width = 16;
  1321. lcd.bwidth = 40;
  1322. lcd.hwidth = 64;
  1323. lcd.height = 2;
  1324. break;
  1325. }
  1326. /* Overwrite with module params set on loading */
  1327. if (lcd_height != NOT_SET)
  1328. lcd.height = lcd_height;
  1329. if (lcd_width != NOT_SET)
  1330. lcd.width = lcd_width;
  1331. if (lcd_bwidth != NOT_SET)
  1332. lcd.bwidth = lcd_bwidth;
  1333. if (lcd_hwidth != NOT_SET)
  1334. lcd.hwidth = lcd_hwidth;
  1335. if (lcd_charset != NOT_SET)
  1336. lcd.charset = lcd_charset;
  1337. if (lcd_proto != NOT_SET)
  1338. lcd.proto = lcd_proto;
  1339. if (lcd_e_pin != PIN_NOT_SET)
  1340. lcd.pins.e = lcd_e_pin;
  1341. if (lcd_rs_pin != PIN_NOT_SET)
  1342. lcd.pins.rs = lcd_rs_pin;
  1343. if (lcd_rw_pin != PIN_NOT_SET)
  1344. lcd.pins.rw = lcd_rw_pin;
  1345. if (lcd_cl_pin != PIN_NOT_SET)
  1346. lcd.pins.cl = lcd_cl_pin;
  1347. if (lcd_da_pin != PIN_NOT_SET)
  1348. lcd.pins.da = lcd_da_pin;
  1349. if (lcd_bl_pin != PIN_NOT_SET)
  1350. lcd.pins.bl = lcd_bl_pin;
  1351. /* this is used to catch wrong and default values */
  1352. if (lcd.width <= 0)
  1353. lcd.width = DEFAULT_LCD_WIDTH;
  1354. if (lcd.bwidth <= 0)
  1355. lcd.bwidth = DEFAULT_LCD_BWIDTH;
  1356. if (lcd.hwidth <= 0)
  1357. lcd.hwidth = DEFAULT_LCD_HWIDTH;
  1358. if (lcd.height <= 0)
  1359. lcd.height = DEFAULT_LCD_HEIGHT;
  1360. if (lcd.proto == LCD_PROTO_SERIAL) { /* SERIAL */
  1361. lcd_write_cmd = lcd_write_cmd_s;
  1362. lcd_write_data = lcd_write_data_s;
  1363. lcd_clear_fast = lcd_clear_fast_s;
  1364. if (lcd.pins.cl == PIN_NOT_SET)
  1365. lcd.pins.cl = DEFAULT_LCD_PIN_SCL;
  1366. if (lcd.pins.da == PIN_NOT_SET)
  1367. lcd.pins.da = DEFAULT_LCD_PIN_SDA;
  1368. } else if (lcd.proto == LCD_PROTO_PARALLEL) { /* PARALLEL */
  1369. lcd_write_cmd = lcd_write_cmd_p8;
  1370. lcd_write_data = lcd_write_data_p8;
  1371. lcd_clear_fast = lcd_clear_fast_p8;
  1372. if (lcd.pins.e == PIN_NOT_SET)
  1373. lcd.pins.e = DEFAULT_LCD_PIN_E;
  1374. if (lcd.pins.rs == PIN_NOT_SET)
  1375. lcd.pins.rs = DEFAULT_LCD_PIN_RS;
  1376. if (lcd.pins.rw == PIN_NOT_SET)
  1377. lcd.pins.rw = DEFAULT_LCD_PIN_RW;
  1378. } else {
  1379. lcd_write_cmd = lcd_write_cmd_tilcd;
  1380. lcd_write_data = lcd_write_data_tilcd;
  1381. lcd_clear_fast = lcd_clear_fast_tilcd;
  1382. }
  1383. if (lcd.pins.bl == PIN_NOT_SET)
  1384. lcd.pins.bl = DEFAULT_LCD_PIN_BL;
  1385. if (lcd.pins.e == PIN_NOT_SET)
  1386. lcd.pins.e = PIN_NONE;
  1387. if (lcd.pins.rs == PIN_NOT_SET)
  1388. lcd.pins.rs = PIN_NONE;
  1389. if (lcd.pins.rw == PIN_NOT_SET)
  1390. lcd.pins.rw = PIN_NONE;
  1391. if (lcd.pins.bl == PIN_NOT_SET)
  1392. lcd.pins.bl = PIN_NONE;
  1393. if (lcd.pins.cl == PIN_NOT_SET)
  1394. lcd.pins.cl = PIN_NONE;
  1395. if (lcd.pins.da == PIN_NOT_SET)
  1396. lcd.pins.da = PIN_NONE;
  1397. if (lcd.charset == NOT_SET)
  1398. lcd.charset = DEFAULT_LCD_CHARSET;
  1399. if (lcd.charset == LCD_CHARSET_KS0074)
  1400. lcd_char_conv = lcd_char_conv_ks0074;
  1401. else
  1402. lcd_char_conv = NULL;
  1403. if (lcd.pins.bl != PIN_NONE)
  1404. init_scan_timer();
  1405. pin_to_bits(lcd.pins.e, lcd_bits[LCD_PORT_D][LCD_BIT_E],
  1406. lcd_bits[LCD_PORT_C][LCD_BIT_E]);
  1407. pin_to_bits(lcd.pins.rs, lcd_bits[LCD_PORT_D][LCD_BIT_RS],
  1408. lcd_bits[LCD_PORT_C][LCD_BIT_RS]);
  1409. pin_to_bits(lcd.pins.rw, lcd_bits[LCD_PORT_D][LCD_BIT_RW],
  1410. lcd_bits[LCD_PORT_C][LCD_BIT_RW]);
  1411. pin_to_bits(lcd.pins.bl, lcd_bits[LCD_PORT_D][LCD_BIT_BL],
  1412. lcd_bits[LCD_PORT_C][LCD_BIT_BL]);
  1413. pin_to_bits(lcd.pins.cl, lcd_bits[LCD_PORT_D][LCD_BIT_CL],
  1414. lcd_bits[LCD_PORT_C][LCD_BIT_CL]);
  1415. pin_to_bits(lcd.pins.da, lcd_bits[LCD_PORT_D][LCD_BIT_DA],
  1416. lcd_bits[LCD_PORT_C][LCD_BIT_DA]);
  1417. /*
  1418. * before this line, we must NOT send anything to the display.
  1419. * Since lcd_init_display() needs to write data, we have to
  1420. * enable mark the LCD initialized just before.
  1421. */
  1422. lcd.initialized = true;
  1423. lcd_init_display();
  1424. /* display a short message */
  1425. #ifdef CONFIG_PANEL_CHANGE_MESSAGE
  1426. #ifdef CONFIG_PANEL_BOOT_MESSAGE
  1427. panel_lcd_print("\x1b[Lc\x1b[Lb\x1b[L*" CONFIG_PANEL_BOOT_MESSAGE);
  1428. #endif
  1429. #else
  1430. panel_lcd_print("\x1b[Lc\x1b[Lb\x1b[L*Linux-" UTS_RELEASE "\nPanel-"
  1431. PANEL_VERSION);
  1432. #endif
  1433. lcd.addr.x = 0;
  1434. lcd.addr.y = 0;
  1435. /* clear the display on the next device opening */
  1436. lcd.must_clear = true;
  1437. lcd_gotoxy();
  1438. }
  1439. /*
  1440. * These are the file operation function for user access to /dev/keypad
  1441. */
  1442. static ssize_t keypad_read(struct file *file,
  1443. char __user *buf, size_t count, loff_t *ppos)
  1444. {
  1445. unsigned i = *ppos;
  1446. char __user *tmp = buf;
  1447. if (keypad_buflen == 0) {
  1448. if (file->f_flags & O_NONBLOCK)
  1449. return -EAGAIN;
  1450. if (wait_event_interruptible(keypad_read_wait,
  1451. keypad_buflen != 0))
  1452. return -EINTR;
  1453. }
  1454. for (; count-- > 0 && (keypad_buflen > 0);
  1455. ++i, ++tmp, --keypad_buflen) {
  1456. put_user(keypad_buffer[keypad_start], tmp);
  1457. keypad_start = (keypad_start + 1) % KEYPAD_BUFFER;
  1458. }
  1459. *ppos = i;
  1460. return tmp - buf;
  1461. }
  1462. static int keypad_open(struct inode *inode, struct file *file)
  1463. {
  1464. if (!atomic_dec_and_test(&keypad_available))
  1465. return -EBUSY; /* open only once at a time */
  1466. if (file->f_mode & FMODE_WRITE) /* device is read-only */
  1467. return -EPERM;
  1468. keypad_buflen = 0; /* flush the buffer on opening */
  1469. return 0;
  1470. }
  1471. static int keypad_release(struct inode *inode, struct file *file)
  1472. {
  1473. atomic_inc(&keypad_available);
  1474. return 0;
  1475. }
  1476. static const struct file_operations keypad_fops = {
  1477. .read = keypad_read, /* read */
  1478. .open = keypad_open, /* open */
  1479. .release = keypad_release, /* close */
  1480. .llseek = default_llseek,
  1481. };
  1482. static struct miscdevice keypad_dev = {
  1483. .minor = KEYPAD_MINOR,
  1484. .name = "keypad",
  1485. .fops = &keypad_fops,
  1486. };
  1487. static void keypad_send_key(const char *string, int max_len)
  1488. {
  1489. /* send the key to the device only if a process is attached to it. */
  1490. if (!atomic_read(&keypad_available)) {
  1491. while (max_len-- && keypad_buflen < KEYPAD_BUFFER && *string) {
  1492. keypad_buffer[(keypad_start + keypad_buflen++) %
  1493. KEYPAD_BUFFER] = *string++;
  1494. }
  1495. wake_up_interruptible(&keypad_read_wait);
  1496. }
  1497. }
  1498. /* this function scans all the bits involving at least one logical signal,
  1499. * and puts the results in the bitfield "phys_read" (one bit per established
  1500. * contact), and sets "phys_read_prev" to "phys_read".
  1501. *
  1502. * Note: to debounce input signals, we will only consider as switched a signal
  1503. * which is stable across 2 measures. Signals which are different between two
  1504. * reads will be kept as they previously were in their logical form (phys_prev).
  1505. * A signal which has just switched will have a 1 in
  1506. * (phys_read ^ phys_read_prev).
  1507. */
  1508. static void phys_scan_contacts(void)
  1509. {
  1510. int bit, bitval;
  1511. char oldval;
  1512. char bitmask;
  1513. char gndmask;
  1514. phys_prev = phys_curr;
  1515. phys_read_prev = phys_read;
  1516. phys_read = 0; /* flush all signals */
  1517. /* keep track of old value, with all outputs disabled */
  1518. oldval = r_dtr(pprt) | scan_mask_o;
  1519. /* activate all keyboard outputs (active low) */
  1520. w_dtr(pprt, oldval & ~scan_mask_o);
  1521. /* will have a 1 for each bit set to gnd */
  1522. bitmask = PNL_PINPUT(r_str(pprt)) & scan_mask_i;
  1523. /* disable all matrix signals */
  1524. w_dtr(pprt, oldval);
  1525. /* now that all outputs are cleared, the only active input bits are
  1526. * directly connected to the ground
  1527. */
  1528. /* 1 for each grounded input */
  1529. gndmask = PNL_PINPUT(r_str(pprt)) & scan_mask_i;
  1530. /* grounded inputs are signals 40-44 */
  1531. phys_read |= (__u64)gndmask << 40;
  1532. if (bitmask != gndmask) {
  1533. /*
  1534. * since clearing the outputs changed some inputs, we know
  1535. * that some input signals are currently tied to some outputs.
  1536. * So we'll scan them.
  1537. */
  1538. for (bit = 0; bit < 8; bit++) {
  1539. bitval = BIT(bit);
  1540. if (!(scan_mask_o & bitval)) /* skip unused bits */
  1541. continue;
  1542. w_dtr(pprt, oldval & ~bitval); /* enable this output */
  1543. bitmask = PNL_PINPUT(r_str(pprt)) & ~gndmask;
  1544. phys_read |= (__u64)bitmask << (5 * bit);
  1545. }
  1546. w_dtr(pprt, oldval); /* disable all outputs */
  1547. }
  1548. /*
  1549. * this is easy: use old bits when they are flapping,
  1550. * use new ones when stable
  1551. */
  1552. phys_curr = (phys_prev & (phys_read ^ phys_read_prev)) |
  1553. (phys_read & ~(phys_read ^ phys_read_prev));
  1554. }
  1555. static inline int input_state_high(struct logical_input *input)
  1556. {
  1557. #if 0
  1558. /* FIXME:
  1559. * this is an invalid test. It tries to catch
  1560. * transitions from single-key to multiple-key, but
  1561. * doesn't take into account the contacts polarity.
  1562. * The only solution to the problem is to parse keys
  1563. * from the most complex to the simplest combinations,
  1564. * and mark them as 'caught' once a combination
  1565. * matches, then unmatch it for all other ones.
  1566. */
  1567. /* try to catch dangerous transitions cases :
  1568. * someone adds a bit, so this signal was a false
  1569. * positive resulting from a transition. We should
  1570. * invalidate the signal immediately and not call the
  1571. * release function.
  1572. * eg: 0 -(press A)-> A -(press B)-> AB : don't match A's release.
  1573. */
  1574. if (((phys_prev & input->mask) == input->value) &&
  1575. ((phys_curr & input->mask) > input->value)) {
  1576. input->state = INPUT_ST_LOW; /* invalidate */
  1577. return 1;
  1578. }
  1579. #endif
  1580. if ((phys_curr & input->mask) == input->value) {
  1581. if ((input->type == INPUT_TYPE_STD) &&
  1582. (input->high_timer == 0)) {
  1583. input->high_timer++;
  1584. if (input->u.std.press_fct)
  1585. input->u.std.press_fct(input->u.std.press_data);
  1586. } else if (input->type == INPUT_TYPE_KBD) {
  1587. /* will turn on the light */
  1588. keypressed = 1;
  1589. if (input->high_timer == 0) {
  1590. char *press_str = input->u.kbd.press_str;
  1591. if (press_str[0]) {
  1592. int s = sizeof(input->u.kbd.press_str);
  1593. keypad_send_key(press_str, s);
  1594. }
  1595. }
  1596. if (input->u.kbd.repeat_str[0]) {
  1597. char *repeat_str = input->u.kbd.repeat_str;
  1598. if (input->high_timer >= KEYPAD_REP_START) {
  1599. int s = sizeof(input->u.kbd.repeat_str);
  1600. input->high_timer -= KEYPAD_REP_DELAY;
  1601. keypad_send_key(repeat_str, s);
  1602. }
  1603. /* we will need to come back here soon */
  1604. inputs_stable = 0;
  1605. }
  1606. if (input->high_timer < 255)
  1607. input->high_timer++;
  1608. }
  1609. return 1;
  1610. }
  1611. /* else signal falling down. Let's fall through. */
  1612. input->state = INPUT_ST_FALLING;
  1613. input->fall_timer = 0;
  1614. return 0;
  1615. }
  1616. static inline void input_state_falling(struct logical_input *input)
  1617. {
  1618. #if 0
  1619. /* FIXME !!! same comment as in input_state_high */
  1620. if (((phys_prev & input->mask) == input->value) &&
  1621. ((phys_curr & input->mask) > input->value)) {
  1622. input->state = INPUT_ST_LOW; /* invalidate */
  1623. return;
  1624. }
  1625. #endif
  1626. if ((phys_curr & input->mask) == input->value) {
  1627. if (input->type == INPUT_TYPE_KBD) {
  1628. /* will turn on the light */
  1629. keypressed = 1;
  1630. if (input->u.kbd.repeat_str[0]) {
  1631. char *repeat_str = input->u.kbd.repeat_str;
  1632. if (input->high_timer >= KEYPAD_REP_START) {
  1633. int s = sizeof(input->u.kbd.repeat_str);
  1634. input->high_timer -= KEYPAD_REP_DELAY;
  1635. keypad_send_key(repeat_str, s);
  1636. }
  1637. /* we will need to come back here soon */
  1638. inputs_stable = 0;
  1639. }
  1640. if (input->high_timer < 255)
  1641. input->high_timer++;
  1642. }
  1643. input->state = INPUT_ST_HIGH;
  1644. } else if (input->fall_timer >= input->fall_time) {
  1645. /* call release event */
  1646. if (input->type == INPUT_TYPE_STD) {
  1647. void (*release_fct)(int) = input->u.std.release_fct;
  1648. if (release_fct)
  1649. release_fct(input->u.std.release_data);
  1650. } else if (input->type == INPUT_TYPE_KBD) {
  1651. char *release_str = input->u.kbd.release_str;
  1652. if (release_str[0]) {
  1653. int s = sizeof(input->u.kbd.release_str);
  1654. keypad_send_key(release_str, s);
  1655. }
  1656. }
  1657. input->state = INPUT_ST_LOW;
  1658. } else {
  1659. input->fall_timer++;
  1660. inputs_stable = 0;
  1661. }
  1662. }
  1663. static void panel_process_inputs(void)
  1664. {
  1665. struct list_head *item;
  1666. struct logical_input *input;
  1667. keypressed = 0;
  1668. inputs_stable = 1;
  1669. list_for_each(item, &logical_inputs) {
  1670. input = list_entry(item, struct logical_input, list);
  1671. switch (input->state) {
  1672. case INPUT_ST_LOW:
  1673. if ((phys_curr & input->mask) != input->value)
  1674. break;
  1675. /* if all needed ones were already set previously,
  1676. * this means that this logical signal has been
  1677. * activated by the releasing of another combined
  1678. * signal, so we don't want to match.
  1679. * eg: AB -(release B)-> A -(release A)-> 0 :
  1680. * don't match A.
  1681. */
  1682. if ((phys_prev & input->mask) == input->value)
  1683. break;
  1684. input->rise_timer = 0;
  1685. input->state = INPUT_ST_RISING;
  1686. /* no break here, fall through */
  1687. case INPUT_ST_RISING:
  1688. if ((phys_curr & input->mask) != input->value) {
  1689. input->state = INPUT_ST_LOW;
  1690. break;
  1691. }
  1692. if (input->rise_timer < input->rise_time) {
  1693. inputs_stable = 0;
  1694. input->rise_timer++;
  1695. break;
  1696. }
  1697. input->high_timer = 0;
  1698. input->state = INPUT_ST_HIGH;
  1699. /* no break here, fall through */
  1700. case INPUT_ST_HIGH:
  1701. if (input_state_high(input))
  1702. break;
  1703. /* no break here, fall through */
  1704. case INPUT_ST_FALLING:
  1705. input_state_falling(input);
  1706. }
  1707. }
  1708. }
  1709. static void panel_scan_timer(void)
  1710. {
  1711. if (keypad.enabled && keypad_initialized) {
  1712. if (spin_trylock_irq(&pprt_lock)) {
  1713. phys_scan_contacts();
  1714. /* no need for the parport anymore */
  1715. spin_unlock_irq(&pprt_lock);
  1716. }
  1717. if (!inputs_stable || phys_curr != phys_prev)
  1718. panel_process_inputs();
  1719. }
  1720. if (lcd.enabled && lcd.initialized) {
  1721. if (keypressed) {
  1722. if (lcd.light_tempo == 0 &&
  1723. ((lcd.flags & LCD_FLAG_L) == 0))
  1724. lcd_backlight(1);
  1725. lcd.light_tempo = FLASH_LIGHT_TEMPO;
  1726. } else if (lcd.light_tempo > 0) {
  1727. lcd.light_tempo--;
  1728. if (lcd.light_tempo == 0 &&
  1729. ((lcd.flags & LCD_FLAG_L) == 0))
  1730. lcd_backlight(0);
  1731. }
  1732. }
  1733. mod_timer(&scan_timer, jiffies + INPUT_POLL_TIME);
  1734. }
  1735. static void init_scan_timer(void)
  1736. {
  1737. if (scan_timer.function)
  1738. return; /* already started */
  1739. setup_timer(&scan_timer, (void *)&panel_scan_timer, 0);
  1740. scan_timer.expires = jiffies + INPUT_POLL_TIME;
  1741. add_timer(&scan_timer);
  1742. }
  1743. /* converts a name of the form "({BbAaPpSsEe}{01234567-})*" to a series of bits.
  1744. * if <omask> or <imask> are non-null, they will be or'ed with the bits
  1745. * corresponding to out and in bits respectively.
  1746. * returns 1 if ok, 0 if error (in which case, nothing is written).
  1747. */
  1748. static u8 input_name2mask(const char *name, __u64 *mask, __u64 *value,
  1749. u8 *imask, u8 *omask)
  1750. {
  1751. const char sigtab[] = "EeSsPpAaBb";
  1752. u8 im, om;
  1753. __u64 m, v;
  1754. om = 0;
  1755. im = 0;
  1756. m = 0ULL;
  1757. v = 0ULL;
  1758. while (*name) {
  1759. int in, out, bit, neg;
  1760. const char *idx;
  1761. idx = strchr(sigtab, *name);
  1762. if (!idx)
  1763. return 0; /* input name not found */
  1764. in = idx - sigtab;
  1765. neg = (in & 1); /* odd (lower) names are negated */
  1766. in >>= 1;
  1767. im |= BIT(in);
  1768. name++;
  1769. if (*name >= '0' && *name <= '7') {
  1770. out = *name - '0';
  1771. om |= BIT(out);
  1772. } else if (*name == '-') {
  1773. out = 8;
  1774. } else {
  1775. return 0; /* unknown bit name */
  1776. }
  1777. bit = (out * 5) + in;
  1778. m |= 1ULL << bit;
  1779. if (!neg)
  1780. v |= 1ULL << bit;
  1781. name++;
  1782. }
  1783. *mask = m;
  1784. *value = v;
  1785. if (imask)
  1786. *imask |= im;
  1787. if (omask)
  1788. *omask |= om;
  1789. return 1;
  1790. }
  1791. /* tries to bind a key to the signal name <name>. The key will send the
  1792. * strings <press>, <repeat>, <release> for these respective events.
  1793. * Returns the pointer to the new key if ok, NULL if the key could not be bound.
  1794. */
  1795. static struct logical_input *panel_bind_key(const char *name, const char *press,
  1796. const char *repeat,
  1797. const char *release)
  1798. {
  1799. struct logical_input *key;
  1800. key = kzalloc(sizeof(*key), GFP_KERNEL);
  1801. if (!key)
  1802. return NULL;
  1803. if (!input_name2mask(name, &key->mask, &key->value, &scan_mask_i,
  1804. &scan_mask_o)) {
  1805. kfree(key);
  1806. return NULL;
  1807. }
  1808. key->type = INPUT_TYPE_KBD;
  1809. key->state = INPUT_ST_LOW;
  1810. key->rise_time = 1;
  1811. key->fall_time = 1;
  1812. strncpy(key->u.kbd.press_str, press, sizeof(key->u.kbd.press_str));
  1813. strncpy(key->u.kbd.repeat_str, repeat, sizeof(key->u.kbd.repeat_str));
  1814. strncpy(key->u.kbd.release_str, release,
  1815. sizeof(key->u.kbd.release_str));
  1816. list_add(&key->list, &logical_inputs);
  1817. return key;
  1818. }
  1819. #if 0
  1820. /* tries to bind a callback function to the signal name <name>. The function
  1821. * <press_fct> will be called with the <press_data> arg when the signal is
  1822. * activated, and so on for <release_fct>/<release_data>
  1823. * Returns the pointer to the new signal if ok, NULL if the signal could not
  1824. * be bound.
  1825. */
  1826. static struct logical_input *panel_bind_callback(char *name,
  1827. void (*press_fct)(int),
  1828. int press_data,
  1829. void (*release_fct)(int),
  1830. int release_data)
  1831. {
  1832. struct logical_input *callback;
  1833. callback = kmalloc(sizeof(*callback), GFP_KERNEL);
  1834. if (!callback)
  1835. return NULL;
  1836. memset(callback, 0, sizeof(struct logical_input));
  1837. if (!input_name2mask(name, &callback->mask, &callback->value,
  1838. &scan_mask_i, &scan_mask_o))
  1839. return NULL;
  1840. callback->type = INPUT_TYPE_STD;
  1841. callback->state = INPUT_ST_LOW;
  1842. callback->rise_time = 1;
  1843. callback->fall_time = 1;
  1844. callback->u.std.press_fct = press_fct;
  1845. callback->u.std.press_data = press_data;
  1846. callback->u.std.release_fct = release_fct;
  1847. callback->u.std.release_data = release_data;
  1848. list_add(&callback->list, &logical_inputs);
  1849. return callback;
  1850. }
  1851. #endif
  1852. static void keypad_init(void)
  1853. {
  1854. int keynum;
  1855. init_waitqueue_head(&keypad_read_wait);
  1856. keypad_buflen = 0; /* flushes any eventual noisy keystroke */
  1857. /* Let's create all known keys */
  1858. for (keynum = 0; keypad_profile[keynum][0][0]; keynum++) {
  1859. panel_bind_key(keypad_profile[keynum][0],
  1860. keypad_profile[keynum][1],
  1861. keypad_profile[keynum][2],
  1862. keypad_profile[keynum][3]);
  1863. }
  1864. init_scan_timer();
  1865. keypad_initialized = 1;
  1866. }
  1867. /**************************************************/
  1868. /* device initialization */
  1869. /**************************************************/
  1870. static int panel_notify_sys(struct notifier_block *this, unsigned long code,
  1871. void *unused)
  1872. {
  1873. if (lcd.enabled && lcd.initialized) {
  1874. switch (code) {
  1875. case SYS_DOWN:
  1876. panel_lcd_print
  1877. ("\x0cReloading\nSystem...\x1b[Lc\x1b[Lb\x1b[L+");
  1878. break;
  1879. case SYS_HALT:
  1880. panel_lcd_print
  1881. ("\x0cSystem Halted.\x1b[Lc\x1b[Lb\x1b[L+");
  1882. break;
  1883. case SYS_POWER_OFF:
  1884. panel_lcd_print("\x0cPower off.\x1b[Lc\x1b[Lb\x1b[L+");
  1885. break;
  1886. default:
  1887. break;
  1888. }
  1889. }
  1890. return NOTIFY_DONE;
  1891. }
  1892. static struct notifier_block panel_notifier = {
  1893. panel_notify_sys,
  1894. NULL,
  1895. 0
  1896. };
  1897. static void panel_attach(struct parport *port)
  1898. {
  1899. struct pardev_cb panel_cb;
  1900. if (port->number != parport)
  1901. return;
  1902. if (pprt) {
  1903. pr_err("%s: port->number=%d parport=%d, already registered!\n",
  1904. __func__, port->number, parport);
  1905. return;
  1906. }
  1907. memset(&panel_cb, 0, sizeof(panel_cb));
  1908. panel_cb.private = &pprt;
  1909. /* panel_cb.flags = 0 should be PARPORT_DEV_EXCL? */
  1910. pprt = parport_register_dev_model(port, "panel", &panel_cb, 0);
  1911. if (!pprt) {
  1912. pr_err("%s: port->number=%d parport=%d, parport_register_device() failed\n",
  1913. __func__, port->number, parport);
  1914. return;
  1915. }
  1916. if (parport_claim(pprt)) {
  1917. pr_err("could not claim access to parport%d. Aborting.\n",
  1918. parport);
  1919. goto err_unreg_device;
  1920. }
  1921. /* must init LCD first, just in case an IRQ from the keypad is
  1922. * generated at keypad init
  1923. */
  1924. if (lcd.enabled) {
  1925. lcd_init();
  1926. if (misc_register(&lcd_dev))
  1927. goto err_unreg_device;
  1928. }
  1929. if (keypad.enabled) {
  1930. keypad_init();
  1931. if (misc_register(&keypad_dev))
  1932. goto err_lcd_unreg;
  1933. }
  1934. register_reboot_notifier(&panel_notifier);
  1935. return;
  1936. err_lcd_unreg:
  1937. if (lcd.enabled)
  1938. misc_deregister(&lcd_dev);
  1939. err_unreg_device:
  1940. parport_unregister_device(pprt);
  1941. pprt = NULL;
  1942. }
  1943. static void panel_detach(struct parport *port)
  1944. {
  1945. if (port->number != parport)
  1946. return;
  1947. if (!pprt) {
  1948. pr_err("%s: port->number=%d parport=%d, nothing to unregister.\n",
  1949. __func__, port->number, parport);
  1950. return;
  1951. }
  1952. if (scan_timer.function)
  1953. del_timer_sync(&scan_timer);
  1954. if (pprt) {
  1955. if (keypad.enabled) {
  1956. misc_deregister(&keypad_dev);
  1957. keypad_initialized = 0;
  1958. }
  1959. if (lcd.enabled) {
  1960. panel_lcd_print("\x0cLCD driver " PANEL_VERSION
  1961. "\nunloaded.\x1b[Lc\x1b[Lb\x1b[L-");
  1962. misc_deregister(&lcd_dev);
  1963. lcd.initialized = false;
  1964. }
  1965. /* TODO: free all input signals */
  1966. parport_release(pprt);
  1967. parport_unregister_device(pprt);
  1968. pprt = NULL;
  1969. unregister_reboot_notifier(&panel_notifier);
  1970. }
  1971. }
  1972. static struct parport_driver panel_driver = {
  1973. .name = "panel",
  1974. .match_port = panel_attach,
  1975. .detach = panel_detach,
  1976. .devmodel = true,
  1977. };
  1978. /* init function */
  1979. static int __init panel_init_module(void)
  1980. {
  1981. int selected_keypad_type = NOT_SET, err;
  1982. /* take care of an eventual profile */
  1983. switch (profile) {
  1984. case PANEL_PROFILE_CUSTOM:
  1985. /* custom profile */
  1986. selected_keypad_type = DEFAULT_KEYPAD_TYPE;
  1987. selected_lcd_type = DEFAULT_LCD_TYPE;
  1988. break;
  1989. case PANEL_PROFILE_OLD:
  1990. /* 8 bits, 2*16, old keypad */
  1991. selected_keypad_type = KEYPAD_TYPE_OLD;
  1992. selected_lcd_type = LCD_TYPE_OLD;
  1993. /* TODO: This two are a little hacky, sort it out later */
  1994. if (lcd_width == NOT_SET)
  1995. lcd_width = 16;
  1996. if (lcd_hwidth == NOT_SET)
  1997. lcd_hwidth = 16;
  1998. break;
  1999. case PANEL_PROFILE_NEW:
  2000. /* serial, 2*16, new keypad */
  2001. selected_keypad_type = KEYPAD_TYPE_NEW;
  2002. selected_lcd_type = LCD_TYPE_KS0074;
  2003. break;
  2004. case PANEL_PROFILE_HANTRONIX:
  2005. /* 8 bits, 2*16 hantronix-like, no keypad */
  2006. selected_keypad_type = KEYPAD_TYPE_NONE;
  2007. selected_lcd_type = LCD_TYPE_HANTRONIX;
  2008. break;
  2009. case PANEL_PROFILE_NEXCOM:
  2010. /* generic 8 bits, 2*16, nexcom keypad, eg. Nexcom. */
  2011. selected_keypad_type = KEYPAD_TYPE_NEXCOM;
  2012. selected_lcd_type = LCD_TYPE_NEXCOM;
  2013. break;
  2014. case PANEL_PROFILE_LARGE:
  2015. /* 8 bits, 2*40, old keypad */
  2016. selected_keypad_type = KEYPAD_TYPE_OLD;
  2017. selected_lcd_type = LCD_TYPE_OLD;
  2018. break;
  2019. }
  2020. /*
  2021. * Overwrite selection with module param values (both keypad and lcd),
  2022. * where the deprecated params have lower prio.
  2023. */
  2024. if (keypad_enabled != NOT_SET)
  2025. selected_keypad_type = keypad_enabled;
  2026. if (keypad_type != NOT_SET)
  2027. selected_keypad_type = keypad_type;
  2028. keypad.enabled = (selected_keypad_type > 0);
  2029. if (lcd_enabled != NOT_SET)
  2030. selected_lcd_type = lcd_enabled;
  2031. if (lcd_type != NOT_SET)
  2032. selected_lcd_type = lcd_type;
  2033. lcd.enabled = (selected_lcd_type > 0);
  2034. if (lcd.enabled) {
  2035. /*
  2036. * Init lcd struct with load-time values to preserve exact
  2037. * current functionality (at least for now).
  2038. */
  2039. lcd.height = lcd_height;
  2040. lcd.width = lcd_width;
  2041. lcd.bwidth = lcd_bwidth;
  2042. lcd.hwidth = lcd_hwidth;
  2043. lcd.charset = lcd_charset;
  2044. lcd.proto = lcd_proto;
  2045. lcd.pins.e = lcd_e_pin;
  2046. lcd.pins.rs = lcd_rs_pin;
  2047. lcd.pins.rw = lcd_rw_pin;
  2048. lcd.pins.cl = lcd_cl_pin;
  2049. lcd.pins.da = lcd_da_pin;
  2050. lcd.pins.bl = lcd_bl_pin;
  2051. /* Leave it for now, just in case */
  2052. lcd.esc_seq.len = -1;
  2053. }
  2054. switch (selected_keypad_type) {
  2055. case KEYPAD_TYPE_OLD:
  2056. keypad_profile = old_keypad_profile;
  2057. break;
  2058. case KEYPAD_TYPE_NEW:
  2059. keypad_profile = new_keypad_profile;
  2060. break;
  2061. case KEYPAD_TYPE_NEXCOM:
  2062. keypad_profile = nexcom_keypad_profile;
  2063. break;
  2064. default:
  2065. keypad_profile = NULL;
  2066. break;
  2067. }
  2068. if (!lcd.enabled && !keypad.enabled) {
  2069. /* no device enabled, let's exit */
  2070. pr_err("driver version " PANEL_VERSION " disabled.\n");
  2071. return -ENODEV;
  2072. }
  2073. err = parport_register_driver(&panel_driver);
  2074. if (err) {
  2075. pr_err("could not register with parport. Aborting.\n");
  2076. return err;
  2077. }
  2078. if (pprt)
  2079. pr_info("driver version " PANEL_VERSION
  2080. " registered on parport%d (io=0x%lx).\n", parport,
  2081. pprt->port->base);
  2082. else
  2083. pr_info("driver version " PANEL_VERSION
  2084. " not yet registered\n");
  2085. return 0;
  2086. }
  2087. static void __exit panel_cleanup_module(void)
  2088. {
  2089. parport_unregister_driver(&panel_driver);
  2090. }
  2091. module_init(panel_init_module);
  2092. module_exit(panel_cleanup_module);
  2093. MODULE_AUTHOR("Willy Tarreau");
  2094. MODULE_LICENSE("GPL");
  2095. /*
  2096. * Local variables:
  2097. * c-indent-level: 4
  2098. * tab-width: 8
  2099. * End:
  2100. */