panel.c 45 KB

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