panel.c 60 KB

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