panel.c 47 KB

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