panel.c 47 KB

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