panel.c 47 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800
  1. /*
  2. * Front panel driver for Linux
  3. * Copyright (C) 2000-2008, Willy Tarreau <w@1wt.eu>
  4. * Copyright (C) 2016-2017 Glider bvba
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License
  8. * as published by the Free Software Foundation; either version
  9. * 2 of the License, or (at your option) any later version.
  10. *
  11. * This code drives an LCD module (/dev/lcd), and a keypad (/dev/keypad)
  12. * connected to a parallel printer port.
  13. *
  14. * The LCD module may either be an HD44780-like 8-bit parallel LCD, or a 1-bit
  15. * serial module compatible with Samsung's KS0074. The pins may be connected in
  16. * any combination, everything is programmable.
  17. *
  18. * The keypad consists in a matrix of push buttons connecting input pins to
  19. * data output pins or to the ground. The combinations have to be hard-coded
  20. * in the driver, though several profiles exist and adding new ones is easy.
  21. *
  22. * Several profiles are provided for commonly found LCD+keypad modules on the
  23. * market, such as those found in Nexcom's appliances.
  24. *
  25. * FIXME:
  26. * - the initialization/deinitialization process is very dirty and should
  27. * be rewritten. It may even be buggy.
  28. *
  29. * TODO:
  30. * - document 24 keys keyboard (3 rows of 8 cols, 32 diodes + 2 inputs)
  31. * - make the LCD a part of a virtual screen of Vx*Vy
  32. * - make the inputs list smp-safe
  33. * - change the keyboard to a double mapping : signals -> key_id -> values
  34. * so that applications can change values without knowing signals
  35. *
  36. */
  37. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  38. #include <linux/module.h>
  39. #include <linux/types.h>
  40. #include <linux/errno.h>
  41. #include <linux/signal.h>
  42. #include <linux/sched.h>
  43. #include <linux/spinlock.h>
  44. #include <linux/interrupt.h>
  45. #include <linux/miscdevice.h>
  46. #include <linux/slab.h>
  47. #include <linux/ioport.h>
  48. #include <linux/fcntl.h>
  49. #include <linux/init.h>
  50. #include <linux/delay.h>
  51. #include <linux/kernel.h>
  52. #include <linux/ctype.h>
  53. #include <linux/parport.h>
  54. #include <linux/list.h>
  55. #include <linux/io.h>
  56. #include <linux/uaccess.h>
  57. #include <misc/charlcd.h>
  58. #define KEYPAD_MINOR 185
  59. #define LCD_MAXBYTES 256 /* max burst write */
  60. #define KEYPAD_BUFFER 64
  61. /* poll the keyboard this every second */
  62. #define INPUT_POLL_TIME (HZ / 50)
  63. /* a key starts to repeat after this times INPUT_POLL_TIME */
  64. #define KEYPAD_REP_START (10)
  65. /* a key repeats this times INPUT_POLL_TIME */
  66. #define KEYPAD_REP_DELAY (2)
  67. /* converts an r_str() input to an active high, bits string : 000BAOSE */
  68. #define PNL_PINPUT(a) ((((unsigned char)(a)) ^ 0x7F) >> 3)
  69. #define PNL_PBUSY 0x80 /* inverted input, active low */
  70. #define PNL_PACK 0x40 /* direct input, active low */
  71. #define PNL_POUTPA 0x20 /* direct input, active high */
  72. #define PNL_PSELECD 0x10 /* direct input, active high */
  73. #define PNL_PERRORP 0x08 /* direct input, active low */
  74. #define PNL_PBIDIR 0x20 /* bi-directional ports */
  75. /* high to read data in or-ed with data out */
  76. #define PNL_PINTEN 0x10
  77. #define PNL_PSELECP 0x08 /* inverted output, active low */
  78. #define PNL_PINITP 0x04 /* direct output, active low */
  79. #define PNL_PAUTOLF 0x02 /* inverted output, active low */
  80. #define PNL_PSTROBE 0x01 /* inverted output */
  81. #define PNL_PD0 0x01
  82. #define PNL_PD1 0x02
  83. #define PNL_PD2 0x04
  84. #define PNL_PD3 0x08
  85. #define PNL_PD4 0x10
  86. #define PNL_PD5 0x20
  87. #define PNL_PD6 0x40
  88. #define PNL_PD7 0x80
  89. #define PIN_NONE 0
  90. #define PIN_STROBE 1
  91. #define PIN_D0 2
  92. #define PIN_D1 3
  93. #define PIN_D2 4
  94. #define PIN_D3 5
  95. #define PIN_D4 6
  96. #define PIN_D5 7
  97. #define PIN_D6 8
  98. #define PIN_D7 9
  99. #define PIN_AUTOLF 14
  100. #define PIN_INITP 16
  101. #define PIN_SELECP 17
  102. #define PIN_NOT_SET 127
  103. #define NOT_SET -1
  104. /* macros to simplify use of the parallel port */
  105. #define r_ctr(x) (parport_read_control((x)->port))
  106. #define r_dtr(x) (parport_read_data((x)->port))
  107. #define r_str(x) (parport_read_status((x)->port))
  108. #define w_ctr(x, y) (parport_write_control((x)->port, (y)))
  109. #define w_dtr(x, y) (parport_write_data((x)->port, (y)))
  110. /* this defines which bits are to be used and which ones to be ignored */
  111. /* logical or of the output bits involved in the scan matrix */
  112. static __u8 scan_mask_o;
  113. /* logical or of the input bits involved in the scan matrix */
  114. static __u8 scan_mask_i;
  115. enum input_type {
  116. INPUT_TYPE_STD,
  117. INPUT_TYPE_KBD,
  118. };
  119. enum input_state {
  120. INPUT_ST_LOW,
  121. INPUT_ST_RISING,
  122. INPUT_ST_HIGH,
  123. INPUT_ST_FALLING,
  124. };
  125. struct logical_input {
  126. struct list_head list;
  127. __u64 mask;
  128. __u64 value;
  129. enum input_type type;
  130. enum input_state state;
  131. __u8 rise_time, fall_time;
  132. __u8 rise_timer, fall_timer, high_timer;
  133. union {
  134. struct { /* valid when type == INPUT_TYPE_STD */
  135. void (*press_fct)(int);
  136. void (*release_fct)(int);
  137. int press_data;
  138. int release_data;
  139. } std;
  140. struct { /* valid when type == INPUT_TYPE_KBD */
  141. /* strings can be non null-terminated */
  142. char press_str[sizeof(void *) + sizeof(int)];
  143. char repeat_str[sizeof(void *) + sizeof(int)];
  144. char release_str[sizeof(void *) + sizeof(int)];
  145. } kbd;
  146. } u;
  147. };
  148. static LIST_HEAD(logical_inputs); /* list of all defined logical inputs */
  149. /* physical contacts history
  150. * Physical contacts are a 45 bits string of 9 groups of 5 bits each.
  151. * The 8 lower groups correspond to output bits 0 to 7, and the 9th group
  152. * corresponds to the ground.
  153. * Within each group, bits are stored in the same order as read on the port :
  154. * BAPSE (busy=4, ack=3, paper empty=2, select=1, error=0).
  155. * So, each __u64 is represented like this :
  156. * 0000000000000000000BAPSEBAPSEBAPSEBAPSEBAPSEBAPSEBAPSEBAPSEBAPSE
  157. * <-----unused------><gnd><d07><d06><d05><d04><d03><d02><d01><d00>
  158. */
  159. /* what has just been read from the I/O ports */
  160. static __u64 phys_read;
  161. /* previous phys_read */
  162. static __u64 phys_read_prev;
  163. /* stabilized phys_read (phys_read|phys_read_prev) */
  164. static __u64 phys_curr;
  165. /* previous phys_curr */
  166. static __u64 phys_prev;
  167. /* 0 means that at least one logical signal needs be computed */
  168. static char inputs_stable;
  169. /* these variables are specific to the keypad */
  170. static struct {
  171. bool enabled;
  172. } keypad;
  173. static char keypad_buffer[KEYPAD_BUFFER];
  174. static int keypad_buflen;
  175. static int keypad_start;
  176. static char keypressed;
  177. static wait_queue_head_t keypad_read_wait;
  178. /* lcd-specific variables */
  179. static struct {
  180. bool enabled;
  181. bool initialized;
  182. int charset;
  183. int proto;
  184. /* TODO: use union here? */
  185. struct {
  186. int e;
  187. int rs;
  188. int rw;
  189. int cl;
  190. int da;
  191. int bl;
  192. } pins;
  193. struct charlcd *charlcd;
  194. } lcd;
  195. /* Needed only for init */
  196. static int selected_lcd_type = NOT_SET;
  197. /*
  198. * Bit masks to convert LCD signals to parallel port outputs.
  199. * _d_ are values for data port, _c_ are for control port.
  200. * [0] = signal OFF, [1] = signal ON, [2] = mask
  201. */
  202. #define BIT_CLR 0
  203. #define BIT_SET 1
  204. #define BIT_MSK 2
  205. #define BIT_STATES 3
  206. /*
  207. * one entry for each bit on the LCD
  208. */
  209. #define LCD_BIT_E 0
  210. #define LCD_BIT_RS 1
  211. #define LCD_BIT_RW 2
  212. #define LCD_BIT_BL 3
  213. #define LCD_BIT_CL 4
  214. #define LCD_BIT_DA 5
  215. #define LCD_BITS 6
  216. /*
  217. * each bit can be either connected to a DATA or CTRL port
  218. */
  219. #define LCD_PORT_C 0
  220. #define LCD_PORT_D 1
  221. #define LCD_PORTS 2
  222. static unsigned char lcd_bits[LCD_PORTS][LCD_BITS][BIT_STATES];
  223. /*
  224. * LCD protocols
  225. */
  226. #define LCD_PROTO_PARALLEL 0
  227. #define LCD_PROTO_SERIAL 1
  228. #define LCD_PROTO_TI_DA8XX_LCD 2
  229. /*
  230. * LCD character sets
  231. */
  232. #define LCD_CHARSET_NORMAL 0
  233. #define LCD_CHARSET_KS0074 1
  234. /*
  235. * LCD types
  236. */
  237. #define LCD_TYPE_NONE 0
  238. #define LCD_TYPE_CUSTOM 1
  239. #define LCD_TYPE_OLD 2
  240. #define LCD_TYPE_KS0074 3
  241. #define LCD_TYPE_HANTRONIX 4
  242. #define LCD_TYPE_NEXCOM 5
  243. /*
  244. * keypad types
  245. */
  246. #define KEYPAD_TYPE_NONE 0
  247. #define KEYPAD_TYPE_OLD 1
  248. #define KEYPAD_TYPE_NEW 2
  249. #define KEYPAD_TYPE_NEXCOM 3
  250. /*
  251. * panel profiles
  252. */
  253. #define PANEL_PROFILE_CUSTOM 0
  254. #define PANEL_PROFILE_OLD 1
  255. #define PANEL_PROFILE_NEW 2
  256. #define PANEL_PROFILE_HANTRONIX 3
  257. #define PANEL_PROFILE_NEXCOM 4
  258. #define PANEL_PROFILE_LARGE 5
  259. /*
  260. * Construct custom config from the kernel's configuration
  261. */
  262. #define DEFAULT_PARPORT 0
  263. #define DEFAULT_PROFILE PANEL_PROFILE_LARGE
  264. #define DEFAULT_KEYPAD_TYPE KEYPAD_TYPE_OLD
  265. #define DEFAULT_LCD_TYPE LCD_TYPE_OLD
  266. #define DEFAULT_LCD_HEIGHT 2
  267. #define DEFAULT_LCD_WIDTH 40
  268. #define DEFAULT_LCD_BWIDTH 40
  269. #define DEFAULT_LCD_HWIDTH 64
  270. #define DEFAULT_LCD_CHARSET LCD_CHARSET_NORMAL
  271. #define DEFAULT_LCD_PROTO LCD_PROTO_PARALLEL
  272. #define DEFAULT_LCD_PIN_E PIN_AUTOLF
  273. #define DEFAULT_LCD_PIN_RS PIN_SELECP
  274. #define DEFAULT_LCD_PIN_RW PIN_INITP
  275. #define DEFAULT_LCD_PIN_SCL PIN_STROBE
  276. #define DEFAULT_LCD_PIN_SDA PIN_D0
  277. #define DEFAULT_LCD_PIN_BL PIN_NOT_SET
  278. #ifdef CONFIG_PANEL_PARPORT
  279. #undef DEFAULT_PARPORT
  280. #define DEFAULT_PARPORT CONFIG_PANEL_PARPORT
  281. #endif
  282. #ifdef CONFIG_PANEL_PROFILE
  283. #undef DEFAULT_PROFILE
  284. #define DEFAULT_PROFILE CONFIG_PANEL_PROFILE
  285. #endif
  286. #if DEFAULT_PROFILE == 0 /* custom */
  287. #ifdef CONFIG_PANEL_KEYPAD
  288. #undef DEFAULT_KEYPAD_TYPE
  289. #define DEFAULT_KEYPAD_TYPE CONFIG_PANEL_KEYPAD
  290. #endif
  291. #ifdef CONFIG_PANEL_LCD
  292. #undef DEFAULT_LCD_TYPE
  293. #define DEFAULT_LCD_TYPE CONFIG_PANEL_LCD
  294. #endif
  295. #ifdef CONFIG_PANEL_LCD_HEIGHT
  296. #undef DEFAULT_LCD_HEIGHT
  297. #define DEFAULT_LCD_HEIGHT CONFIG_PANEL_LCD_HEIGHT
  298. #endif
  299. #ifdef CONFIG_PANEL_LCD_WIDTH
  300. #undef DEFAULT_LCD_WIDTH
  301. #define DEFAULT_LCD_WIDTH CONFIG_PANEL_LCD_WIDTH
  302. #endif
  303. #ifdef CONFIG_PANEL_LCD_BWIDTH
  304. #undef DEFAULT_LCD_BWIDTH
  305. #define DEFAULT_LCD_BWIDTH CONFIG_PANEL_LCD_BWIDTH
  306. #endif
  307. #ifdef CONFIG_PANEL_LCD_HWIDTH
  308. #undef DEFAULT_LCD_HWIDTH
  309. #define DEFAULT_LCD_HWIDTH CONFIG_PANEL_LCD_HWIDTH
  310. #endif
  311. #ifdef CONFIG_PANEL_LCD_CHARSET
  312. #undef DEFAULT_LCD_CHARSET
  313. #define DEFAULT_LCD_CHARSET CONFIG_PANEL_LCD_CHARSET
  314. #endif
  315. #ifdef CONFIG_PANEL_LCD_PROTO
  316. #undef DEFAULT_LCD_PROTO
  317. #define DEFAULT_LCD_PROTO CONFIG_PANEL_LCD_PROTO
  318. #endif
  319. #ifdef CONFIG_PANEL_LCD_PIN_E
  320. #undef DEFAULT_LCD_PIN_E
  321. #define DEFAULT_LCD_PIN_E CONFIG_PANEL_LCD_PIN_E
  322. #endif
  323. #ifdef CONFIG_PANEL_LCD_PIN_RS
  324. #undef DEFAULT_LCD_PIN_RS
  325. #define DEFAULT_LCD_PIN_RS CONFIG_PANEL_LCD_PIN_RS
  326. #endif
  327. #ifdef CONFIG_PANEL_LCD_PIN_RW
  328. #undef DEFAULT_LCD_PIN_RW
  329. #define DEFAULT_LCD_PIN_RW CONFIG_PANEL_LCD_PIN_RW
  330. #endif
  331. #ifdef CONFIG_PANEL_LCD_PIN_SCL
  332. #undef DEFAULT_LCD_PIN_SCL
  333. #define DEFAULT_LCD_PIN_SCL CONFIG_PANEL_LCD_PIN_SCL
  334. #endif
  335. #ifdef CONFIG_PANEL_LCD_PIN_SDA
  336. #undef DEFAULT_LCD_PIN_SDA
  337. #define DEFAULT_LCD_PIN_SDA CONFIG_PANEL_LCD_PIN_SDA
  338. #endif
  339. #ifdef CONFIG_PANEL_LCD_PIN_BL
  340. #undef DEFAULT_LCD_PIN_BL
  341. #define DEFAULT_LCD_PIN_BL CONFIG_PANEL_LCD_PIN_BL
  342. #endif
  343. #endif /* DEFAULT_PROFILE == 0 */
  344. /* global variables */
  345. /* Device single-open policy control */
  346. static atomic_t keypad_available = ATOMIC_INIT(1);
  347. static struct pardevice *pprt;
  348. static int keypad_initialized;
  349. static DEFINE_SPINLOCK(pprt_lock);
  350. static struct timer_list scan_timer;
  351. MODULE_DESCRIPTION("Generic parallel port LCD/Keypad driver");
  352. static int parport = DEFAULT_PARPORT;
  353. module_param(parport, int, 0000);
  354. MODULE_PARM_DESC(parport, "Parallel port index (0=lpt1, 1=lpt2, ...)");
  355. static int profile = DEFAULT_PROFILE;
  356. module_param(profile, int, 0000);
  357. MODULE_PARM_DESC(profile,
  358. "1=16x2 old kp; 2=serial 16x2, new kp; 3=16x2 hantronix; "
  359. "4=16x2 nexcom; default=40x2, old kp");
  360. static int keypad_type = NOT_SET;
  361. module_param(keypad_type, int, 0000);
  362. MODULE_PARM_DESC(keypad_type,
  363. "Keypad type: 0=none, 1=old 6 keys, 2=new 6+1 keys, 3=nexcom 4 keys");
  364. static int lcd_type = NOT_SET;
  365. module_param(lcd_type, int, 0000);
  366. MODULE_PARM_DESC(lcd_type,
  367. "LCD type: 0=none, 1=compiled-in, 2=old, 3=serial ks0074, 4=hantronix, 5=nexcom");
  368. static int lcd_height = NOT_SET;
  369. module_param(lcd_height, int, 0000);
  370. MODULE_PARM_DESC(lcd_height, "Number of lines on the LCD");
  371. static int lcd_width = NOT_SET;
  372. module_param(lcd_width, int, 0000);
  373. MODULE_PARM_DESC(lcd_width, "Number of columns on the LCD");
  374. static int lcd_bwidth = NOT_SET; /* 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 = NOT_SET; /* 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_charset = NOT_SET;
  381. module_param(lcd_charset, int, 0000);
  382. MODULE_PARM_DESC(lcd_charset, "LCD character set: 0=standard, 1=KS0074");
  383. static int lcd_proto = NOT_SET;
  384. module_param(lcd_proto, int, 0000);
  385. MODULE_PARM_DESC(lcd_proto,
  386. "LCD communication: 0=parallel (//), 1=serial, 2=TI LCD Interface");
  387. /*
  388. * These are the parallel port pins the LCD control signals are connected to.
  389. * Set this to 0 if the signal is not used. Set it to its opposite value
  390. * (negative) if the signal is negated. -MAXINT is used to indicate that the
  391. * pin has not been explicitly specified.
  392. *
  393. * WARNING! no check will be performed about collisions with keypad !
  394. */
  395. static int lcd_e_pin = PIN_NOT_SET;
  396. module_param(lcd_e_pin, int, 0000);
  397. MODULE_PARM_DESC(lcd_e_pin,
  398. "# of the // port pin connected to LCD 'E' signal, with polarity (-17..17)");
  399. static int lcd_rs_pin = PIN_NOT_SET;
  400. module_param(lcd_rs_pin, int, 0000);
  401. MODULE_PARM_DESC(lcd_rs_pin,
  402. "# of the // port pin connected to LCD 'RS' signal, with polarity (-17..17)");
  403. static int lcd_rw_pin = PIN_NOT_SET;
  404. module_param(lcd_rw_pin, int, 0000);
  405. MODULE_PARM_DESC(lcd_rw_pin,
  406. "# of the // port pin connected to LCD 'RW' signal, with polarity (-17..17)");
  407. static int lcd_cl_pin = PIN_NOT_SET;
  408. module_param(lcd_cl_pin, int, 0000);
  409. MODULE_PARM_DESC(lcd_cl_pin,
  410. "# of the // port pin connected to serial LCD 'SCL' signal, with polarity (-17..17)");
  411. static int lcd_da_pin = PIN_NOT_SET;
  412. module_param(lcd_da_pin, int, 0000);
  413. MODULE_PARM_DESC(lcd_da_pin,
  414. "# of the // port pin connected to serial LCD 'SDA' signal, with polarity (-17..17)");
  415. static int lcd_bl_pin = PIN_NOT_SET;
  416. module_param(lcd_bl_pin, int, 0000);
  417. MODULE_PARM_DESC(lcd_bl_pin,
  418. "# of the // port pin connected to LCD backlight, with polarity (-17..17)");
  419. /* Deprecated module parameters - consider not using them anymore */
  420. static int lcd_enabled = NOT_SET;
  421. module_param(lcd_enabled, int, 0000);
  422. MODULE_PARM_DESC(lcd_enabled, "Deprecated option, use lcd_type instead");
  423. static int keypad_enabled = NOT_SET;
  424. module_param(keypad_enabled, int, 0000);
  425. MODULE_PARM_DESC(keypad_enabled, "Deprecated option, use keypad_type instead");
  426. /* for some LCD drivers (ks0074) we need a charset conversion table. */
  427. static const unsigned char lcd_char_conv_ks0074[256] = {
  428. /* 0|8 1|9 2|A 3|B 4|C 5|D 6|E 7|F */
  429. /* 0x00 */ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  430. /* 0x08 */ 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
  431. /* 0x10 */ 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
  432. /* 0x18 */ 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
  433. /* 0x20 */ 0x20, 0x21, 0x22, 0x23, 0xa2, 0x25, 0x26, 0x27,
  434. /* 0x28 */ 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
  435. /* 0x30 */ 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  436. /* 0x38 */ 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f,
  437. /* 0x40 */ 0xa0, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47,
  438. /* 0x48 */ 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f,
  439. /* 0x50 */ 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
  440. /* 0x58 */ 0x58, 0x59, 0x5a, 0xfa, 0xfb, 0xfc, 0x1d, 0xc4,
  441. /* 0x60 */ 0x96, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67,
  442. /* 0x68 */ 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f,
  443. /* 0x70 */ 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77,
  444. /* 0x78 */ 0x78, 0x79, 0x7a, 0xfd, 0xfe, 0xff, 0xce, 0x20,
  445. /* 0x80 */ 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
  446. /* 0x88 */ 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,
  447. /* 0x90 */ 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97,
  448. /* 0x98 */ 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f,
  449. /* 0xA0 */ 0x20, 0x40, 0xb1, 0xa1, 0x24, 0xa3, 0xfe, 0x5f,
  450. /* 0xA8 */ 0x22, 0xc8, 0x61, 0x14, 0x97, 0x2d, 0xad, 0x96,
  451. /* 0xB0 */ 0x80, 0x8c, 0x82, 0x83, 0x27, 0x8f, 0x86, 0xdd,
  452. /* 0xB8 */ 0x2c, 0x81, 0x6f, 0x15, 0x8b, 0x8a, 0x84, 0x60,
  453. /* 0xC0 */ 0xe2, 0xe2, 0xe2, 0x5b, 0x5b, 0xae, 0xbc, 0xa9,
  454. /* 0xC8 */ 0xc5, 0xbf, 0xc6, 0xf1, 0xe3, 0xe3, 0xe3, 0xe3,
  455. /* 0xD0 */ 0x44, 0x5d, 0xa8, 0xe4, 0xec, 0xec, 0x5c, 0x78,
  456. /* 0xD8 */ 0xab, 0xa6, 0xe5, 0x5e, 0x5e, 0xe6, 0xaa, 0xbe,
  457. /* 0xE0 */ 0x7f, 0xe7, 0xaf, 0x7b, 0x7b, 0xaf, 0xbd, 0xc8,
  458. /* 0xE8 */ 0xa4, 0xa5, 0xc7, 0xf6, 0xa7, 0xe8, 0x69, 0x69,
  459. /* 0xF0 */ 0xed, 0x7d, 0xa8, 0xe4, 0xec, 0x5c, 0x5c, 0x25,
  460. /* 0xF8 */ 0xac, 0xa6, 0xea, 0xef, 0x7e, 0xeb, 0xb2, 0x79,
  461. };
  462. static const char old_keypad_profile[][4][9] = {
  463. {"S0", "Left\n", "Left\n", ""},
  464. {"S1", "Down\n", "Down\n", ""},
  465. {"S2", "Up\n", "Up\n", ""},
  466. {"S3", "Right\n", "Right\n", ""},
  467. {"S4", "Esc\n", "Esc\n", ""},
  468. {"S5", "Ret\n", "Ret\n", ""},
  469. {"", "", "", ""}
  470. };
  471. /* signals, press, repeat, release */
  472. static const char new_keypad_profile[][4][9] = {
  473. {"S0", "Left\n", "Left\n", ""},
  474. {"S1", "Down\n", "Down\n", ""},
  475. {"S2", "Up\n", "Up\n", ""},
  476. {"S3", "Right\n", "Right\n", ""},
  477. {"S4s5", "", "Esc\n", "Esc\n"},
  478. {"s4S5", "", "Ret\n", "Ret\n"},
  479. {"S4S5", "Help\n", "", ""},
  480. /* add new signals above this line */
  481. {"", "", "", ""}
  482. };
  483. /* signals, press, repeat, release */
  484. static const char nexcom_keypad_profile[][4][9] = {
  485. {"a-p-e-", "Down\n", "Down\n", ""},
  486. {"a-p-E-", "Ret\n", "Ret\n", ""},
  487. {"a-P-E-", "Esc\n", "Esc\n", ""},
  488. {"a-P-e-", "Up\n", "Up\n", ""},
  489. /* add new signals above this line */
  490. {"", "", "", ""}
  491. };
  492. static const char (*keypad_profile)[4][9] = old_keypad_profile;
  493. static DECLARE_BITMAP(bits, LCD_BITS);
  494. static void lcd_get_bits(unsigned int port, int *val)
  495. {
  496. unsigned int bit, state;
  497. for (bit = 0; bit < LCD_BITS; bit++) {
  498. state = test_bit(bit, bits) ? BIT_SET : BIT_CLR;
  499. *val &= lcd_bits[port][bit][BIT_MSK];
  500. *val |= lcd_bits[port][bit][state];
  501. }
  502. }
  503. /* sets data port bits according to current signals values */
  504. static int set_data_bits(void)
  505. {
  506. int val;
  507. val = r_dtr(pprt);
  508. lcd_get_bits(LCD_PORT_D, &val);
  509. w_dtr(pprt, val);
  510. return val;
  511. }
  512. /* sets ctrl port bits according to current signals values */
  513. static int set_ctrl_bits(void)
  514. {
  515. int val;
  516. val = r_ctr(pprt);
  517. lcd_get_bits(LCD_PORT_C, &val);
  518. w_ctr(pprt, val);
  519. return val;
  520. }
  521. /* sets ctrl & data port bits according to current signals values */
  522. static void panel_set_bits(void)
  523. {
  524. set_data_bits();
  525. set_ctrl_bits();
  526. }
  527. /*
  528. * Converts a parallel port pin (from -25 to 25) to data and control ports
  529. * masks, and data and control port bits. The signal will be considered
  530. * unconnected if it's on pin 0 or an invalid pin (<-25 or >25).
  531. *
  532. * Result will be used this way :
  533. * out(dport, in(dport) & d_val[2] | d_val[signal_state])
  534. * out(cport, in(cport) & c_val[2] | c_val[signal_state])
  535. */
  536. static void pin_to_bits(int pin, unsigned char *d_val, unsigned char *c_val)
  537. {
  538. int d_bit, c_bit, inv;
  539. d_val[0] = 0;
  540. c_val[0] = 0;
  541. d_val[1] = 0;
  542. c_val[1] = 0;
  543. d_val[2] = 0xFF;
  544. c_val[2] = 0xFF;
  545. if (pin == 0)
  546. return;
  547. inv = (pin < 0);
  548. if (inv)
  549. pin = -pin;
  550. d_bit = 0;
  551. c_bit = 0;
  552. switch (pin) {
  553. case PIN_STROBE: /* strobe, inverted */
  554. c_bit = PNL_PSTROBE;
  555. inv = !inv;
  556. break;
  557. case PIN_D0...PIN_D7: /* D0 - D7 = 2 - 9 */
  558. d_bit = 1 << (pin - 2);
  559. break;
  560. case PIN_AUTOLF: /* autofeed, inverted */
  561. c_bit = PNL_PAUTOLF;
  562. inv = !inv;
  563. break;
  564. case PIN_INITP: /* init, direct */
  565. c_bit = PNL_PINITP;
  566. break;
  567. case PIN_SELECP: /* select_in, inverted */
  568. c_bit = PNL_PSELECP;
  569. inv = !inv;
  570. break;
  571. default: /* unknown pin, ignore */
  572. break;
  573. }
  574. if (c_bit) {
  575. c_val[2] &= ~c_bit;
  576. c_val[!inv] = c_bit;
  577. } else if (d_bit) {
  578. d_val[2] &= ~d_bit;
  579. d_val[!inv] = d_bit;
  580. }
  581. }
  582. /*
  583. * send a serial byte to the LCD panel. The caller is responsible for locking
  584. * if needed.
  585. */
  586. static void lcd_send_serial(int byte)
  587. {
  588. int bit;
  589. /*
  590. * the data bit is set on D0, and the clock on STROBE.
  591. * LCD reads D0 on STROBE's rising edge.
  592. */
  593. for (bit = 0; bit < 8; bit++) {
  594. clear_bit(LCD_BIT_CL, bits); /* CLK low */
  595. panel_set_bits();
  596. if (byte & 1) {
  597. set_bit(LCD_BIT_DA, bits);
  598. } else {
  599. clear_bit(LCD_BIT_DA, bits);
  600. }
  601. panel_set_bits();
  602. udelay(2); /* maintain the data during 2 us before CLK up */
  603. set_bit(LCD_BIT_CL, bits); /* CLK high */
  604. panel_set_bits();
  605. udelay(1); /* maintain the strobe during 1 us */
  606. byte >>= 1;
  607. }
  608. }
  609. /* turn the backlight on or off */
  610. static void lcd_backlight(struct charlcd *charlcd, int on)
  611. {
  612. if (lcd.pins.bl == PIN_NONE)
  613. return;
  614. /* The backlight is activated by setting the AUTOFEED line to +5V */
  615. spin_lock_irq(&pprt_lock);
  616. if (on)
  617. set_bit(LCD_BIT_BL, bits);
  618. else
  619. clear_bit(LCD_BIT_BL, bits);
  620. panel_set_bits();
  621. spin_unlock_irq(&pprt_lock);
  622. }
  623. /* send a command to the LCD panel in serial mode */
  624. static void lcd_write_cmd_s(struct charlcd *charlcd, int cmd)
  625. {
  626. spin_lock_irq(&pprt_lock);
  627. lcd_send_serial(0x1F); /* R/W=W, RS=0 */
  628. lcd_send_serial(cmd & 0x0F);
  629. lcd_send_serial((cmd >> 4) & 0x0F);
  630. udelay(40); /* the shortest command takes at least 40 us */
  631. spin_unlock_irq(&pprt_lock);
  632. }
  633. /* send data to the LCD panel in serial mode */
  634. static void lcd_write_data_s(struct charlcd *charlcd, int data)
  635. {
  636. spin_lock_irq(&pprt_lock);
  637. lcd_send_serial(0x5F); /* R/W=W, RS=1 */
  638. lcd_send_serial(data & 0x0F);
  639. lcd_send_serial((data >> 4) & 0x0F);
  640. udelay(40); /* the shortest data takes at least 40 us */
  641. spin_unlock_irq(&pprt_lock);
  642. }
  643. /* send a command to the LCD panel in 8 bits parallel mode */
  644. static void lcd_write_cmd_p8(struct charlcd *charlcd, int cmd)
  645. {
  646. spin_lock_irq(&pprt_lock);
  647. /* present the data to the data port */
  648. w_dtr(pprt, cmd);
  649. udelay(20); /* maintain the data during 20 us before the strobe */
  650. set_bit(LCD_BIT_E, bits);
  651. clear_bit(LCD_BIT_RS, bits);
  652. clear_bit(LCD_BIT_RW, bits);
  653. set_ctrl_bits();
  654. udelay(40); /* maintain the strobe during 40 us */
  655. clear_bit(LCD_BIT_E, bits);
  656. set_ctrl_bits();
  657. udelay(120); /* the shortest command takes at least 120 us */
  658. spin_unlock_irq(&pprt_lock);
  659. }
  660. /* send data to the LCD panel in 8 bits parallel mode */
  661. static void lcd_write_data_p8(struct charlcd *charlcd, int data)
  662. {
  663. spin_lock_irq(&pprt_lock);
  664. /* present the data to the data port */
  665. w_dtr(pprt, data);
  666. udelay(20); /* maintain the data during 20 us before the strobe */
  667. set_bit(LCD_BIT_E, bits);
  668. set_bit(LCD_BIT_RS, bits);
  669. clear_bit(LCD_BIT_RW, bits);
  670. set_ctrl_bits();
  671. udelay(40); /* maintain the strobe during 40 us */
  672. clear_bit(LCD_BIT_E, bits);
  673. set_ctrl_bits();
  674. udelay(45); /* the shortest data takes at least 45 us */
  675. spin_unlock_irq(&pprt_lock);
  676. }
  677. /* send a command to the TI LCD panel */
  678. static void lcd_write_cmd_tilcd(struct charlcd *charlcd, int cmd)
  679. {
  680. spin_lock_irq(&pprt_lock);
  681. /* present the data to the control port */
  682. w_ctr(pprt, cmd);
  683. udelay(60);
  684. spin_unlock_irq(&pprt_lock);
  685. }
  686. /* send data to the TI LCD panel */
  687. static void lcd_write_data_tilcd(struct charlcd *charlcd, int data)
  688. {
  689. spin_lock_irq(&pprt_lock);
  690. /* present the data to the data port */
  691. w_dtr(pprt, data);
  692. udelay(60);
  693. spin_unlock_irq(&pprt_lock);
  694. }
  695. /* fills the display with spaces and resets X/Y */
  696. static void lcd_clear_fast_s(struct charlcd *charlcd)
  697. {
  698. int pos;
  699. spin_lock_irq(&pprt_lock);
  700. for (pos = 0; pos < charlcd->height * charlcd->hwidth; pos++) {
  701. lcd_send_serial(0x5F); /* R/W=W, RS=1 */
  702. lcd_send_serial(' ' & 0x0F);
  703. lcd_send_serial((' ' >> 4) & 0x0F);
  704. /* the shortest data takes at least 40 us */
  705. udelay(40);
  706. }
  707. spin_unlock_irq(&pprt_lock);
  708. }
  709. /* fills the display with spaces and resets X/Y */
  710. static void lcd_clear_fast_p8(struct charlcd *charlcd)
  711. {
  712. int pos;
  713. spin_lock_irq(&pprt_lock);
  714. for (pos = 0; pos < charlcd->height * charlcd->hwidth; pos++) {
  715. /* present the data to the data port */
  716. w_dtr(pprt, ' ');
  717. /* maintain the data during 20 us before the strobe */
  718. udelay(20);
  719. set_bit(LCD_BIT_E, bits);
  720. set_bit(LCD_BIT_RS, bits);
  721. clear_bit(LCD_BIT_RW, bits);
  722. set_ctrl_bits();
  723. /* maintain the strobe during 40 us */
  724. udelay(40);
  725. clear_bit(LCD_BIT_E, bits);
  726. set_ctrl_bits();
  727. /* the shortest data takes at least 45 us */
  728. udelay(45);
  729. }
  730. spin_unlock_irq(&pprt_lock);
  731. }
  732. /* fills the display with spaces and resets X/Y */
  733. static void lcd_clear_fast_tilcd(struct charlcd *charlcd)
  734. {
  735. int pos;
  736. spin_lock_irq(&pprt_lock);
  737. for (pos = 0; pos < charlcd->height * charlcd->hwidth; pos++) {
  738. /* present the data to the data port */
  739. w_dtr(pprt, ' ');
  740. udelay(60);
  741. }
  742. spin_unlock_irq(&pprt_lock);
  743. }
  744. static const struct charlcd_ops charlcd_serial_ops = {
  745. .write_cmd = lcd_write_cmd_s,
  746. .write_data = lcd_write_data_s,
  747. .clear_fast = lcd_clear_fast_s,
  748. .backlight = lcd_backlight,
  749. };
  750. static const struct charlcd_ops charlcd_parallel_ops = {
  751. .write_cmd = lcd_write_cmd_p8,
  752. .write_data = lcd_write_data_p8,
  753. .clear_fast = lcd_clear_fast_p8,
  754. .backlight = lcd_backlight,
  755. };
  756. static const struct charlcd_ops charlcd_tilcd_ops = {
  757. .write_cmd = lcd_write_cmd_tilcd,
  758. .write_data = lcd_write_data_tilcd,
  759. .clear_fast = lcd_clear_fast_tilcd,
  760. .backlight = lcd_backlight,
  761. };
  762. /* initialize the LCD driver */
  763. static void lcd_init(void)
  764. {
  765. struct charlcd *charlcd;
  766. charlcd = charlcd_alloc(0);
  767. if (!charlcd)
  768. return;
  769. /*
  770. * Init lcd struct with load-time values to preserve exact
  771. * current functionality (at least for now).
  772. */
  773. charlcd->height = lcd_height;
  774. charlcd->width = lcd_width;
  775. charlcd->bwidth = lcd_bwidth;
  776. charlcd->hwidth = lcd_hwidth;
  777. switch (selected_lcd_type) {
  778. case LCD_TYPE_OLD:
  779. /* parallel mode, 8 bits */
  780. lcd.proto = LCD_PROTO_PARALLEL;
  781. lcd.charset = LCD_CHARSET_NORMAL;
  782. lcd.pins.e = PIN_STROBE;
  783. lcd.pins.rs = PIN_AUTOLF;
  784. charlcd->width = 40;
  785. charlcd->bwidth = 40;
  786. charlcd->hwidth = 64;
  787. charlcd->height = 2;
  788. break;
  789. case LCD_TYPE_KS0074:
  790. /* serial mode, ks0074 */
  791. lcd.proto = LCD_PROTO_SERIAL;
  792. lcd.charset = LCD_CHARSET_KS0074;
  793. lcd.pins.bl = PIN_AUTOLF;
  794. lcd.pins.cl = PIN_STROBE;
  795. lcd.pins.da = PIN_D0;
  796. charlcd->width = 16;
  797. charlcd->bwidth = 40;
  798. charlcd->hwidth = 16;
  799. charlcd->height = 2;
  800. break;
  801. case LCD_TYPE_NEXCOM:
  802. /* parallel mode, 8 bits, generic */
  803. lcd.proto = LCD_PROTO_PARALLEL;
  804. lcd.charset = LCD_CHARSET_NORMAL;
  805. lcd.pins.e = PIN_AUTOLF;
  806. lcd.pins.rs = PIN_SELECP;
  807. lcd.pins.rw = PIN_INITP;
  808. charlcd->width = 16;
  809. charlcd->bwidth = 40;
  810. charlcd->hwidth = 64;
  811. charlcd->height = 2;
  812. break;
  813. case LCD_TYPE_CUSTOM:
  814. /* customer-defined */
  815. lcd.proto = DEFAULT_LCD_PROTO;
  816. lcd.charset = DEFAULT_LCD_CHARSET;
  817. /* default geometry will be set later */
  818. break;
  819. case LCD_TYPE_HANTRONIX:
  820. /* parallel mode, 8 bits, hantronix-like */
  821. default:
  822. lcd.proto = LCD_PROTO_PARALLEL;
  823. lcd.charset = LCD_CHARSET_NORMAL;
  824. lcd.pins.e = PIN_STROBE;
  825. lcd.pins.rs = PIN_SELECP;
  826. charlcd->width = 16;
  827. charlcd->bwidth = 40;
  828. charlcd->hwidth = 64;
  829. charlcd->height = 2;
  830. break;
  831. }
  832. /* Overwrite with module params set on loading */
  833. if (lcd_height != NOT_SET)
  834. charlcd->height = lcd_height;
  835. if (lcd_width != NOT_SET)
  836. charlcd->width = lcd_width;
  837. if (lcd_bwidth != NOT_SET)
  838. charlcd->bwidth = lcd_bwidth;
  839. if (lcd_hwidth != NOT_SET)
  840. charlcd->hwidth = lcd_hwidth;
  841. if (lcd_charset != NOT_SET)
  842. lcd.charset = lcd_charset;
  843. if (lcd_proto != NOT_SET)
  844. lcd.proto = lcd_proto;
  845. if (lcd_e_pin != PIN_NOT_SET)
  846. lcd.pins.e = lcd_e_pin;
  847. if (lcd_rs_pin != PIN_NOT_SET)
  848. lcd.pins.rs = lcd_rs_pin;
  849. if (lcd_rw_pin != PIN_NOT_SET)
  850. lcd.pins.rw = lcd_rw_pin;
  851. if (lcd_cl_pin != PIN_NOT_SET)
  852. lcd.pins.cl = lcd_cl_pin;
  853. if (lcd_da_pin != PIN_NOT_SET)
  854. lcd.pins.da = lcd_da_pin;
  855. if (lcd_bl_pin != PIN_NOT_SET)
  856. lcd.pins.bl = lcd_bl_pin;
  857. /* this is used to catch wrong and default values */
  858. if (charlcd->width <= 0)
  859. charlcd->width = DEFAULT_LCD_WIDTH;
  860. if (charlcd->bwidth <= 0)
  861. charlcd->bwidth = DEFAULT_LCD_BWIDTH;
  862. if (charlcd->hwidth <= 0)
  863. charlcd->hwidth = DEFAULT_LCD_HWIDTH;
  864. if (charlcd->height <= 0)
  865. charlcd->height = DEFAULT_LCD_HEIGHT;
  866. if (lcd.proto == LCD_PROTO_SERIAL) { /* SERIAL */
  867. charlcd->ops = &charlcd_serial_ops;
  868. if (lcd.pins.cl == PIN_NOT_SET)
  869. lcd.pins.cl = DEFAULT_LCD_PIN_SCL;
  870. if (lcd.pins.da == PIN_NOT_SET)
  871. lcd.pins.da = DEFAULT_LCD_PIN_SDA;
  872. } else if (lcd.proto == LCD_PROTO_PARALLEL) { /* PARALLEL */
  873. charlcd->ops = &charlcd_parallel_ops;
  874. if (lcd.pins.e == PIN_NOT_SET)
  875. lcd.pins.e = DEFAULT_LCD_PIN_E;
  876. if (lcd.pins.rs == PIN_NOT_SET)
  877. lcd.pins.rs = DEFAULT_LCD_PIN_RS;
  878. if (lcd.pins.rw == PIN_NOT_SET)
  879. lcd.pins.rw = DEFAULT_LCD_PIN_RW;
  880. } else {
  881. charlcd->ops = &charlcd_tilcd_ops;
  882. }
  883. if (lcd.pins.bl == PIN_NOT_SET)
  884. lcd.pins.bl = DEFAULT_LCD_PIN_BL;
  885. if (lcd.pins.e == PIN_NOT_SET)
  886. lcd.pins.e = PIN_NONE;
  887. if (lcd.pins.rs == PIN_NOT_SET)
  888. lcd.pins.rs = PIN_NONE;
  889. if (lcd.pins.rw == PIN_NOT_SET)
  890. lcd.pins.rw = PIN_NONE;
  891. if (lcd.pins.bl == PIN_NOT_SET)
  892. lcd.pins.bl = PIN_NONE;
  893. if (lcd.pins.cl == PIN_NOT_SET)
  894. lcd.pins.cl = PIN_NONE;
  895. if (lcd.pins.da == PIN_NOT_SET)
  896. lcd.pins.da = PIN_NONE;
  897. if (lcd.charset == NOT_SET)
  898. lcd.charset = DEFAULT_LCD_CHARSET;
  899. if (lcd.charset == LCD_CHARSET_KS0074)
  900. charlcd->char_conv = lcd_char_conv_ks0074;
  901. else
  902. charlcd->char_conv = NULL;
  903. pin_to_bits(lcd.pins.e, lcd_bits[LCD_PORT_D][LCD_BIT_E],
  904. lcd_bits[LCD_PORT_C][LCD_BIT_E]);
  905. pin_to_bits(lcd.pins.rs, lcd_bits[LCD_PORT_D][LCD_BIT_RS],
  906. lcd_bits[LCD_PORT_C][LCD_BIT_RS]);
  907. pin_to_bits(lcd.pins.rw, lcd_bits[LCD_PORT_D][LCD_BIT_RW],
  908. lcd_bits[LCD_PORT_C][LCD_BIT_RW]);
  909. pin_to_bits(lcd.pins.bl, lcd_bits[LCD_PORT_D][LCD_BIT_BL],
  910. lcd_bits[LCD_PORT_C][LCD_BIT_BL]);
  911. pin_to_bits(lcd.pins.cl, lcd_bits[LCD_PORT_D][LCD_BIT_CL],
  912. lcd_bits[LCD_PORT_C][LCD_BIT_CL]);
  913. pin_to_bits(lcd.pins.da, lcd_bits[LCD_PORT_D][LCD_BIT_DA],
  914. lcd_bits[LCD_PORT_C][LCD_BIT_DA]);
  915. lcd.charlcd = charlcd;
  916. lcd.initialized = true;
  917. }
  918. /*
  919. * These are the file operation function for user access to /dev/keypad
  920. */
  921. static ssize_t keypad_read(struct file *file,
  922. char __user *buf, size_t count, loff_t *ppos)
  923. {
  924. unsigned i = *ppos;
  925. char __user *tmp = buf;
  926. if (keypad_buflen == 0) {
  927. if (file->f_flags & O_NONBLOCK)
  928. return -EAGAIN;
  929. if (wait_event_interruptible(keypad_read_wait,
  930. keypad_buflen != 0))
  931. return -EINTR;
  932. }
  933. for (; count-- > 0 && (keypad_buflen > 0);
  934. ++i, ++tmp, --keypad_buflen) {
  935. put_user(keypad_buffer[keypad_start], tmp);
  936. keypad_start = (keypad_start + 1) % KEYPAD_BUFFER;
  937. }
  938. *ppos = i;
  939. return tmp - buf;
  940. }
  941. static int keypad_open(struct inode *inode, struct file *file)
  942. {
  943. int ret;
  944. ret = -EBUSY;
  945. if (!atomic_dec_and_test(&keypad_available))
  946. goto fail; /* open only once at a time */
  947. ret = -EPERM;
  948. if (file->f_mode & FMODE_WRITE) /* device is read-only */
  949. goto fail;
  950. keypad_buflen = 0; /* flush the buffer on opening */
  951. return 0;
  952. fail:
  953. atomic_inc(&keypad_available);
  954. return ret;
  955. }
  956. static int keypad_release(struct inode *inode, struct file *file)
  957. {
  958. atomic_inc(&keypad_available);
  959. return 0;
  960. }
  961. static const struct file_operations keypad_fops = {
  962. .read = keypad_read, /* read */
  963. .open = keypad_open, /* open */
  964. .release = keypad_release, /* close */
  965. .llseek = default_llseek,
  966. };
  967. static struct miscdevice keypad_dev = {
  968. .minor = KEYPAD_MINOR,
  969. .name = "keypad",
  970. .fops = &keypad_fops,
  971. };
  972. static void keypad_send_key(const char *string, int max_len)
  973. {
  974. /* send the key to the device only if a process is attached to it. */
  975. if (!atomic_read(&keypad_available)) {
  976. while (max_len-- && keypad_buflen < KEYPAD_BUFFER && *string) {
  977. keypad_buffer[(keypad_start + keypad_buflen++) %
  978. KEYPAD_BUFFER] = *string++;
  979. }
  980. wake_up_interruptible(&keypad_read_wait);
  981. }
  982. }
  983. /* this function scans all the bits involving at least one logical signal,
  984. * and puts the results in the bitfield "phys_read" (one bit per established
  985. * contact), and sets "phys_read_prev" to "phys_read".
  986. *
  987. * Note: to debounce input signals, we will only consider as switched a signal
  988. * which is stable across 2 measures. Signals which are different between two
  989. * reads will be kept as they previously were in their logical form (phys_prev).
  990. * A signal which has just switched will have a 1 in
  991. * (phys_read ^ phys_read_prev).
  992. */
  993. static void phys_scan_contacts(void)
  994. {
  995. int bit, bitval;
  996. char oldval;
  997. char bitmask;
  998. char gndmask;
  999. phys_prev = phys_curr;
  1000. phys_read_prev = phys_read;
  1001. phys_read = 0; /* flush all signals */
  1002. /* keep track of old value, with all outputs disabled */
  1003. oldval = r_dtr(pprt) | scan_mask_o;
  1004. /* activate all keyboard outputs (active low) */
  1005. w_dtr(pprt, oldval & ~scan_mask_o);
  1006. /* will have a 1 for each bit set to gnd */
  1007. bitmask = PNL_PINPUT(r_str(pprt)) & scan_mask_i;
  1008. /* disable all matrix signals */
  1009. w_dtr(pprt, oldval);
  1010. /* now that all outputs are cleared, the only active input bits are
  1011. * directly connected to the ground
  1012. */
  1013. /* 1 for each grounded input */
  1014. gndmask = PNL_PINPUT(r_str(pprt)) & scan_mask_i;
  1015. /* grounded inputs are signals 40-44 */
  1016. phys_read |= (__u64)gndmask << 40;
  1017. if (bitmask != gndmask) {
  1018. /*
  1019. * since clearing the outputs changed some inputs, we know
  1020. * that some input signals are currently tied to some outputs.
  1021. * So we'll scan them.
  1022. */
  1023. for (bit = 0; bit < 8; bit++) {
  1024. bitval = BIT(bit);
  1025. if (!(scan_mask_o & bitval)) /* skip unused bits */
  1026. continue;
  1027. w_dtr(pprt, oldval & ~bitval); /* enable this output */
  1028. bitmask = PNL_PINPUT(r_str(pprt)) & ~gndmask;
  1029. phys_read |= (__u64)bitmask << (5 * bit);
  1030. }
  1031. w_dtr(pprt, oldval); /* disable all outputs */
  1032. }
  1033. /*
  1034. * this is easy: use old bits when they are flapping,
  1035. * use new ones when stable
  1036. */
  1037. phys_curr = (phys_prev & (phys_read ^ phys_read_prev)) |
  1038. (phys_read & ~(phys_read ^ phys_read_prev));
  1039. }
  1040. static inline int input_state_high(struct logical_input *input)
  1041. {
  1042. #if 0
  1043. /* FIXME:
  1044. * this is an invalid test. It tries to catch
  1045. * transitions from single-key to multiple-key, but
  1046. * doesn't take into account the contacts polarity.
  1047. * The only solution to the problem is to parse keys
  1048. * from the most complex to the simplest combinations,
  1049. * and mark them as 'caught' once a combination
  1050. * matches, then unmatch it for all other ones.
  1051. */
  1052. /* try to catch dangerous transitions cases :
  1053. * someone adds a bit, so this signal was a false
  1054. * positive resulting from a transition. We should
  1055. * invalidate the signal immediately and not call the
  1056. * release function.
  1057. * eg: 0 -(press A)-> A -(press B)-> AB : don't match A's release.
  1058. */
  1059. if (((phys_prev & input->mask) == input->value) &&
  1060. ((phys_curr & input->mask) > input->value)) {
  1061. input->state = INPUT_ST_LOW; /* invalidate */
  1062. return 1;
  1063. }
  1064. #endif
  1065. if ((phys_curr & input->mask) == input->value) {
  1066. if ((input->type == INPUT_TYPE_STD) &&
  1067. (input->high_timer == 0)) {
  1068. input->high_timer++;
  1069. if (input->u.std.press_fct)
  1070. input->u.std.press_fct(input->u.std.press_data);
  1071. } else if (input->type == INPUT_TYPE_KBD) {
  1072. /* will turn on the light */
  1073. keypressed = 1;
  1074. if (input->high_timer == 0) {
  1075. char *press_str = input->u.kbd.press_str;
  1076. if (press_str[0]) {
  1077. int s = sizeof(input->u.kbd.press_str);
  1078. keypad_send_key(press_str, s);
  1079. }
  1080. }
  1081. if (input->u.kbd.repeat_str[0]) {
  1082. char *repeat_str = input->u.kbd.repeat_str;
  1083. if (input->high_timer >= KEYPAD_REP_START) {
  1084. int s = sizeof(input->u.kbd.repeat_str);
  1085. input->high_timer -= KEYPAD_REP_DELAY;
  1086. keypad_send_key(repeat_str, s);
  1087. }
  1088. /* we will need to come back here soon */
  1089. inputs_stable = 0;
  1090. }
  1091. if (input->high_timer < 255)
  1092. input->high_timer++;
  1093. }
  1094. return 1;
  1095. }
  1096. /* else signal falling down. Let's fall through. */
  1097. input->state = INPUT_ST_FALLING;
  1098. input->fall_timer = 0;
  1099. return 0;
  1100. }
  1101. static inline void input_state_falling(struct logical_input *input)
  1102. {
  1103. #if 0
  1104. /* FIXME !!! same comment as in input_state_high */
  1105. if (((phys_prev & input->mask) == input->value) &&
  1106. ((phys_curr & input->mask) > input->value)) {
  1107. input->state = INPUT_ST_LOW; /* invalidate */
  1108. return;
  1109. }
  1110. #endif
  1111. if ((phys_curr & input->mask) == input->value) {
  1112. if (input->type == INPUT_TYPE_KBD) {
  1113. /* will turn on the light */
  1114. keypressed = 1;
  1115. if (input->u.kbd.repeat_str[0]) {
  1116. char *repeat_str = input->u.kbd.repeat_str;
  1117. if (input->high_timer >= KEYPAD_REP_START) {
  1118. int s = sizeof(input->u.kbd.repeat_str);
  1119. input->high_timer -= KEYPAD_REP_DELAY;
  1120. keypad_send_key(repeat_str, s);
  1121. }
  1122. /* we will need to come back here soon */
  1123. inputs_stable = 0;
  1124. }
  1125. if (input->high_timer < 255)
  1126. input->high_timer++;
  1127. }
  1128. input->state = INPUT_ST_HIGH;
  1129. } else if (input->fall_timer >= input->fall_time) {
  1130. /* call release event */
  1131. if (input->type == INPUT_TYPE_STD) {
  1132. void (*release_fct)(int) = input->u.std.release_fct;
  1133. if (release_fct)
  1134. release_fct(input->u.std.release_data);
  1135. } else if (input->type == INPUT_TYPE_KBD) {
  1136. char *release_str = input->u.kbd.release_str;
  1137. if (release_str[0]) {
  1138. int s = sizeof(input->u.kbd.release_str);
  1139. keypad_send_key(release_str, s);
  1140. }
  1141. }
  1142. input->state = INPUT_ST_LOW;
  1143. } else {
  1144. input->fall_timer++;
  1145. inputs_stable = 0;
  1146. }
  1147. }
  1148. static void panel_process_inputs(void)
  1149. {
  1150. struct logical_input *input;
  1151. keypressed = 0;
  1152. inputs_stable = 1;
  1153. list_for_each_entry(input, &logical_inputs, list) {
  1154. switch (input->state) {
  1155. case INPUT_ST_LOW:
  1156. if ((phys_curr & input->mask) != input->value)
  1157. break;
  1158. /* if all needed ones were already set previously,
  1159. * this means that this logical signal has been
  1160. * activated by the releasing of another combined
  1161. * signal, so we don't want to match.
  1162. * eg: AB -(release B)-> A -(release A)-> 0 :
  1163. * don't match A.
  1164. */
  1165. if ((phys_prev & input->mask) == input->value)
  1166. break;
  1167. input->rise_timer = 0;
  1168. input->state = INPUT_ST_RISING;
  1169. /* no break here, fall through */
  1170. case INPUT_ST_RISING:
  1171. if ((phys_curr & input->mask) != input->value) {
  1172. input->state = INPUT_ST_LOW;
  1173. break;
  1174. }
  1175. if (input->rise_timer < input->rise_time) {
  1176. inputs_stable = 0;
  1177. input->rise_timer++;
  1178. break;
  1179. }
  1180. input->high_timer = 0;
  1181. input->state = INPUT_ST_HIGH;
  1182. /* no break here, fall through */
  1183. case INPUT_ST_HIGH:
  1184. if (input_state_high(input))
  1185. break;
  1186. /* no break here, fall through */
  1187. case INPUT_ST_FALLING:
  1188. input_state_falling(input);
  1189. }
  1190. }
  1191. }
  1192. static void panel_scan_timer(void)
  1193. {
  1194. if (keypad.enabled && keypad_initialized) {
  1195. if (spin_trylock_irq(&pprt_lock)) {
  1196. phys_scan_contacts();
  1197. /* no need for the parport anymore */
  1198. spin_unlock_irq(&pprt_lock);
  1199. }
  1200. if (!inputs_stable || phys_curr != phys_prev)
  1201. panel_process_inputs();
  1202. }
  1203. if (keypressed && lcd.enabled && lcd.initialized)
  1204. charlcd_poke(lcd.charlcd);
  1205. mod_timer(&scan_timer, jiffies + INPUT_POLL_TIME);
  1206. }
  1207. static void init_scan_timer(void)
  1208. {
  1209. if (scan_timer.function)
  1210. return; /* already started */
  1211. setup_timer(&scan_timer, (void *)&panel_scan_timer, 0);
  1212. scan_timer.expires = jiffies + INPUT_POLL_TIME;
  1213. add_timer(&scan_timer);
  1214. }
  1215. /* converts a name of the form "({BbAaPpSsEe}{01234567-})*" to a series of bits.
  1216. * if <omask> or <imask> are non-null, they will be or'ed with the bits
  1217. * corresponding to out and in bits respectively.
  1218. * returns 1 if ok, 0 if error (in which case, nothing is written).
  1219. */
  1220. static u8 input_name2mask(const char *name, __u64 *mask, __u64 *value,
  1221. u8 *imask, u8 *omask)
  1222. {
  1223. const char sigtab[] = "EeSsPpAaBb";
  1224. u8 im, om;
  1225. __u64 m, v;
  1226. om = 0;
  1227. im = 0;
  1228. m = 0ULL;
  1229. v = 0ULL;
  1230. while (*name) {
  1231. int in, out, bit, neg;
  1232. const char *idx;
  1233. idx = strchr(sigtab, *name);
  1234. if (!idx)
  1235. return 0; /* input name not found */
  1236. in = idx - sigtab;
  1237. neg = (in & 1); /* odd (lower) names are negated */
  1238. in >>= 1;
  1239. im |= BIT(in);
  1240. name++;
  1241. if (*name >= '0' && *name <= '7') {
  1242. out = *name - '0';
  1243. om |= BIT(out);
  1244. } else if (*name == '-') {
  1245. out = 8;
  1246. } else {
  1247. return 0; /* unknown bit name */
  1248. }
  1249. bit = (out * 5) + in;
  1250. m |= 1ULL << bit;
  1251. if (!neg)
  1252. v |= 1ULL << bit;
  1253. name++;
  1254. }
  1255. *mask = m;
  1256. *value = v;
  1257. if (imask)
  1258. *imask |= im;
  1259. if (omask)
  1260. *omask |= om;
  1261. return 1;
  1262. }
  1263. /* tries to bind a key to the signal name <name>. The key will send the
  1264. * strings <press>, <repeat>, <release> for these respective events.
  1265. * Returns the pointer to the new key if ok, NULL if the key could not be bound.
  1266. */
  1267. static struct logical_input *panel_bind_key(const char *name, const char *press,
  1268. const char *repeat,
  1269. const char *release)
  1270. {
  1271. struct logical_input *key;
  1272. key = kzalloc(sizeof(*key), GFP_KERNEL);
  1273. if (!key)
  1274. return NULL;
  1275. if (!input_name2mask(name, &key->mask, &key->value, &scan_mask_i,
  1276. &scan_mask_o)) {
  1277. kfree(key);
  1278. return NULL;
  1279. }
  1280. key->type = INPUT_TYPE_KBD;
  1281. key->state = INPUT_ST_LOW;
  1282. key->rise_time = 1;
  1283. key->fall_time = 1;
  1284. strncpy(key->u.kbd.press_str, press, sizeof(key->u.kbd.press_str));
  1285. strncpy(key->u.kbd.repeat_str, repeat, sizeof(key->u.kbd.repeat_str));
  1286. strncpy(key->u.kbd.release_str, release,
  1287. sizeof(key->u.kbd.release_str));
  1288. list_add(&key->list, &logical_inputs);
  1289. return key;
  1290. }
  1291. #if 0
  1292. /* tries to bind a callback function to the signal name <name>. The function
  1293. * <press_fct> will be called with the <press_data> arg when the signal is
  1294. * activated, and so on for <release_fct>/<release_data>
  1295. * Returns the pointer to the new signal if ok, NULL if the signal could not
  1296. * be bound.
  1297. */
  1298. static struct logical_input *panel_bind_callback(char *name,
  1299. void (*press_fct)(int),
  1300. int press_data,
  1301. void (*release_fct)(int),
  1302. int release_data)
  1303. {
  1304. struct logical_input *callback;
  1305. callback = kmalloc(sizeof(*callback), GFP_KERNEL);
  1306. if (!callback)
  1307. return NULL;
  1308. memset(callback, 0, sizeof(struct logical_input));
  1309. if (!input_name2mask(name, &callback->mask, &callback->value,
  1310. &scan_mask_i, &scan_mask_o))
  1311. return NULL;
  1312. callback->type = INPUT_TYPE_STD;
  1313. callback->state = INPUT_ST_LOW;
  1314. callback->rise_time = 1;
  1315. callback->fall_time = 1;
  1316. callback->u.std.press_fct = press_fct;
  1317. callback->u.std.press_data = press_data;
  1318. callback->u.std.release_fct = release_fct;
  1319. callback->u.std.release_data = release_data;
  1320. list_add(&callback->list, &logical_inputs);
  1321. return callback;
  1322. }
  1323. #endif
  1324. static void keypad_init(void)
  1325. {
  1326. int keynum;
  1327. init_waitqueue_head(&keypad_read_wait);
  1328. keypad_buflen = 0; /* flushes any eventual noisy keystroke */
  1329. /* Let's create all known keys */
  1330. for (keynum = 0; keypad_profile[keynum][0][0]; keynum++) {
  1331. panel_bind_key(keypad_profile[keynum][0],
  1332. keypad_profile[keynum][1],
  1333. keypad_profile[keynum][2],
  1334. keypad_profile[keynum][3]);
  1335. }
  1336. init_scan_timer();
  1337. keypad_initialized = 1;
  1338. }
  1339. /**************************************************/
  1340. /* device initialization */
  1341. /**************************************************/
  1342. static void panel_attach(struct parport *port)
  1343. {
  1344. struct pardev_cb panel_cb;
  1345. if (port->number != parport)
  1346. return;
  1347. if (pprt) {
  1348. pr_err("%s: port->number=%d parport=%d, already registered!\n",
  1349. __func__, port->number, parport);
  1350. return;
  1351. }
  1352. memset(&panel_cb, 0, sizeof(panel_cb));
  1353. panel_cb.private = &pprt;
  1354. /* panel_cb.flags = 0 should be PARPORT_DEV_EXCL? */
  1355. pprt = parport_register_dev_model(port, "panel", &panel_cb, 0);
  1356. if (!pprt) {
  1357. pr_err("%s: port->number=%d parport=%d, parport_register_device() failed\n",
  1358. __func__, port->number, parport);
  1359. return;
  1360. }
  1361. if (parport_claim(pprt)) {
  1362. pr_err("could not claim access to parport%d. Aborting.\n",
  1363. parport);
  1364. goto err_unreg_device;
  1365. }
  1366. /* must init LCD first, just in case an IRQ from the keypad is
  1367. * generated at keypad init
  1368. */
  1369. if (lcd.enabled) {
  1370. lcd_init();
  1371. if (!lcd.charlcd || charlcd_register(lcd.charlcd))
  1372. goto err_unreg_device;
  1373. }
  1374. if (keypad.enabled) {
  1375. keypad_init();
  1376. if (misc_register(&keypad_dev))
  1377. goto err_lcd_unreg;
  1378. }
  1379. return;
  1380. err_lcd_unreg:
  1381. if (lcd.enabled)
  1382. charlcd_unregister(lcd.charlcd);
  1383. err_unreg_device:
  1384. kfree(lcd.charlcd);
  1385. lcd.charlcd = NULL;
  1386. parport_unregister_device(pprt);
  1387. pprt = NULL;
  1388. }
  1389. static void panel_detach(struct parport *port)
  1390. {
  1391. if (port->number != parport)
  1392. return;
  1393. if (!pprt) {
  1394. pr_err("%s: port->number=%d parport=%d, nothing to unregister.\n",
  1395. __func__, port->number, parport);
  1396. return;
  1397. }
  1398. if (scan_timer.function)
  1399. del_timer_sync(&scan_timer);
  1400. if (keypad.enabled) {
  1401. misc_deregister(&keypad_dev);
  1402. keypad_initialized = 0;
  1403. }
  1404. if (lcd.enabled) {
  1405. charlcd_unregister(lcd.charlcd);
  1406. lcd.initialized = false;
  1407. kfree(lcd.charlcd);
  1408. lcd.charlcd = NULL;
  1409. }
  1410. /* TODO: free all input signals */
  1411. parport_release(pprt);
  1412. parport_unregister_device(pprt);
  1413. pprt = NULL;
  1414. }
  1415. static struct parport_driver panel_driver = {
  1416. .name = "panel",
  1417. .match_port = panel_attach,
  1418. .detach = panel_detach,
  1419. .devmodel = true,
  1420. };
  1421. /* init function */
  1422. static int __init panel_init_module(void)
  1423. {
  1424. int selected_keypad_type = NOT_SET, err;
  1425. /* take care of an eventual profile */
  1426. switch (profile) {
  1427. case PANEL_PROFILE_CUSTOM:
  1428. /* custom profile */
  1429. selected_keypad_type = DEFAULT_KEYPAD_TYPE;
  1430. selected_lcd_type = DEFAULT_LCD_TYPE;
  1431. break;
  1432. case PANEL_PROFILE_OLD:
  1433. /* 8 bits, 2*16, old keypad */
  1434. selected_keypad_type = KEYPAD_TYPE_OLD;
  1435. selected_lcd_type = LCD_TYPE_OLD;
  1436. /* TODO: This two are a little hacky, sort it out later */
  1437. if (lcd_width == NOT_SET)
  1438. lcd_width = 16;
  1439. if (lcd_hwidth == NOT_SET)
  1440. lcd_hwidth = 16;
  1441. break;
  1442. case PANEL_PROFILE_NEW:
  1443. /* serial, 2*16, new keypad */
  1444. selected_keypad_type = KEYPAD_TYPE_NEW;
  1445. selected_lcd_type = LCD_TYPE_KS0074;
  1446. break;
  1447. case PANEL_PROFILE_HANTRONIX:
  1448. /* 8 bits, 2*16 hantronix-like, no keypad */
  1449. selected_keypad_type = KEYPAD_TYPE_NONE;
  1450. selected_lcd_type = LCD_TYPE_HANTRONIX;
  1451. break;
  1452. case PANEL_PROFILE_NEXCOM:
  1453. /* generic 8 bits, 2*16, nexcom keypad, eg. Nexcom. */
  1454. selected_keypad_type = KEYPAD_TYPE_NEXCOM;
  1455. selected_lcd_type = LCD_TYPE_NEXCOM;
  1456. break;
  1457. case PANEL_PROFILE_LARGE:
  1458. /* 8 bits, 2*40, old keypad */
  1459. selected_keypad_type = KEYPAD_TYPE_OLD;
  1460. selected_lcd_type = LCD_TYPE_OLD;
  1461. break;
  1462. }
  1463. /*
  1464. * Overwrite selection with module param values (both keypad and lcd),
  1465. * where the deprecated params have lower prio.
  1466. */
  1467. if (keypad_enabled != NOT_SET)
  1468. selected_keypad_type = keypad_enabled;
  1469. if (keypad_type != NOT_SET)
  1470. selected_keypad_type = keypad_type;
  1471. keypad.enabled = (selected_keypad_type > 0);
  1472. if (lcd_enabled != NOT_SET)
  1473. selected_lcd_type = lcd_enabled;
  1474. if (lcd_type != NOT_SET)
  1475. selected_lcd_type = lcd_type;
  1476. lcd.enabled = (selected_lcd_type > 0);
  1477. if (lcd.enabled) {
  1478. /*
  1479. * Init lcd struct with load-time values to preserve exact
  1480. * current functionality (at least for now).
  1481. */
  1482. lcd.charset = lcd_charset;
  1483. lcd.proto = lcd_proto;
  1484. lcd.pins.e = lcd_e_pin;
  1485. lcd.pins.rs = lcd_rs_pin;
  1486. lcd.pins.rw = lcd_rw_pin;
  1487. lcd.pins.cl = lcd_cl_pin;
  1488. lcd.pins.da = lcd_da_pin;
  1489. lcd.pins.bl = lcd_bl_pin;
  1490. }
  1491. switch (selected_keypad_type) {
  1492. case KEYPAD_TYPE_OLD:
  1493. keypad_profile = old_keypad_profile;
  1494. break;
  1495. case KEYPAD_TYPE_NEW:
  1496. keypad_profile = new_keypad_profile;
  1497. break;
  1498. case KEYPAD_TYPE_NEXCOM:
  1499. keypad_profile = nexcom_keypad_profile;
  1500. break;
  1501. default:
  1502. keypad_profile = NULL;
  1503. break;
  1504. }
  1505. if (!lcd.enabled && !keypad.enabled) {
  1506. /* no device enabled, let's exit */
  1507. pr_err("panel driver disabled.\n");
  1508. return -ENODEV;
  1509. }
  1510. err = parport_register_driver(&panel_driver);
  1511. if (err) {
  1512. pr_err("could not register with parport. Aborting.\n");
  1513. return err;
  1514. }
  1515. if (pprt)
  1516. pr_info("panel driver registered on parport%d (io=0x%lx).\n",
  1517. parport, pprt->port->base);
  1518. else
  1519. pr_info("panel driver not yet registered\n");
  1520. return 0;
  1521. }
  1522. static void __exit panel_cleanup_module(void)
  1523. {
  1524. parport_unregister_driver(&panel_driver);
  1525. }
  1526. module_init(panel_init_module);
  1527. module_exit(panel_cleanup_module);
  1528. MODULE_AUTHOR("Willy Tarreau");
  1529. MODULE_LICENSE("GPL");
  1530. /*
  1531. * Local variables:
  1532. * c-indent-level: 4
  1533. * tab-width: 8
  1534. * End:
  1535. */