panel.c 60 KB

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