panel.c 61 KB

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