2008-11-14 01:18:59 +00:00
|
|
|
/*
|
2008-11-22 10:29:33 +00:00
|
|
|
* Front panel driver for Linux
|
|
|
|
* Copyright (C) 2000-2008, Willy Tarreau <w@1wt.eu>
|
2008-11-14 01:18:59 +00:00
|
|
|
*
|
2008-11-22 10:29:33 +00:00
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version
|
|
|
|
* 2 of the License, or (at your option) any later version.
|
2008-11-14 01:18:59 +00:00
|
|
|
*
|
2008-11-22 10:29:33 +00:00
|
|
|
* This code drives an LCD module (/dev/lcd), and a keypad (/dev/keypad)
|
|
|
|
* connected to a parallel printer port.
|
2008-11-14 01:18:59 +00:00
|
|
|
*
|
2008-11-22 10:29:33 +00:00
|
|
|
* The LCD module may either be an HD44780-like 8-bit parallel LCD, or a 1-bit
|
|
|
|
* serial module compatible with Samsung's KS0074. The pins may be connected in
|
|
|
|
* any combination, everything is programmable.
|
2008-11-14 01:18:59 +00:00
|
|
|
*
|
2008-11-22 10:29:33 +00:00
|
|
|
* The keypad consists in a matrix of push buttons connecting input pins to
|
|
|
|
* data output pins or to the ground. The combinations have to be hard-coded
|
|
|
|
* in the driver, though several profiles exist and adding new ones is easy.
|
2008-11-14 01:18:59 +00:00
|
|
|
*
|
2008-11-22 10:29:33 +00:00
|
|
|
* Several profiles are provided for commonly found LCD+keypad modules on the
|
|
|
|
* market, such as those found in Nexcom's appliances.
|
2008-11-14 01:18:59 +00:00
|
|
|
*
|
|
|
|
* FIXME:
|
|
|
|
* - the initialization/deinitialization process is very dirty and should
|
|
|
|
* be rewritten. It may even be buggy.
|
|
|
|
*
|
|
|
|
* TODO:
|
|
|
|
* - document 24 keys keyboard (3 rows of 8 cols, 32 diodes + 2 inputs)
|
|
|
|
* - make the LCD a part of a virtual screen of Vx*Vy
|
|
|
|
* - make the inputs list smp-safe
|
|
|
|
* - change the keyboard to a double mapping : signals -> key_id -> values
|
|
|
|
* so that applications can change values without knowing signals
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2012-07-12 13:01:00 +00:00
|
|
|
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
|
|
|
|
|
2008-11-14 01:18:59 +00:00
|
|
|
#include <linux/module.h>
|
|
|
|
|
|
|
|
#include <linux/types.h>
|
|
|
|
#include <linux/errno.h>
|
|
|
|
#include <linux/signal.h>
|
|
|
|
#include <linux/sched.h>
|
|
|
|
#include <linux/spinlock.h>
|
|
|
|
#include <linux/interrupt.h>
|
|
|
|
#include <linux/miscdevice.h>
|
2008-11-22 10:29:33 +00:00
|
|
|
#include <linux/slab.h>
|
2008-11-14 01:18:59 +00:00
|
|
|
#include <linux/ioport.h>
|
|
|
|
#include <linux/fcntl.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/delay.h>
|
2010-07-22 16:57:08 +00:00
|
|
|
#include <linux/kernel.h>
|
2008-11-14 01:18:59 +00:00
|
|
|
#include <linux/ctype.h>
|
|
|
|
#include <linux/parport.h>
|
|
|
|
#include <linux/list.h>
|
|
|
|
#include <linux/notifier.h>
|
|
|
|
#include <linux/reboot.h>
|
2017-02-06 14:38:10 +00:00
|
|
|
#include <linux/workqueue.h>
|
2009-10-17 22:52:28 +00:00
|
|
|
#include <generated/utsrelease.h>
|
2008-11-14 01:18:59 +00:00
|
|
|
|
2008-11-22 10:29:33 +00:00
|
|
|
#include <linux/io.h>
|
2010-05-08 13:56:24 +00:00
|
|
|
#include <linux/uaccess.h>
|
2008-11-14 01:18:59 +00:00
|
|
|
|
|
|
|
#define LCD_MINOR 156
|
|
|
|
#define KEYPAD_MINOR 185
|
|
|
|
|
|
|
|
#define LCD_MAXBYTES 256 /* max burst write */
|
|
|
|
|
|
|
|
#define KEYPAD_BUFFER 64
|
|
|
|
|
2010-06-11 21:27:36 +00:00
|
|
|
/* poll the keyboard this every second */
|
2015-10-27 09:24:51 +00:00
|
|
|
#define INPUT_POLL_TIME (HZ / 50)
|
2010-06-11 21:27:36 +00:00
|
|
|
/* a key starts to repeat after this times INPUT_POLL_TIME */
|
|
|
|
#define KEYPAD_REP_START (10)
|
|
|
|
/* a key repeats this times INPUT_POLL_TIME */
|
|
|
|
#define KEYPAD_REP_DELAY (2)
|
|
|
|
|
2017-02-06 14:38:10 +00:00
|
|
|
/* keep the light on this many seconds for each flash */
|
|
|
|
#define FLASH_LIGHT_TEMPO (4)
|
2008-11-14 01:18:59 +00:00
|
|
|
|
|
|
|
/* converts an r_str() input to an active high, bits string : 000BAOSE */
|
|
|
|
#define PNL_PINPUT(a) ((((unsigned char)(a)) ^ 0x7F) >> 3)
|
|
|
|
|
2008-11-22 10:29:33 +00:00
|
|
|
#define PNL_PBUSY 0x80 /* inverted input, active low */
|
|
|
|
#define PNL_PACK 0x40 /* direct input, active low */
|
|
|
|
#define PNL_POUTPA 0x20 /* direct input, active high */
|
|
|
|
#define PNL_PSELECD 0x10 /* direct input, active high */
|
|
|
|
#define PNL_PERRORP 0x08 /* direct input, active low */
|
2008-11-14 01:18:59 +00:00
|
|
|
|
2008-11-22 10:29:33 +00:00
|
|
|
#define PNL_PBIDIR 0x20 /* bi-directional ports */
|
2010-06-11 21:27:36 +00:00
|
|
|
/* high to read data in or-ed with data out */
|
|
|
|
#define PNL_PINTEN 0x10
|
2008-11-22 10:29:33 +00:00
|
|
|
#define PNL_PSELECP 0x08 /* inverted output, active low */
|
|
|
|
#define PNL_PINITP 0x04 /* direct output, active low */
|
|
|
|
#define PNL_PAUTOLF 0x02 /* inverted output, active low */
|
|
|
|
#define PNL_PSTROBE 0x01 /* inverted output */
|
2008-11-14 01:18:59 +00:00
|
|
|
|
|
|
|
#define PNL_PD0 0x01
|
|
|
|
#define PNL_PD1 0x02
|
|
|
|
#define PNL_PD2 0x04
|
|
|
|
#define PNL_PD3 0x08
|
|
|
|
#define PNL_PD4 0x10
|
|
|
|
#define PNL_PD5 0x20
|
|
|
|
#define PNL_PD6 0x40
|
|
|
|
#define PNL_PD7 0x80
|
|
|
|
|
|
|
|
#define PIN_NONE 0
|
|
|
|
#define PIN_STROBE 1
|
|
|
|
#define PIN_D0 2
|
|
|
|
#define PIN_D1 3
|
|
|
|
#define PIN_D2 4
|
|
|
|
#define PIN_D3 5
|
|
|
|
#define PIN_D4 6
|
|
|
|
#define PIN_D5 7
|
|
|
|
#define PIN_D6 8
|
|
|
|
#define PIN_D7 9
|
|
|
|
#define PIN_AUTOLF 14
|
|
|
|
#define PIN_INITP 16
|
|
|
|
#define PIN_SELECP 17
|
|
|
|
#define PIN_NOT_SET 127
|
|
|
|
|
|
|
|
#define LCD_FLAG_B 0x0004 /* blink on */
|
|
|
|
#define LCD_FLAG_C 0x0008 /* cursor on */
|
|
|
|
#define LCD_FLAG_D 0x0010 /* display on */
|
|
|
|
#define LCD_FLAG_F 0x0020 /* large font mode */
|
|
|
|
#define LCD_FLAG_N 0x0040 /* 2-rows mode */
|
|
|
|
#define LCD_FLAG_L 0x0080 /* backlight enabled */
|
|
|
|
|
2014-12-05 21:28:19 +00:00
|
|
|
/* LCD commands */
|
|
|
|
#define LCD_CMD_DISPLAY_CLEAR 0x01 /* Clear entire display */
|
|
|
|
|
|
|
|
#define LCD_CMD_ENTRY_MODE 0x04 /* Set entry mode */
|
|
|
|
#define LCD_CMD_CURSOR_INC 0x02 /* Increment cursor */
|
|
|
|
|
|
|
|
#define LCD_CMD_DISPLAY_CTRL 0x08 /* Display control */
|
|
|
|
#define LCD_CMD_DISPLAY_ON 0x04 /* Set display on */
|
|
|
|
#define LCD_CMD_CURSOR_ON 0x02 /* Set cursor on */
|
|
|
|
#define LCD_CMD_BLINK_ON 0x01 /* Set blink on */
|
|
|
|
|
|
|
|
#define LCD_CMD_SHIFT 0x10 /* Shift cursor/display */
|
|
|
|
#define LCD_CMD_DISPLAY_SHIFT 0x08 /* Shift display instead of cursor */
|
|
|
|
#define LCD_CMD_SHIFT_RIGHT 0x04 /* Shift display/cursor to the right */
|
|
|
|
|
|
|
|
#define LCD_CMD_FUNCTION_SET 0x20 /* Set function */
|
|
|
|
#define LCD_CMD_DATA_LEN_8BITS 0x10 /* Set data length to 8 bits */
|
|
|
|
#define LCD_CMD_TWO_LINES 0x08 /* Set to two display lines */
|
|
|
|
#define LCD_CMD_FONT_5X10_DOTS 0x04 /* Set char font to 5x10 dots */
|
|
|
|
|
|
|
|
#define LCD_CMD_SET_CGRAM_ADDR 0x40 /* Set char generator RAM address */
|
|
|
|
|
|
|
|
#define LCD_CMD_SET_DDRAM_ADDR 0x80 /* Set display data RAM address */
|
|
|
|
|
2010-06-11 21:27:36 +00:00
|
|
|
#define LCD_ESCAPE_LEN 24 /* max chars for LCD escape command */
|
2008-11-14 01:18:59 +00:00
|
|
|
#define LCD_ESCAPE_CHAR 27 /* use char 27 for escape command */
|
|
|
|
|
2014-11-27 21:36:47 +00:00
|
|
|
#define NOT_SET -1
|
|
|
|
|
2008-11-14 01:18:59 +00:00
|
|
|
/* macros to simplify use of the parallel port */
|
|
|
|
#define r_ctr(x) (parport_read_control((x)->port))
|
|
|
|
#define r_dtr(x) (parport_read_data((x)->port))
|
|
|
|
#define r_str(x) (parport_read_status((x)->port))
|
2012-07-25 03:18:12 +00:00
|
|
|
#define w_ctr(x, y) (parport_write_control((x)->port, (y)))
|
|
|
|
#define w_dtr(x, y) (parport_write_data((x)->port, (y)))
|
2008-11-14 01:18:59 +00:00
|
|
|
|
|
|
|
/* this defines which bits are to be used and which ones to be ignored */
|
2010-06-11 21:27:36 +00:00
|
|
|
/* logical or of the output bits involved in the scan matrix */
|
|
|
|
static __u8 scan_mask_o;
|
|
|
|
/* logical or of the input bits involved in the scan matrix */
|
|
|
|
static __u8 scan_mask_i;
|
2008-11-14 01:18:59 +00:00
|
|
|
|
|
|
|
enum input_type {
|
2008-11-22 10:29:33 +00:00
|
|
|
INPUT_TYPE_STD,
|
|
|
|
INPUT_TYPE_KBD,
|
2008-11-14 01:18:59 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
enum input_state {
|
2008-11-22 10:29:33 +00:00
|
|
|
INPUT_ST_LOW,
|
|
|
|
INPUT_ST_RISING,
|
|
|
|
INPUT_ST_HIGH,
|
|
|
|
INPUT_ST_FALLING,
|
2008-11-14 01:18:59 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct logical_input {
|
2008-11-22 10:29:33 +00:00
|
|
|
struct list_head list;
|
2016-01-03 19:40:58 +00:00
|
|
|
__u64 mask;
|
|
|
|
__u64 value;
|
2008-11-22 10:29:33 +00:00
|
|
|
enum input_type type;
|
|
|
|
enum input_state state;
|
|
|
|
__u8 rise_time, fall_time;
|
|
|
|
__u8 rise_timer, fall_timer, high_timer;
|
|
|
|
|
|
|
|
union {
|
2010-06-11 21:27:36 +00:00
|
|
|
struct { /* valid when type == INPUT_TYPE_STD */
|
2014-02-25 14:10:49 +00:00
|
|
|
void (*press_fct)(int);
|
|
|
|
void (*release_fct)(int);
|
2008-11-22 10:29:33 +00:00
|
|
|
int press_data;
|
|
|
|
int release_data;
|
|
|
|
} std;
|
2010-06-11 21:27:36 +00:00
|
|
|
struct { /* valid when type == INPUT_TYPE_KBD */
|
|
|
|
/* strings can be non null-terminated */
|
2008-11-22 10:29:33 +00:00
|
|
|
char press_str[sizeof(void *) + sizeof(int)];
|
|
|
|
char repeat_str[sizeof(void *) + sizeof(int)];
|
|
|
|
char release_str[sizeof(void *) + sizeof(int)];
|
|
|
|
} kbd;
|
|
|
|
} u;
|
2008-11-14 01:18:59 +00:00
|
|
|
};
|
|
|
|
|
2013-02-15 12:47:05 +00:00
|
|
|
static LIST_HEAD(logical_inputs); /* list of all defined logical inputs */
|
2008-11-14 01:18:59 +00:00
|
|
|
|
|
|
|
/* physical contacts history
|
|
|
|
* Physical contacts are a 45 bits string of 9 groups of 5 bits each.
|
|
|
|
* The 8 lower groups correspond to output bits 0 to 7, and the 9th group
|
|
|
|
* corresponds to the ground.
|
|
|
|
* Within each group, bits are stored in the same order as read on the port :
|
|
|
|
* BAPSE (busy=4, ack=3, paper empty=2, select=1, error=0).
|
2016-01-03 19:40:58 +00:00
|
|
|
* So, each __u64 is represented like this :
|
2008-11-14 01:18:59 +00:00
|
|
|
* 0000000000000000000BAPSEBAPSEBAPSEBAPSEBAPSEBAPSEBAPSEBAPSEBAPSE
|
|
|
|
* <-----unused------><gnd><d07><d06><d05><d04><d03><d02><d01><d00>
|
|
|
|
*/
|
2010-06-11 21:27:36 +00:00
|
|
|
|
|
|
|
/* what has just been read from the I/O ports */
|
2016-01-03 19:40:58 +00:00
|
|
|
static __u64 phys_read;
|
2010-06-11 21:27:36 +00:00
|
|
|
/* previous phys_read */
|
2016-01-03 19:40:58 +00:00
|
|
|
static __u64 phys_read_prev;
|
2010-06-11 21:27:36 +00:00
|
|
|
/* stabilized phys_read (phys_read|phys_read_prev) */
|
2016-01-03 19:40:58 +00:00
|
|
|
static __u64 phys_curr;
|
2010-06-11 21:27:36 +00:00
|
|
|
/* previous phys_curr */
|
2016-01-03 19:40:58 +00:00
|
|
|
static __u64 phys_prev;
|
2010-06-11 21:27:36 +00:00
|
|
|
/* 0 means that at least one logical signal needs be computed */
|
|
|
|
static char inputs_stable;
|
2008-11-14 01:18:59 +00:00
|
|
|
|
|
|
|
/* these variables are specific to the keypad */
|
2014-11-27 21:36:49 +00:00
|
|
|
static struct {
|
|
|
|
bool enabled;
|
|
|
|
} keypad;
|
|
|
|
|
2008-11-14 01:18:59 +00:00
|
|
|
static char keypad_buffer[KEYPAD_BUFFER];
|
2008-11-22 10:29:33 +00:00
|
|
|
static int keypad_buflen;
|
|
|
|
static int keypad_start;
|
|
|
|
static char keypressed;
|
2008-11-14 01:18:59 +00:00
|
|
|
static wait_queue_head_t keypad_read_wait;
|
|
|
|
|
|
|
|
/* lcd-specific variables */
|
2014-11-27 21:36:49 +00:00
|
|
|
static struct {
|
|
|
|
bool enabled;
|
2014-11-27 21:36:53 +00:00
|
|
|
bool initialized;
|
|
|
|
bool must_clear;
|
|
|
|
|
2014-11-27 21:36:51 +00:00
|
|
|
int height;
|
|
|
|
int width;
|
|
|
|
int bwidth;
|
|
|
|
int hwidth;
|
|
|
|
int charset;
|
|
|
|
int proto;
|
2017-02-06 14:38:10 +00:00
|
|
|
|
|
|
|
struct delayed_work bl_work;
|
|
|
|
struct mutex bl_tempo_lock; /* Protects access to bl_tempo */
|
|
|
|
bool bl_tempo;
|
2014-11-27 21:36:53 +00:00
|
|
|
|
2014-11-27 21:36:51 +00:00
|
|
|
/* TODO: use union here? */
|
|
|
|
struct {
|
|
|
|
int e;
|
|
|
|
int rs;
|
|
|
|
int rw;
|
|
|
|
int cl;
|
|
|
|
int da;
|
|
|
|
int bl;
|
|
|
|
} pins;
|
2014-11-27 21:36:53 +00:00
|
|
|
|
|
|
|
/* contains the LCD config state */
|
|
|
|
unsigned long int flags;
|
|
|
|
|
|
|
|
/* Contains the LCD X and Y offset */
|
|
|
|
struct {
|
|
|
|
unsigned long int x;
|
|
|
|
unsigned long int y;
|
|
|
|
} addr;
|
|
|
|
|
|
|
|
/* Current escape sequence and it's length or -1 if outside */
|
|
|
|
struct {
|
|
|
|
char buf[LCD_ESCAPE_LEN + 1];
|
|
|
|
int len;
|
|
|
|
} esc_seq;
|
2014-11-27 21:36:49 +00:00
|
|
|
} lcd;
|
2010-06-11 21:27:36 +00:00
|
|
|
|
2014-11-27 21:36:50 +00:00
|
|
|
/* Needed only for init */
|
|
|
|
static int selected_lcd_type = NOT_SET;
|
|
|
|
|
2008-11-14 01:18:59 +00:00
|
|
|
/*
|
|
|
|
* Bit masks to convert LCD signals to parallel port outputs.
|
|
|
|
* _d_ are values for data port, _c_ are for control port.
|
|
|
|
* [0] = signal OFF, [1] = signal ON, [2] = mask
|
|
|
|
*/
|
2008-11-22 10:29:33 +00:00
|
|
|
#define BIT_CLR 0
|
|
|
|
#define BIT_SET 1
|
|
|
|
#define BIT_MSK 2
|
2008-11-14 01:18:59 +00:00
|
|
|
#define BIT_STATES 3
|
|
|
|
/*
|
|
|
|
* one entry for each bit on the LCD
|
|
|
|
*/
|
|
|
|
#define LCD_BIT_E 0
|
|
|
|
#define LCD_BIT_RS 1
|
|
|
|
#define LCD_BIT_RW 2
|
|
|
|
#define LCD_BIT_BL 3
|
|
|
|
#define LCD_BIT_CL 4
|
|
|
|
#define LCD_BIT_DA 5
|
|
|
|
#define LCD_BITS 6
|
|
|
|
|
|
|
|
/*
|
|
|
|
* each bit can be either connected to a DATA or CTRL port
|
|
|
|
*/
|
|
|
|
#define LCD_PORT_C 0
|
|
|
|
#define LCD_PORT_D 1
|
|
|
|
#define LCD_PORTS 2
|
|
|
|
|
|
|
|
static unsigned char lcd_bits[LCD_PORTS][LCD_BITS][BIT_STATES];
|
|
|
|
|
|
|
|
/*
|
|
|
|
* LCD protocols
|
|
|
|
*/
|
|
|
|
#define LCD_PROTO_PARALLEL 0
|
|
|
|
#define LCD_PROTO_SERIAL 1
|
2009-08-20 22:13:18 +00:00
|
|
|
#define LCD_PROTO_TI_DA8XX_LCD 2
|
2008-11-14 01:18:59 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* LCD character sets
|
|
|
|
*/
|
|
|
|
#define LCD_CHARSET_NORMAL 0
|
|
|
|
#define LCD_CHARSET_KS0074 1
|
|
|
|
|
|
|
|
/*
|
|
|
|
* LCD types
|
|
|
|
*/
|
|
|
|
#define LCD_TYPE_NONE 0
|
2015-03-24 10:59:32 +00:00
|
|
|
#define LCD_TYPE_CUSTOM 1
|
|
|
|
#define LCD_TYPE_OLD 2
|
|
|
|
#define LCD_TYPE_KS0074 3
|
|
|
|
#define LCD_TYPE_HANTRONIX 4
|
|
|
|
#define LCD_TYPE_NEXCOM 5
|
2008-11-14 01:18:59 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* keypad types
|
|
|
|
*/
|
|
|
|
#define KEYPAD_TYPE_NONE 0
|
|
|
|
#define KEYPAD_TYPE_OLD 1
|
|
|
|
#define KEYPAD_TYPE_NEW 2
|
|
|
|
#define KEYPAD_TYPE_NEXCOM 3
|
|
|
|
|
|
|
|
/*
|
|
|
|
* panel profiles
|
|
|
|
*/
|
|
|
|
#define PANEL_PROFILE_CUSTOM 0
|
|
|
|
#define PANEL_PROFILE_OLD 1
|
|
|
|
#define PANEL_PROFILE_NEW 2
|
|
|
|
#define PANEL_PROFILE_HANTRONIX 3
|
|
|
|
#define PANEL_PROFILE_NEXCOM 4
|
|
|
|
#define PANEL_PROFILE_LARGE 5
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Construct custom config from the kernel's configuration
|
|
|
|
*/
|
|
|
|
#define DEFAULT_PARPORT 0
|
2014-11-12 01:08:06 +00:00
|
|
|
#define DEFAULT_PROFILE PANEL_PROFILE_LARGE
|
2014-11-12 01:08:09 +00:00
|
|
|
#define DEFAULT_KEYPAD_TYPE KEYPAD_TYPE_OLD
|
|
|
|
#define DEFAULT_LCD_TYPE LCD_TYPE_OLD
|
2014-11-12 01:08:06 +00:00
|
|
|
#define DEFAULT_LCD_HEIGHT 2
|
2008-11-14 01:18:59 +00:00
|
|
|
#define DEFAULT_LCD_WIDTH 40
|
|
|
|
#define DEFAULT_LCD_BWIDTH 40
|
|
|
|
#define DEFAULT_LCD_HWIDTH 64
|
2014-11-12 01:08:06 +00:00
|
|
|
#define DEFAULT_LCD_CHARSET LCD_CHARSET_NORMAL
|
2008-11-14 01:18:59 +00:00
|
|
|
#define DEFAULT_LCD_PROTO LCD_PROTO_PARALLEL
|
|
|
|
|
|
|
|
#define DEFAULT_LCD_PIN_E PIN_AUTOLF
|
|
|
|
#define DEFAULT_LCD_PIN_RS PIN_SELECP
|
|
|
|
#define DEFAULT_LCD_PIN_RW PIN_INITP
|
|
|
|
#define DEFAULT_LCD_PIN_SCL PIN_STROBE
|
|
|
|
#define DEFAULT_LCD_PIN_SDA PIN_D0
|
|
|
|
#define DEFAULT_LCD_PIN_BL PIN_NOT_SET
|
|
|
|
|
|
|
|
#ifdef CONFIG_PANEL_PARPORT
|
|
|
|
#undef DEFAULT_PARPORT
|
|
|
|
#define DEFAULT_PARPORT CONFIG_PANEL_PARPORT
|
|
|
|
#endif
|
|
|
|
|
2014-11-12 01:08:07 +00:00
|
|
|
#ifdef CONFIG_PANEL_PROFILE
|
|
|
|
#undef DEFAULT_PROFILE
|
|
|
|
#define DEFAULT_PROFILE CONFIG_PANEL_PROFILE
|
|
|
|
#endif
|
|
|
|
|
2008-11-22 10:29:33 +00:00
|
|
|
#if DEFAULT_PROFILE == 0 /* custom */
|
2008-11-14 01:18:59 +00:00
|
|
|
#ifdef CONFIG_PANEL_KEYPAD
|
2014-11-12 01:08:09 +00:00
|
|
|
#undef DEFAULT_KEYPAD_TYPE
|
|
|
|
#define DEFAULT_KEYPAD_TYPE CONFIG_PANEL_KEYPAD
|
2008-11-14 01:18:59 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef CONFIG_PANEL_LCD
|
2014-11-12 01:08:09 +00:00
|
|
|
#undef DEFAULT_LCD_TYPE
|
|
|
|
#define DEFAULT_LCD_TYPE CONFIG_PANEL_LCD
|
2008-11-14 01:18:59 +00:00
|
|
|
#endif
|
|
|
|
|
2014-11-12 01:08:07 +00:00
|
|
|
#ifdef CONFIG_PANEL_LCD_HEIGHT
|
|
|
|
#undef DEFAULT_LCD_HEIGHT
|
|
|
|
#define DEFAULT_LCD_HEIGHT CONFIG_PANEL_LCD_HEIGHT
|
|
|
|
#endif
|
|
|
|
|
2008-11-14 01:18:59 +00:00
|
|
|
#ifdef CONFIG_PANEL_LCD_WIDTH
|
|
|
|
#undef DEFAULT_LCD_WIDTH
|
|
|
|
#define DEFAULT_LCD_WIDTH CONFIG_PANEL_LCD_WIDTH
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef CONFIG_PANEL_LCD_BWIDTH
|
|
|
|
#undef DEFAULT_LCD_BWIDTH
|
|
|
|
#define DEFAULT_LCD_BWIDTH CONFIG_PANEL_LCD_BWIDTH
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef CONFIG_PANEL_LCD_HWIDTH
|
|
|
|
#undef DEFAULT_LCD_HWIDTH
|
|
|
|
#define DEFAULT_LCD_HWIDTH CONFIG_PANEL_LCD_HWIDTH
|
|
|
|
#endif
|
|
|
|
|
2014-11-12 01:08:07 +00:00
|
|
|
#ifdef CONFIG_PANEL_LCD_CHARSET
|
|
|
|
#undef DEFAULT_LCD_CHARSET
|
|
|
|
#define DEFAULT_LCD_CHARSET CONFIG_PANEL_LCD_CHARSET
|
2008-11-14 01:18:59 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef CONFIG_PANEL_LCD_PROTO
|
|
|
|
#undef DEFAULT_LCD_PROTO
|
|
|
|
#define DEFAULT_LCD_PROTO CONFIG_PANEL_LCD_PROTO
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef CONFIG_PANEL_LCD_PIN_E
|
|
|
|
#undef DEFAULT_LCD_PIN_E
|
|
|
|
#define DEFAULT_LCD_PIN_E CONFIG_PANEL_LCD_PIN_E
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef CONFIG_PANEL_LCD_PIN_RS
|
|
|
|
#undef DEFAULT_LCD_PIN_RS
|
|
|
|
#define DEFAULT_LCD_PIN_RS CONFIG_PANEL_LCD_PIN_RS
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef CONFIG_PANEL_LCD_PIN_RW
|
|
|
|
#undef DEFAULT_LCD_PIN_RW
|
|
|
|
#define DEFAULT_LCD_PIN_RW CONFIG_PANEL_LCD_PIN_RW
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef CONFIG_PANEL_LCD_PIN_SCL
|
|
|
|
#undef DEFAULT_LCD_PIN_SCL
|
|
|
|
#define DEFAULT_LCD_PIN_SCL CONFIG_PANEL_LCD_PIN_SCL
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef CONFIG_PANEL_LCD_PIN_SDA
|
|
|
|
#undef DEFAULT_LCD_PIN_SDA
|
|
|
|
#define DEFAULT_LCD_PIN_SDA CONFIG_PANEL_LCD_PIN_SDA
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef CONFIG_PANEL_LCD_PIN_BL
|
|
|
|
#undef DEFAULT_LCD_PIN_BL
|
|
|
|
#define DEFAULT_LCD_PIN_BL CONFIG_PANEL_LCD_PIN_BL
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif /* DEFAULT_PROFILE == 0 */
|
|
|
|
|
|
|
|
/* global variables */
|
2014-11-04 21:47:19 +00:00
|
|
|
|
|
|
|
/* Device single-open policy control */
|
|
|
|
static atomic_t lcd_available = ATOMIC_INIT(1);
|
|
|
|
static atomic_t keypad_available = ATOMIC_INIT(1);
|
|
|
|
|
2008-11-22 10:29:33 +00:00
|
|
|
static struct pardevice *pprt;
|
2008-11-14 01:18:59 +00:00
|
|
|
|
2008-11-22 11:04:19 +00:00
|
|
|
static int keypad_initialized;
|
2008-11-14 01:18:59 +00:00
|
|
|
|
2014-02-25 14:10:49 +00:00
|
|
|
static void (*lcd_write_cmd)(int);
|
|
|
|
static void (*lcd_write_data)(int);
|
|
|
|
static void (*lcd_clear_fast)(void);
|
2008-11-14 01:18:59 +00:00
|
|
|
|
2008-11-22 10:29:33 +00:00
|
|
|
static DEFINE_SPINLOCK(pprt_lock);
|
2008-11-14 01:18:59 +00:00
|
|
|
static struct timer_list scan_timer;
|
|
|
|
|
2008-11-22 11:52:18 +00:00
|
|
|
MODULE_DESCRIPTION("Generic parallel port LCD/Keypad driver");
|
2008-11-22 11:04:19 +00:00
|
|
|
|
2014-11-27 21:36:45 +00:00
|
|
|
static int parport = DEFAULT_PARPORT;
|
2008-11-22 10:29:33 +00:00
|
|
|
module_param(parport, int, 0000);
|
|
|
|
MODULE_PARM_DESC(parport, "Parallel port index (0=lpt1, 1=lpt2, ...)");
|
2008-11-22 11:04:19 +00:00
|
|
|
|
2014-11-12 01:08:08 +00:00
|
|
|
static int profile = DEFAULT_PROFILE;
|
|
|
|
module_param(profile, int, 0000);
|
|
|
|
MODULE_PARM_DESC(profile,
|
|
|
|
"1=16x2 old kp; 2=serial 16x2, new kp; 3=16x2 hantronix; "
|
|
|
|
"4=16x2 nexcom; default=40x2, old kp");
|
|
|
|
|
2014-11-27 21:36:47 +00:00
|
|
|
static int keypad_type = NOT_SET;
|
2014-11-12 01:08:08 +00:00
|
|
|
module_param(keypad_type, int, 0000);
|
|
|
|
MODULE_PARM_DESC(keypad_type,
|
|
|
|
"Keypad type: 0=none, 1=old 6 keys, 2=new 6+1 keys, 3=nexcom 4 keys");
|
|
|
|
|
2014-11-27 21:36:47 +00:00
|
|
|
static int lcd_type = NOT_SET;
|
2014-11-12 01:08:08 +00:00
|
|
|
module_param(lcd_type, int, 0000);
|
|
|
|
MODULE_PARM_DESC(lcd_type,
|
2015-03-24 10:59:32 +00:00
|
|
|
"LCD type: 0=none, 1=compiled-in, 2=old, 3=serial ks0074, 4=hantronix, 5=nexcom");
|
2014-11-12 01:08:08 +00:00
|
|
|
|
2014-11-27 21:36:47 +00:00
|
|
|
static int lcd_height = NOT_SET;
|
2008-11-22 10:29:33 +00:00
|
|
|
module_param(lcd_height, int, 0000);
|
|
|
|
MODULE_PARM_DESC(lcd_height, "Number of lines on the LCD");
|
2008-11-22 11:04:19 +00:00
|
|
|
|
2014-11-27 21:36:47 +00:00
|
|
|
static int lcd_width = NOT_SET;
|
2008-11-22 10:29:33 +00:00
|
|
|
module_param(lcd_width, int, 0000);
|
|
|
|
MODULE_PARM_DESC(lcd_width, "Number of columns on the LCD");
|
2008-11-22 11:04:19 +00:00
|
|
|
|
2014-11-27 21:36:47 +00:00
|
|
|
static int lcd_bwidth = NOT_SET; /* internal buffer width (usually 40) */
|
2008-11-22 10:29:33 +00:00
|
|
|
module_param(lcd_bwidth, int, 0000);
|
|
|
|
MODULE_PARM_DESC(lcd_bwidth, "Internal LCD line width (40)");
|
2008-11-22 11:04:19 +00:00
|
|
|
|
2014-11-27 21:36:47 +00:00
|
|
|
static int lcd_hwidth = NOT_SET; /* hardware buffer width (usually 64) */
|
2008-11-22 10:29:33 +00:00
|
|
|
module_param(lcd_hwidth, int, 0000);
|
|
|
|
MODULE_PARM_DESC(lcd_hwidth, "LCD line hardware address (64)");
|
2008-11-22 11:04:19 +00:00
|
|
|
|
2014-11-27 21:36:47 +00:00
|
|
|
static int lcd_charset = NOT_SET;
|
2014-11-12 01:08:08 +00:00
|
|
|
module_param(lcd_charset, int, 0000);
|
|
|
|
MODULE_PARM_DESC(lcd_charset, "LCD character set: 0=standard, 1=KS0074");
|
2008-11-22 11:04:19 +00:00
|
|
|
|
2014-11-27 21:36:47 +00:00
|
|
|
static int lcd_proto = NOT_SET;
|
2008-11-22 10:29:33 +00:00
|
|
|
module_param(lcd_proto, int, 0000);
|
2010-06-11 21:27:36 +00:00
|
|
|
MODULE_PARM_DESC(lcd_proto,
|
2014-05-21 12:10:00 +00:00
|
|
|
"LCD communication: 0=parallel (//), 1=serial, 2=TI LCD Interface");
|
2008-11-22 11:04:19 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* These are the parallel port pins the LCD control signals are connected to.
|
|
|
|
* Set this to 0 if the signal is not used. Set it to its opposite value
|
|
|
|
* (negative) if the signal is negated. -MAXINT is used to indicate that the
|
|
|
|
* pin has not been explicitly specified.
|
|
|
|
*
|
2008-11-22 11:52:18 +00:00
|
|
|
* WARNING! no check will be performed about collisions with keypad !
|
2008-11-22 11:04:19 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
static int lcd_e_pin = PIN_NOT_SET;
|
2008-11-22 10:29:33 +00:00
|
|
|
module_param(lcd_e_pin, int, 0000);
|
|
|
|
MODULE_PARM_DESC(lcd_e_pin,
|
2014-02-25 14:12:46 +00:00
|
|
|
"# of the // port pin connected to LCD 'E' signal, with polarity (-17..17)");
|
2008-11-22 11:04:19 +00:00
|
|
|
|
|
|
|
static int lcd_rs_pin = PIN_NOT_SET;
|
2008-11-22 10:29:33 +00:00
|
|
|
module_param(lcd_rs_pin, int, 0000);
|
|
|
|
MODULE_PARM_DESC(lcd_rs_pin,
|
2014-02-25 14:12:46 +00:00
|
|
|
"# of the // port pin connected to LCD 'RS' signal, with polarity (-17..17)");
|
2008-11-22 11:04:19 +00:00
|
|
|
|
|
|
|
static int lcd_rw_pin = PIN_NOT_SET;
|
2008-11-22 10:29:33 +00:00
|
|
|
module_param(lcd_rw_pin, int, 0000);
|
|
|
|
MODULE_PARM_DESC(lcd_rw_pin,
|
2014-02-25 14:12:46 +00:00
|
|
|
"# of the // port pin connected to LCD 'RW' signal, with polarity (-17..17)");
|
2008-11-22 11:04:19 +00:00
|
|
|
|
2014-11-12 01:08:08 +00:00
|
|
|
static int lcd_cl_pin = PIN_NOT_SET;
|
|
|
|
module_param(lcd_cl_pin, int, 0000);
|
|
|
|
MODULE_PARM_DESC(lcd_cl_pin,
|
|
|
|
"# of the // port pin connected to serial LCD 'SCL' signal, with polarity (-17..17)");
|
2008-11-22 11:04:19 +00:00
|
|
|
|
|
|
|
static int lcd_da_pin = PIN_NOT_SET;
|
2008-11-22 10:29:33 +00:00
|
|
|
module_param(lcd_da_pin, int, 0000);
|
|
|
|
MODULE_PARM_DESC(lcd_da_pin,
|
2014-02-25 14:12:46 +00:00
|
|
|
"# of the // port pin connected to serial LCD 'SDA' signal, with polarity (-17..17)");
|
2008-11-22 11:04:19 +00:00
|
|
|
|
2014-11-12 01:08:08 +00:00
|
|
|
static int lcd_bl_pin = PIN_NOT_SET;
|
|
|
|
module_param(lcd_bl_pin, int, 0000);
|
|
|
|
MODULE_PARM_DESC(lcd_bl_pin,
|
|
|
|
"# of the // port pin connected to LCD backlight, with polarity (-17..17)");
|
|
|
|
|
|
|
|
/* Deprecated module parameters - consider not using them anymore */
|
|
|
|
|
2014-11-27 21:36:47 +00:00
|
|
|
static int lcd_enabled = NOT_SET;
|
2014-11-12 01:08:08 +00:00
|
|
|
module_param(lcd_enabled, int, 0000);
|
|
|
|
MODULE_PARM_DESC(lcd_enabled, "Deprecated option, use lcd_type instead");
|
|
|
|
|
2014-11-27 21:36:47 +00:00
|
|
|
static int keypad_enabled = NOT_SET;
|
2014-11-12 01:08:08 +00:00
|
|
|
module_param(keypad_enabled, int, 0000);
|
|
|
|
MODULE_PARM_DESC(keypad_enabled, "Deprecated option, use keypad_type instead");
|
|
|
|
|
2013-02-15 12:47:05 +00:00
|
|
|
static const unsigned char *lcd_char_conv;
|
2008-11-14 01:18:59 +00:00
|
|
|
|
|
|
|
/* for some LCD drivers (ks0074) we need a charset conversion table. */
|
2013-02-15 12:47:05 +00:00
|
|
|
static const unsigned char lcd_char_conv_ks0074[256] = {
|
2008-11-22 10:29:33 +00:00
|
|
|
/* 0|8 1|9 2|A 3|B 4|C 5|D 6|E 7|F */
|
|
|
|
/* 0x00 */ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
|
|
|
|
/* 0x08 */ 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
|
|
|
|
/* 0x10 */ 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
|
|
|
|
/* 0x18 */ 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
|
|
|
|
/* 0x20 */ 0x20, 0x21, 0x22, 0x23, 0xa2, 0x25, 0x26, 0x27,
|
|
|
|
/* 0x28 */ 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
|
|
|
|
/* 0x30 */ 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
|
|
|
|
/* 0x38 */ 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f,
|
|
|
|
/* 0x40 */ 0xa0, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47,
|
|
|
|
/* 0x48 */ 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f,
|
|
|
|
/* 0x50 */ 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
|
|
|
|
/* 0x58 */ 0x58, 0x59, 0x5a, 0xfa, 0xfb, 0xfc, 0x1d, 0xc4,
|
|
|
|
/* 0x60 */ 0x96, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67,
|
|
|
|
/* 0x68 */ 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f,
|
|
|
|
/* 0x70 */ 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77,
|
|
|
|
/* 0x78 */ 0x78, 0x79, 0x7a, 0xfd, 0xfe, 0xff, 0xce, 0x20,
|
|
|
|
/* 0x80 */ 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
|
|
|
|
/* 0x88 */ 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,
|
|
|
|
/* 0x90 */ 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97,
|
|
|
|
/* 0x98 */ 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f,
|
|
|
|
/* 0xA0 */ 0x20, 0x40, 0xb1, 0xa1, 0x24, 0xa3, 0xfe, 0x5f,
|
|
|
|
/* 0xA8 */ 0x22, 0xc8, 0x61, 0x14, 0x97, 0x2d, 0xad, 0x96,
|
|
|
|
/* 0xB0 */ 0x80, 0x8c, 0x82, 0x83, 0x27, 0x8f, 0x86, 0xdd,
|
|
|
|
/* 0xB8 */ 0x2c, 0x81, 0x6f, 0x15, 0x8b, 0x8a, 0x84, 0x60,
|
|
|
|
/* 0xC0 */ 0xe2, 0xe2, 0xe2, 0x5b, 0x5b, 0xae, 0xbc, 0xa9,
|
|
|
|
/* 0xC8 */ 0xc5, 0xbf, 0xc6, 0xf1, 0xe3, 0xe3, 0xe3, 0xe3,
|
|
|
|
/* 0xD0 */ 0x44, 0x5d, 0xa8, 0xe4, 0xec, 0xec, 0x5c, 0x78,
|
|
|
|
/* 0xD8 */ 0xab, 0xa6, 0xe5, 0x5e, 0x5e, 0xe6, 0xaa, 0xbe,
|
|
|
|
/* 0xE0 */ 0x7f, 0xe7, 0xaf, 0x7b, 0x7b, 0xaf, 0xbd, 0xc8,
|
|
|
|
/* 0xE8 */ 0xa4, 0xa5, 0xc7, 0xf6, 0xa7, 0xe8, 0x69, 0x69,
|
|
|
|
/* 0xF0 */ 0xed, 0x7d, 0xa8, 0xe4, 0xec, 0x5c, 0x5c, 0x25,
|
|
|
|
/* 0xF8 */ 0xac, 0xa6, 0xea, 0xef, 0x7e, 0xeb, 0xb2, 0x79,
|
2008-11-14 01:18:59 +00:00
|
|
|
};
|
|
|
|
|
2013-02-15 12:47:05 +00:00
|
|
|
static const char old_keypad_profile[][4][9] = {
|
2008-11-22 10:29:33 +00:00
|
|
|
{"S0", "Left\n", "Left\n", ""},
|
|
|
|
{"S1", "Down\n", "Down\n", ""},
|
|
|
|
{"S2", "Up\n", "Up\n", ""},
|
|
|
|
{"S3", "Right\n", "Right\n", ""},
|
|
|
|
{"S4", "Esc\n", "Esc\n", ""},
|
|
|
|
{"S5", "Ret\n", "Ret\n", ""},
|
|
|
|
{"", "", "", ""}
|
2008-11-14 01:18:59 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* signals, press, repeat, release */
|
2013-02-15 12:47:05 +00:00
|
|
|
static const char new_keypad_profile[][4][9] = {
|
2008-11-22 10:29:33 +00:00
|
|
|
{"S0", "Left\n", "Left\n", ""},
|
|
|
|
{"S1", "Down\n", "Down\n", ""},
|
|
|
|
{"S2", "Up\n", "Up\n", ""},
|
|
|
|
{"S3", "Right\n", "Right\n", ""},
|
|
|
|
{"S4s5", "", "Esc\n", "Esc\n"},
|
|
|
|
{"s4S5", "", "Ret\n", "Ret\n"},
|
|
|
|
{"S4S5", "Help\n", "", ""},
|
|
|
|
/* add new signals above this line */
|
|
|
|
{"", "", "", ""}
|
2008-11-14 01:18:59 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* signals, press, repeat, release */
|
2013-02-15 12:47:05 +00:00
|
|
|
static const char nexcom_keypad_profile[][4][9] = {
|
2008-11-22 10:29:33 +00:00
|
|
|
{"a-p-e-", "Down\n", "Down\n", ""},
|
|
|
|
{"a-p-E-", "Ret\n", "Ret\n", ""},
|
|
|
|
{"a-P-E-", "Esc\n", "Esc\n", ""},
|
|
|
|
{"a-P-e-", "Up\n", "Up\n", ""},
|
|
|
|
/* add new signals above this line */
|
|
|
|
{"", "", "", ""}
|
2008-11-14 01:18:59 +00:00
|
|
|
};
|
|
|
|
|
2013-02-15 12:47:05 +00:00
|
|
|
static const char (*keypad_profile)[4][9] = old_keypad_profile;
|
2008-11-14 01:18:59 +00:00
|
|
|
|
2016-02-11 12:29:23 +00:00
|
|
|
static DECLARE_BITMAP(bits, LCD_BITS);
|
|
|
|
|
|
|
|
static void lcd_get_bits(unsigned int port, int *val)
|
|
|
|
{
|
|
|
|
unsigned int bit, state;
|
|
|
|
|
|
|
|
for (bit = 0; bit < LCD_BITS; bit++) {
|
|
|
|
state = test_bit(bit, bits) ? BIT_SET : BIT_CLR;
|
|
|
|
*val &= lcd_bits[port][bit][BIT_MSK];
|
|
|
|
*val |= lcd_bits[port][bit][state];
|
|
|
|
}
|
|
|
|
}
|
2008-11-14 01:18:59 +00:00
|
|
|
|
|
|
|
/* sets data port bits according to current signals values */
|
2008-11-22 10:29:33 +00:00
|
|
|
static int set_data_bits(void)
|
|
|
|
{
|
2016-02-11 12:29:23 +00:00
|
|
|
int val;
|
2008-11-22 10:29:33 +00:00
|
|
|
|
|
|
|
val = r_dtr(pprt);
|
2016-02-11 12:29:23 +00:00
|
|
|
lcd_get_bits(LCD_PORT_D, &val);
|
2008-11-22 10:29:33 +00:00
|
|
|
w_dtr(pprt, val);
|
|
|
|
return val;
|
2008-11-14 01:18:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* sets ctrl port bits according to current signals values */
|
2008-11-22 10:29:33 +00:00
|
|
|
static int set_ctrl_bits(void)
|
|
|
|
{
|
2016-02-11 12:29:23 +00:00
|
|
|
int val;
|
2008-11-22 10:29:33 +00:00
|
|
|
|
|
|
|
val = r_ctr(pprt);
|
2016-02-11 12:29:23 +00:00
|
|
|
lcd_get_bits(LCD_PORT_C, &val);
|
2008-11-22 10:29:33 +00:00
|
|
|
w_ctr(pprt, val);
|
|
|
|
return val;
|
2008-11-14 01:18:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* sets ctrl & data port bits according to current signals values */
|
2009-02-03 15:40:58 +00:00
|
|
|
static void panel_set_bits(void)
|
2008-11-22 10:29:33 +00:00
|
|
|
{
|
|
|
|
set_data_bits();
|
|
|
|
set_ctrl_bits();
|
2008-11-14 01:18:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Converts a parallel port pin (from -25 to 25) to data and control ports
|
|
|
|
* masks, and data and control port bits. The signal will be considered
|
|
|
|
* unconnected if it's on pin 0 or an invalid pin (<-25 or >25).
|
|
|
|
*
|
|
|
|
* Result will be used this way :
|
|
|
|
* out(dport, in(dport) & d_val[2] | d_val[signal_state])
|
|
|
|
* out(cport, in(cport) & c_val[2] | c_val[signal_state])
|
|
|
|
*/
|
2013-02-15 12:47:05 +00:00
|
|
|
static void pin_to_bits(int pin, unsigned char *d_val, unsigned char *c_val)
|
2008-11-22 10:29:33 +00:00
|
|
|
{
|
|
|
|
int d_bit, c_bit, inv;
|
|
|
|
|
2014-05-23 23:35:24 +00:00
|
|
|
d_val[0] = 0;
|
|
|
|
c_val[0] = 0;
|
|
|
|
d_val[1] = 0;
|
|
|
|
c_val[1] = 0;
|
|
|
|
d_val[2] = 0xFF;
|
|
|
|
c_val[2] = 0xFF;
|
2008-11-22 10:29:33 +00:00
|
|
|
|
|
|
|
if (pin == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
inv = (pin < 0);
|
|
|
|
if (inv)
|
|
|
|
pin = -pin;
|
|
|
|
|
2014-05-23 23:35:24 +00:00
|
|
|
d_bit = 0;
|
|
|
|
c_bit = 0;
|
2008-11-22 10:29:33 +00:00
|
|
|
|
|
|
|
switch (pin) {
|
|
|
|
case PIN_STROBE: /* strobe, inverted */
|
|
|
|
c_bit = PNL_PSTROBE;
|
|
|
|
inv = !inv;
|
|
|
|
break;
|
|
|
|
case PIN_D0...PIN_D7: /* D0 - D7 = 2 - 9 */
|
|
|
|
d_bit = 1 << (pin - 2);
|
|
|
|
break;
|
|
|
|
case PIN_AUTOLF: /* autofeed, inverted */
|
|
|
|
c_bit = PNL_PAUTOLF;
|
|
|
|
inv = !inv;
|
|
|
|
break;
|
2010-06-11 21:27:36 +00:00
|
|
|
case PIN_INITP: /* init, direct */
|
2008-11-22 10:29:33 +00:00
|
|
|
c_bit = PNL_PINITP;
|
|
|
|
break;
|
|
|
|
case PIN_SELECP: /* select_in, inverted */
|
|
|
|
c_bit = PNL_PSELECP;
|
|
|
|
inv = !inv;
|
|
|
|
break;
|
|
|
|
default: /* unknown pin, ignore */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (c_bit) {
|
|
|
|
c_val[2] &= ~c_bit;
|
|
|
|
c_val[!inv] = c_bit;
|
|
|
|
} else if (d_bit) {
|
|
|
|
d_val[2] &= ~d_bit;
|
|
|
|
d_val[!inv] = d_bit;
|
|
|
|
}
|
2008-11-14 01:18:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* sleeps that many milliseconds with a reschedule */
|
2008-11-22 10:29:33 +00:00
|
|
|
static void long_sleep(int ms)
|
|
|
|
{
|
2015-05-29 17:02:32 +00:00
|
|
|
if (in_interrupt())
|
2008-11-22 10:29:33 +00:00
|
|
|
mdelay(ms);
|
2015-05-29 17:02:32 +00:00
|
|
|
else
|
|
|
|
schedule_timeout_interruptible(msecs_to_jiffies(ms));
|
2008-11-22 10:29:33 +00:00
|
|
|
}
|
2008-11-14 01:18:59 +00:00
|
|
|
|
2015-07-31 17:08:29 +00:00
|
|
|
/*
|
|
|
|
* send a serial byte to the LCD panel. The caller is responsible for locking
|
|
|
|
* if needed.
|
|
|
|
*/
|
2008-11-22 10:29:33 +00:00
|
|
|
static void lcd_send_serial(int byte)
|
|
|
|
{
|
|
|
|
int bit;
|
|
|
|
|
2015-07-31 17:08:29 +00:00
|
|
|
/*
|
|
|
|
* the data bit is set on D0, and the clock on STROBE.
|
|
|
|
* LCD reads D0 on STROBE's rising edge.
|
|
|
|
*/
|
2008-11-22 10:29:33 +00:00
|
|
|
for (bit = 0; bit < 8; bit++) {
|
2016-02-11 12:29:23 +00:00
|
|
|
clear_bit(LCD_BIT_CL, bits); /* CLK low */
|
2009-02-03 15:40:58 +00:00
|
|
|
panel_set_bits();
|
2016-02-11 12:29:23 +00:00
|
|
|
if (byte & 1) {
|
|
|
|
set_bit(LCD_BIT_DA, bits);
|
|
|
|
} else {
|
|
|
|
clear_bit(LCD_BIT_DA, bits);
|
|
|
|
}
|
|
|
|
|
2009-02-03 15:40:58 +00:00
|
|
|
panel_set_bits();
|
2010-06-11 21:27:36 +00:00
|
|
|
udelay(2); /* maintain the data during 2 us before CLK up */
|
2016-02-11 12:29:23 +00:00
|
|
|
set_bit(LCD_BIT_CL, bits); /* CLK high */
|
2009-02-03 15:40:58 +00:00
|
|
|
panel_set_bits();
|
2010-06-11 21:27:36 +00:00
|
|
|
udelay(1); /* maintain the strobe during 1 us */
|
2008-11-22 10:29:33 +00:00
|
|
|
byte >>= 1;
|
|
|
|
}
|
2008-11-14 01:18:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* turn the backlight on or off */
|
2017-02-06 14:38:10 +00:00
|
|
|
static void __lcd_backlight(int on)
|
2008-11-22 10:29:33 +00:00
|
|
|
{
|
2012-03-19 15:17:52 +00:00
|
|
|
/* The backlight is activated by setting the AUTOFEED line to +5V */
|
2012-09-09 08:23:46 +00:00
|
|
|
spin_lock_irq(&pprt_lock);
|
2016-02-11 12:29:23 +00:00
|
|
|
if (on)
|
|
|
|
set_bit(LCD_BIT_BL, bits);
|
|
|
|
else
|
|
|
|
clear_bit(LCD_BIT_BL, bits);
|
2009-02-03 15:40:58 +00:00
|
|
|
panel_set_bits();
|
2012-09-09 08:23:46 +00:00
|
|
|
spin_unlock_irq(&pprt_lock);
|
2008-11-14 01:18:59 +00:00
|
|
|
}
|
|
|
|
|
2017-02-06 14:38:10 +00:00
|
|
|
static void lcd_backlight(int on)
|
|
|
|
{
|
|
|
|
if (lcd.pins.bl == PIN_NONE)
|
|
|
|
return;
|
|
|
|
|
|
|
|
mutex_lock(&lcd.bl_tempo_lock);
|
|
|
|
if (!lcd.bl_tempo)
|
|
|
|
__lcd_backlight(on);
|
|
|
|
mutex_unlock(&lcd.bl_tempo_lock);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void lcd_bl_off(struct work_struct *work)
|
|
|
|
{
|
|
|
|
mutex_lock(&lcd.bl_tempo_lock);
|
|
|
|
if (lcd.bl_tempo) {
|
|
|
|
lcd.bl_tempo = false;
|
|
|
|
if (!(lcd.flags & LCD_FLAG_L))
|
|
|
|
__lcd_backlight(0);
|
|
|
|
}
|
|
|
|
mutex_unlock(&lcd.bl_tempo_lock);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* turn the backlight on for a little while */
|
|
|
|
static void lcd_poke(void)
|
|
|
|
{
|
|
|
|
if (lcd.pins.bl == PIN_NONE)
|
|
|
|
return;
|
|
|
|
|
|
|
|
cancel_delayed_work_sync(&lcd.bl_work);
|
|
|
|
|
|
|
|
mutex_lock(&lcd.bl_tempo_lock);
|
|
|
|
if (!lcd.bl_tempo && !(lcd.flags & LCD_FLAG_L))
|
|
|
|
__lcd_backlight(1);
|
|
|
|
lcd.bl_tempo = true;
|
|
|
|
schedule_delayed_work(&lcd.bl_work, FLASH_LIGHT_TEMPO * HZ);
|
|
|
|
mutex_unlock(&lcd.bl_tempo_lock);
|
|
|
|
}
|
|
|
|
|
2008-11-14 01:18:59 +00:00
|
|
|
/* send a command to the LCD panel in serial mode */
|
2008-11-22 10:29:33 +00:00
|
|
|
static void lcd_write_cmd_s(int cmd)
|
|
|
|
{
|
2012-09-09 08:23:46 +00:00
|
|
|
spin_lock_irq(&pprt_lock);
|
2008-11-22 10:29:33 +00:00
|
|
|
lcd_send_serial(0x1F); /* R/W=W, RS=0 */
|
|
|
|
lcd_send_serial(cmd & 0x0F);
|
|
|
|
lcd_send_serial((cmd >> 4) & 0x0F);
|
2016-01-23 09:19:20 +00:00
|
|
|
udelay(40); /* the shortest command takes at least 40 us */
|
2012-09-09 08:23:46 +00:00
|
|
|
spin_unlock_irq(&pprt_lock);
|
2008-11-14 01:18:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* send data to the LCD panel in serial mode */
|
2008-11-22 10:29:33 +00:00
|
|
|
static void lcd_write_data_s(int data)
|
|
|
|
{
|
2012-09-09 08:23:46 +00:00
|
|
|
spin_lock_irq(&pprt_lock);
|
2008-11-22 10:29:33 +00:00
|
|
|
lcd_send_serial(0x5F); /* R/W=W, RS=1 */
|
|
|
|
lcd_send_serial(data & 0x0F);
|
|
|
|
lcd_send_serial((data >> 4) & 0x0F);
|
2016-01-23 09:19:20 +00:00
|
|
|
udelay(40); /* the shortest data takes at least 40 us */
|
2012-09-09 08:23:46 +00:00
|
|
|
spin_unlock_irq(&pprt_lock);
|
2008-11-14 01:18:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* send a command to the LCD panel in 8 bits parallel mode */
|
2008-11-22 10:29:33 +00:00
|
|
|
static void lcd_write_cmd_p8(int cmd)
|
|
|
|
{
|
2012-09-09 08:23:46 +00:00
|
|
|
spin_lock_irq(&pprt_lock);
|
2008-11-22 10:29:33 +00:00
|
|
|
/* present the data to the data port */
|
|
|
|
w_dtr(pprt, cmd);
|
2016-01-23 09:19:20 +00:00
|
|
|
udelay(20); /* maintain the data during 20 us before the strobe */
|
2008-11-14 01:18:59 +00:00
|
|
|
|
2016-02-11 12:29:23 +00:00
|
|
|
set_bit(LCD_BIT_E, bits);
|
|
|
|
clear_bit(LCD_BIT_RS, bits);
|
|
|
|
clear_bit(LCD_BIT_RW, bits);
|
2008-11-22 10:29:33 +00:00
|
|
|
set_ctrl_bits();
|
2008-11-14 01:18:59 +00:00
|
|
|
|
2016-01-23 09:19:20 +00:00
|
|
|
udelay(40); /* maintain the strobe during 40 us */
|
2008-11-14 01:18:59 +00:00
|
|
|
|
2016-02-11 12:29:23 +00:00
|
|
|
clear_bit(LCD_BIT_E, bits);
|
2008-11-22 10:29:33 +00:00
|
|
|
set_ctrl_bits();
|
2008-11-14 01:18:59 +00:00
|
|
|
|
2016-01-23 09:19:20 +00:00
|
|
|
udelay(120); /* the shortest command takes at least 120 us */
|
2012-09-09 08:23:46 +00:00
|
|
|
spin_unlock_irq(&pprt_lock);
|
2008-11-14 01:18:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* send data to the LCD panel in 8 bits parallel mode */
|
2008-11-22 10:29:33 +00:00
|
|
|
static void lcd_write_data_p8(int data)
|
|
|
|
{
|
2012-09-09 08:23:46 +00:00
|
|
|
spin_lock_irq(&pprt_lock);
|
2008-11-22 10:29:33 +00:00
|
|
|
/* present the data to the data port */
|
|
|
|
w_dtr(pprt, data);
|
2016-01-23 09:19:20 +00:00
|
|
|
udelay(20); /* maintain the data during 20 us before the strobe */
|
2008-11-14 01:18:59 +00:00
|
|
|
|
2016-02-11 12:29:23 +00:00
|
|
|
set_bit(LCD_BIT_E, bits);
|
|
|
|
set_bit(LCD_BIT_RS, bits);
|
|
|
|
clear_bit(LCD_BIT_RW, bits);
|
2008-11-22 10:29:33 +00:00
|
|
|
set_ctrl_bits();
|
2008-11-14 01:18:59 +00:00
|
|
|
|
2016-01-23 09:19:20 +00:00
|
|
|
udelay(40); /* maintain the strobe during 40 us */
|
2008-11-14 01:18:59 +00:00
|
|
|
|
2016-02-11 12:29:23 +00:00
|
|
|
clear_bit(LCD_BIT_E, bits);
|
2008-11-22 10:29:33 +00:00
|
|
|
set_ctrl_bits();
|
2008-11-14 01:18:59 +00:00
|
|
|
|
2016-01-23 09:19:20 +00:00
|
|
|
udelay(45); /* the shortest data takes at least 45 us */
|
2012-09-09 08:23:46 +00:00
|
|
|
spin_unlock_irq(&pprt_lock);
|
2008-11-14 01:18:59 +00:00
|
|
|
}
|
|
|
|
|
2009-08-20 22:13:18 +00:00
|
|
|
/* send a command to the TI LCD panel */
|
|
|
|
static void lcd_write_cmd_tilcd(int cmd)
|
|
|
|
{
|
2012-09-09 08:23:46 +00:00
|
|
|
spin_lock_irq(&pprt_lock);
|
2009-08-20 22:13:18 +00:00
|
|
|
/* present the data to the control port */
|
|
|
|
w_ctr(pprt, cmd);
|
2016-01-23 09:19:20 +00:00
|
|
|
udelay(60);
|
2012-09-09 08:23:46 +00:00
|
|
|
spin_unlock_irq(&pprt_lock);
|
2009-08-20 22:13:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* send data to the TI LCD panel */
|
|
|
|
static void lcd_write_data_tilcd(int data)
|
|
|
|
{
|
2012-09-09 08:23:46 +00:00
|
|
|
spin_lock_irq(&pprt_lock);
|
2009-08-20 22:13:18 +00:00
|
|
|
/* present the data to the data port */
|
|
|
|
w_dtr(pprt, data);
|
2016-01-23 09:19:20 +00:00
|
|
|
udelay(60);
|
2012-09-09 08:23:46 +00:00
|
|
|
spin_unlock_irq(&pprt_lock);
|
2009-08-20 22:13:18 +00:00
|
|
|
}
|
|
|
|
|
2008-11-22 10:29:33 +00:00
|
|
|
static void lcd_gotoxy(void)
|
|
|
|
{
|
2014-12-05 21:28:19 +00:00
|
|
|
lcd_write_cmd(LCD_CMD_SET_DDRAM_ADDR
|
2014-11-27 21:36:53 +00:00
|
|
|
| (lcd.addr.y ? lcd.hwidth : 0)
|
2015-08-27 15:32:46 +00:00
|
|
|
/*
|
|
|
|
* we force the cursor to stay at the end of the
|
|
|
|
* line if it wants to go farther
|
|
|
|
*/
|
2014-11-27 21:36:53 +00:00
|
|
|
| ((lcd.addr.x < lcd.bwidth) ? lcd.addr.x &
|
2014-11-27 21:36:51 +00:00
|
|
|
(lcd.hwidth - 1) : lcd.bwidth - 1));
|
2008-11-14 01:18:59 +00:00
|
|
|
}
|
|
|
|
|
2017-02-06 14:38:09 +00:00
|
|
|
static void lcd_home(void)
|
|
|
|
{
|
|
|
|
lcd.addr.x = 0;
|
|
|
|
lcd.addr.y = 0;
|
|
|
|
lcd_gotoxy();
|
|
|
|
}
|
|
|
|
|
2008-11-22 10:29:33 +00:00
|
|
|
static void lcd_print(char c)
|
|
|
|
{
|
2014-11-27 21:36:53 +00:00
|
|
|
if (lcd.addr.x < lcd.bwidth) {
|
2015-10-03 11:52:09 +00:00
|
|
|
if (lcd_char_conv)
|
2008-11-22 10:29:33 +00:00
|
|
|
c = lcd_char_conv[(unsigned char)c];
|
|
|
|
lcd_write_data(c);
|
2014-11-27 21:36:53 +00:00
|
|
|
lcd.addr.x++;
|
2008-11-22 10:29:33 +00:00
|
|
|
}
|
|
|
|
/* prevents the cursor from wrapping onto the next line */
|
2014-11-27 21:36:53 +00:00
|
|
|
if (lcd.addr.x == lcd.bwidth)
|
2008-11-22 10:29:33 +00:00
|
|
|
lcd_gotoxy();
|
2008-11-14 01:18:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* fills the display with spaces and resets X/Y */
|
2008-11-22 10:29:33 +00:00
|
|
|
static void lcd_clear_fast_s(void)
|
|
|
|
{
|
|
|
|
int pos;
|
2014-04-04 19:45:07 +00:00
|
|
|
|
2017-02-06 14:38:09 +00:00
|
|
|
lcd_home();
|
2008-11-22 10:29:33 +00:00
|
|
|
|
2012-09-09 08:23:46 +00:00
|
|
|
spin_lock_irq(&pprt_lock);
|
2014-11-27 21:36:51 +00:00
|
|
|
for (pos = 0; pos < lcd.height * lcd.hwidth; pos++) {
|
2008-11-22 10:29:33 +00:00
|
|
|
lcd_send_serial(0x5F); /* R/W=W, RS=1 */
|
|
|
|
lcd_send_serial(' ' & 0x0F);
|
|
|
|
lcd_send_serial((' ' >> 4) & 0x0F);
|
2015-12-08 21:30:40 +00:00
|
|
|
/* the shortest data takes at least 40 us */
|
2016-02-01 20:50:26 +00:00
|
|
|
udelay(40);
|
2008-11-22 10:29:33 +00:00
|
|
|
}
|
2012-09-09 08:23:46 +00:00
|
|
|
spin_unlock_irq(&pprt_lock);
|
2008-11-22 10:29:33 +00:00
|
|
|
|
2017-02-06 14:38:09 +00:00
|
|
|
lcd_home();
|
2008-11-14 01:18:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* fills the display with spaces and resets X/Y */
|
2008-11-22 10:29:33 +00:00
|
|
|
static void lcd_clear_fast_p8(void)
|
|
|
|
{
|
|
|
|
int pos;
|
2014-04-04 19:45:07 +00:00
|
|
|
|
2017-02-06 14:38:09 +00:00
|
|
|
lcd_home();
|
2008-11-14 01:18:59 +00:00
|
|
|
|
2012-09-09 08:23:46 +00:00
|
|
|
spin_lock_irq(&pprt_lock);
|
2014-11-27 21:36:51 +00:00
|
|
|
for (pos = 0; pos < lcd.height * lcd.hwidth; pos++) {
|
2008-11-22 10:29:33 +00:00
|
|
|
/* present the data to the data port */
|
|
|
|
w_dtr(pprt, ' ');
|
2010-06-11 21:27:36 +00:00
|
|
|
|
|
|
|
/* maintain the data during 20 us before the strobe */
|
2016-01-23 09:19:20 +00:00
|
|
|
udelay(20);
|
2008-11-14 01:18:59 +00:00
|
|
|
|
2016-02-11 12:29:23 +00:00
|
|
|
set_bit(LCD_BIT_E, bits);
|
|
|
|
set_bit(LCD_BIT_RS, bits);
|
|
|
|
clear_bit(LCD_BIT_RW, bits);
|
2008-11-22 10:29:33 +00:00
|
|
|
set_ctrl_bits();
|
2008-11-14 01:18:59 +00:00
|
|
|
|
2010-06-11 21:27:36 +00:00
|
|
|
/* maintain the strobe during 40 us */
|
2016-01-23 09:19:20 +00:00
|
|
|
udelay(40);
|
2008-11-14 01:18:59 +00:00
|
|
|
|
2016-02-11 12:29:23 +00:00
|
|
|
clear_bit(LCD_BIT_E, bits);
|
2008-11-22 10:29:33 +00:00
|
|
|
set_ctrl_bits();
|
2008-11-14 01:18:59 +00:00
|
|
|
|
2010-06-11 21:27:36 +00:00
|
|
|
/* the shortest data takes at least 45 us */
|
2016-01-23 09:19:20 +00:00
|
|
|
udelay(45);
|
2008-11-22 10:29:33 +00:00
|
|
|
}
|
2012-09-09 08:23:46 +00:00
|
|
|
spin_unlock_irq(&pprt_lock);
|
2008-11-14 01:18:59 +00:00
|
|
|
|
2017-02-06 14:38:09 +00:00
|
|
|
lcd_home();
|
2008-11-14 01:18:59 +00:00
|
|
|
}
|
|
|
|
|
2009-08-20 22:13:18 +00:00
|
|
|
/* fills the display with spaces and resets X/Y */
|
|
|
|
static void lcd_clear_fast_tilcd(void)
|
|
|
|
{
|
|
|
|
int pos;
|
2014-04-04 19:45:07 +00:00
|
|
|
|
2017-02-06 14:38:09 +00:00
|
|
|
lcd_home();
|
2009-08-20 22:13:18 +00:00
|
|
|
|
2012-09-09 08:23:46 +00:00
|
|
|
spin_lock_irq(&pprt_lock);
|
2014-11-27 21:36:51 +00:00
|
|
|
for (pos = 0; pos < lcd.height * lcd.hwidth; pos++) {
|
2009-08-20 22:13:18 +00:00
|
|
|
/* present the data to the data port */
|
|
|
|
w_dtr(pprt, ' ');
|
2016-01-23 09:19:20 +00:00
|
|
|
udelay(60);
|
2009-08-20 22:13:18 +00:00
|
|
|
}
|
|
|
|
|
2012-09-09 08:23:46 +00:00
|
|
|
spin_unlock_irq(&pprt_lock);
|
2009-08-20 22:13:18 +00:00
|
|
|
|
2017-02-06 14:38:09 +00:00
|
|
|
lcd_home();
|
2009-08-20 22:13:18 +00:00
|
|
|
}
|
|
|
|
|
2008-11-14 01:18:59 +00:00
|
|
|
/* clears the display and resets X/Y */
|
2008-11-22 10:29:33 +00:00
|
|
|
static void lcd_clear_display(void)
|
|
|
|
{
|
2014-12-05 21:28:19 +00:00
|
|
|
lcd_write_cmd(LCD_CMD_DISPLAY_CLEAR);
|
2014-11-27 21:36:53 +00:00
|
|
|
lcd.addr.x = 0;
|
|
|
|
lcd.addr.y = 0;
|
2008-11-22 10:29:33 +00:00
|
|
|
/* we must wait a few milliseconds (15) */
|
|
|
|
long_sleep(15);
|
2008-11-14 01:18:59 +00:00
|
|
|
}
|
|
|
|
|
2008-11-22 10:29:33 +00:00
|
|
|
static void lcd_init_display(void)
|
|
|
|
{
|
2014-11-27 21:36:53 +00:00
|
|
|
lcd.flags = ((lcd.height > 1) ? LCD_FLAG_N : 0)
|
2008-11-22 10:29:33 +00:00
|
|
|
| LCD_FLAG_D | LCD_FLAG_C | LCD_FLAG_B;
|
2008-11-14 01:18:59 +00:00
|
|
|
|
2008-11-22 10:29:33 +00:00
|
|
|
long_sleep(20); /* wait 20 ms after power-up for the paranoid */
|
2008-11-14 01:18:59 +00:00
|
|
|
|
2014-12-05 21:28:19 +00:00
|
|
|
/* 8bits, 1 line, small fonts; let's do it 3 times */
|
|
|
|
lcd_write_cmd(LCD_CMD_FUNCTION_SET | LCD_CMD_DATA_LEN_8BITS);
|
2008-11-22 10:29:33 +00:00
|
|
|
long_sleep(10);
|
2014-12-05 21:28:19 +00:00
|
|
|
lcd_write_cmd(LCD_CMD_FUNCTION_SET | LCD_CMD_DATA_LEN_8BITS);
|
2008-11-22 10:29:33 +00:00
|
|
|
long_sleep(10);
|
2014-12-05 21:28:19 +00:00
|
|
|
lcd_write_cmd(LCD_CMD_FUNCTION_SET | LCD_CMD_DATA_LEN_8BITS);
|
2008-11-22 10:29:33 +00:00
|
|
|
long_sleep(10);
|
2008-11-14 01:18:59 +00:00
|
|
|
|
2014-12-05 21:28:19 +00:00
|
|
|
/* set font height and lines number */
|
|
|
|
lcd_write_cmd(LCD_CMD_FUNCTION_SET | LCD_CMD_DATA_LEN_8BITS
|
|
|
|
| ((lcd.flags & LCD_FLAG_F) ? LCD_CMD_FONT_5X10_DOTS : 0)
|
|
|
|
| ((lcd.flags & LCD_FLAG_N) ? LCD_CMD_TWO_LINES : 0)
|
2008-11-22 10:29:33 +00:00
|
|
|
);
|
|
|
|
long_sleep(10);
|
2008-11-14 01:18:59 +00:00
|
|
|
|
2014-12-05 21:28:19 +00:00
|
|
|
/* display off, cursor off, blink off */
|
|
|
|
lcd_write_cmd(LCD_CMD_DISPLAY_CTRL);
|
2008-11-22 10:29:33 +00:00
|
|
|
long_sleep(10);
|
2008-11-14 01:18:59 +00:00
|
|
|
|
2014-12-05 21:28:19 +00:00
|
|
|
lcd_write_cmd(LCD_CMD_DISPLAY_CTRL /* set display mode */
|
|
|
|
| ((lcd.flags & LCD_FLAG_D) ? LCD_CMD_DISPLAY_ON : 0)
|
|
|
|
| ((lcd.flags & LCD_FLAG_C) ? LCD_CMD_CURSOR_ON : 0)
|
|
|
|
| ((lcd.flags & LCD_FLAG_B) ? LCD_CMD_BLINK_ON : 0)
|
2008-11-22 10:29:33 +00:00
|
|
|
);
|
2008-11-14 01:18:59 +00:00
|
|
|
|
2014-11-27 21:36:53 +00:00
|
|
|
lcd_backlight((lcd.flags & LCD_FLAG_L) ? 1 : 0);
|
2008-11-14 01:18:59 +00:00
|
|
|
|
2008-11-22 10:29:33 +00:00
|
|
|
long_sleep(10);
|
2008-11-14 01:18:59 +00:00
|
|
|
|
2010-06-11 21:27:36 +00:00
|
|
|
/* entry mode set : increment, cursor shifting */
|
2014-12-05 21:28:19 +00:00
|
|
|
lcd_write_cmd(LCD_CMD_ENTRY_MODE | LCD_CMD_CURSOR_INC);
|
2008-11-14 01:18:59 +00:00
|
|
|
|
2008-11-22 10:29:33 +00:00
|
|
|
lcd_clear_display();
|
2008-11-14 01:18:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* These are the file operation function for user access to /dev/lcd
|
|
|
|
* This function can also be called from inside the kernel, by
|
|
|
|
* setting file and ppos to NULL.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2010-06-11 21:27:36 +00:00
|
|
|
static inline int handle_lcd_special_code(void)
|
|
|
|
{
|
|
|
|
/* LCD special codes */
|
|
|
|
|
|
|
|
int processed = 0;
|
|
|
|
|
2014-11-27 21:36:53 +00:00
|
|
|
char *esc = lcd.esc_seq.buf + 2;
|
|
|
|
int oldflags = lcd.flags;
|
2010-06-11 21:27:36 +00:00
|
|
|
|
|
|
|
/* check for display mode flags */
|
|
|
|
switch (*esc) {
|
|
|
|
case 'D': /* Display ON */
|
2014-11-27 21:36:53 +00:00
|
|
|
lcd.flags |= LCD_FLAG_D;
|
2010-06-11 21:27:36 +00:00
|
|
|
processed = 1;
|
|
|
|
break;
|
|
|
|
case 'd': /* Display OFF */
|
2014-11-27 21:36:53 +00:00
|
|
|
lcd.flags &= ~LCD_FLAG_D;
|
2010-06-11 21:27:36 +00:00
|
|
|
processed = 1;
|
|
|
|
break;
|
|
|
|
case 'C': /* Cursor ON */
|
2014-11-27 21:36:53 +00:00
|
|
|
lcd.flags |= LCD_FLAG_C;
|
2010-06-11 21:27:36 +00:00
|
|
|
processed = 1;
|
|
|
|
break;
|
|
|
|
case 'c': /* Cursor OFF */
|
2014-11-27 21:36:53 +00:00
|
|
|
lcd.flags &= ~LCD_FLAG_C;
|
2010-06-11 21:27:36 +00:00
|
|
|
processed = 1;
|
|
|
|
break;
|
|
|
|
case 'B': /* Blink ON */
|
2014-11-27 21:36:53 +00:00
|
|
|
lcd.flags |= LCD_FLAG_B;
|
2010-06-11 21:27:36 +00:00
|
|
|
processed = 1;
|
|
|
|
break;
|
|
|
|
case 'b': /* Blink OFF */
|
2014-11-27 21:36:53 +00:00
|
|
|
lcd.flags &= ~LCD_FLAG_B;
|
2010-06-11 21:27:36 +00:00
|
|
|
processed = 1;
|
|
|
|
break;
|
|
|
|
case '+': /* Back light ON */
|
2014-11-27 21:36:53 +00:00
|
|
|
lcd.flags |= LCD_FLAG_L;
|
2010-06-11 21:27:36 +00:00
|
|
|
processed = 1;
|
|
|
|
break;
|
|
|
|
case '-': /* Back light OFF */
|
2014-11-27 21:36:53 +00:00
|
|
|
lcd.flags &= ~LCD_FLAG_L;
|
2010-06-11 21:27:36 +00:00
|
|
|
processed = 1;
|
|
|
|
break;
|
|
|
|
case '*':
|
2017-02-06 14:38:10 +00:00
|
|
|
/* flash back light */
|
|
|
|
lcd_poke();
|
2010-06-11 21:27:36 +00:00
|
|
|
processed = 1;
|
|
|
|
break;
|
|
|
|
case 'f': /* Small Font */
|
2014-11-27 21:36:53 +00:00
|
|
|
lcd.flags &= ~LCD_FLAG_F;
|
2010-06-11 21:27:36 +00:00
|
|
|
processed = 1;
|
|
|
|
break;
|
|
|
|
case 'F': /* Large Font */
|
2014-11-27 21:36:53 +00:00
|
|
|
lcd.flags |= LCD_FLAG_F;
|
2010-06-11 21:27:36 +00:00
|
|
|
processed = 1;
|
|
|
|
break;
|
|
|
|
case 'n': /* One Line */
|
2014-11-27 21:36:53 +00:00
|
|
|
lcd.flags &= ~LCD_FLAG_N;
|
2010-06-11 21:27:36 +00:00
|
|
|
processed = 1;
|
|
|
|
break;
|
|
|
|
case 'N': /* Two Lines */
|
2014-11-27 21:36:53 +00:00
|
|
|
lcd.flags |= LCD_FLAG_N;
|
2010-06-11 21:27:36 +00:00
|
|
|
break;
|
|
|
|
case 'l': /* Shift Cursor Left */
|
2014-11-27 21:36:53 +00:00
|
|
|
if (lcd.addr.x > 0) {
|
2010-06-11 21:27:36 +00:00
|
|
|
/* back one char if not at end of line */
|
2014-11-27 21:36:53 +00:00
|
|
|
if (lcd.addr.x < lcd.bwidth)
|
2014-12-05 21:28:19 +00:00
|
|
|
lcd_write_cmd(LCD_CMD_SHIFT);
|
2014-11-27 21:36:53 +00:00
|
|
|
lcd.addr.x--;
|
2010-06-11 21:27:36 +00:00
|
|
|
}
|
|
|
|
processed = 1;
|
|
|
|
break;
|
|
|
|
case 'r': /* shift cursor right */
|
2014-11-27 21:36:53 +00:00
|
|
|
if (lcd.addr.x < lcd.width) {
|
2010-06-11 21:27:36 +00:00
|
|
|
/* allow the cursor to pass the end of the line */
|
2014-12-05 21:28:19 +00:00
|
|
|
if (lcd.addr.x < (lcd.bwidth - 1))
|
|
|
|
lcd_write_cmd(LCD_CMD_SHIFT |
|
|
|
|
LCD_CMD_SHIFT_RIGHT);
|
2014-11-27 21:36:53 +00:00
|
|
|
lcd.addr.x++;
|
2010-06-11 21:27:36 +00:00
|
|
|
}
|
|
|
|
processed = 1;
|
|
|
|
break;
|
|
|
|
case 'L': /* shift display left */
|
2014-12-05 21:28:19 +00:00
|
|
|
lcd_write_cmd(LCD_CMD_SHIFT | LCD_CMD_DISPLAY_SHIFT);
|
2010-06-11 21:27:36 +00:00
|
|
|
processed = 1;
|
|
|
|
break;
|
|
|
|
case 'R': /* shift display right */
|
2014-12-05 21:28:19 +00:00
|
|
|
lcd_write_cmd(LCD_CMD_SHIFT | LCD_CMD_DISPLAY_SHIFT |
|
|
|
|
LCD_CMD_SHIFT_RIGHT);
|
2010-06-11 21:27:36 +00:00
|
|
|
processed = 1;
|
|
|
|
break;
|
|
|
|
case 'k': { /* kill end of line */
|
|
|
|
int x;
|
2014-04-04 19:45:07 +00:00
|
|
|
|
2014-11-27 21:36:53 +00:00
|
|
|
for (x = lcd.addr.x; x < lcd.bwidth; x++)
|
2010-06-11 21:27:36 +00:00
|
|
|
lcd_write_data(' ');
|
|
|
|
|
|
|
|
/* restore cursor position */
|
|
|
|
lcd_gotoxy();
|
|
|
|
processed = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 'I': /* reinitialize display */
|
|
|
|
lcd_init_display();
|
|
|
|
processed = 1;
|
|
|
|
break;
|
|
|
|
case 'G': {
|
|
|
|
/* Generator : LGcxxxxx...xx; must have <c> between '0'
|
|
|
|
* and '7', representing the numerical ASCII code of the
|
|
|
|
* redefined character, and <xx...xx> a sequence of 16
|
|
|
|
* hex digits representing 8 bytes for each character.
|
|
|
|
* Most LCDs will only use 5 lower bits of the 7 first
|
|
|
|
* bytes.
|
|
|
|
*/
|
|
|
|
|
|
|
|
unsigned char cgbytes[8];
|
|
|
|
unsigned char cgaddr;
|
|
|
|
int cgoffset;
|
|
|
|
int shift;
|
|
|
|
char value;
|
|
|
|
int addr;
|
|
|
|
|
2015-10-03 11:52:09 +00:00
|
|
|
if (!strchr(esc, ';'))
|
2010-06-11 21:27:36 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
esc++;
|
|
|
|
|
|
|
|
cgaddr = *(esc++) - '0';
|
|
|
|
if (cgaddr > 7) {
|
|
|
|
processed = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
cgoffset = 0;
|
|
|
|
shift = 0;
|
|
|
|
value = 0;
|
|
|
|
while (*esc && cgoffset < 8) {
|
|
|
|
shift ^= 4;
|
2014-05-21 12:09:59 +00:00
|
|
|
if (*esc >= '0' && *esc <= '9') {
|
2010-06-11 21:27:36 +00:00
|
|
|
value |= (*esc - '0') << shift;
|
2014-05-21 12:09:59 +00:00
|
|
|
} else if (*esc >= 'A' && *esc <= 'Z') {
|
2010-06-11 21:27:36 +00:00
|
|
|
value |= (*esc - 'A' + 10) << shift;
|
2014-05-21 12:09:59 +00:00
|
|
|
} else if (*esc >= 'a' && *esc <= 'z') {
|
2010-06-11 21:27:36 +00:00
|
|
|
value |= (*esc - 'a' + 10) << shift;
|
2014-05-21 12:09:59 +00:00
|
|
|
} else {
|
2010-06-11 21:27:36 +00:00
|
|
|
esc++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (shift == 0) {
|
|
|
|
cgbytes[cgoffset++] = value;
|
|
|
|
value = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
esc++;
|
|
|
|
}
|
|
|
|
|
2014-12-05 21:28:19 +00:00
|
|
|
lcd_write_cmd(LCD_CMD_SET_CGRAM_ADDR | (cgaddr * 8));
|
2010-06-11 21:27:36 +00:00
|
|
|
for (addr = 0; addr < cgoffset; addr++)
|
|
|
|
lcd_write_data(cgbytes[addr]);
|
|
|
|
|
|
|
|
/* ensures that we stop writing to CGRAM */
|
|
|
|
lcd_gotoxy();
|
|
|
|
processed = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 'x': /* gotoxy : LxXXX[yYYY]; */
|
|
|
|
case 'y': /* gotoxy : LyYYY[xXXX]; */
|
2015-10-03 11:52:09 +00:00
|
|
|
if (!strchr(esc, ';'))
|
2010-06-11 21:27:36 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
while (*esc) {
|
|
|
|
if (*esc == 'x') {
|
|
|
|
esc++;
|
2014-11-27 21:36:53 +00:00
|
|
|
if (kstrtoul(esc, 10, &lcd.addr.x) < 0)
|
2011-08-30 18:29:24 +00:00
|
|
|
break;
|
2010-06-11 21:27:36 +00:00
|
|
|
} else if (*esc == 'y') {
|
|
|
|
esc++;
|
2014-11-27 21:36:53 +00:00
|
|
|
if (kstrtoul(esc, 10, &lcd.addr.y) < 0)
|
2011-08-30 18:29:24 +00:00
|
|
|
break;
|
2014-05-21 12:09:59 +00:00
|
|
|
} else {
|
2010-06-11 21:27:36 +00:00
|
|
|
break;
|
2014-05-21 12:09:59 +00:00
|
|
|
}
|
2010-06-11 21:27:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
lcd_gotoxy();
|
|
|
|
processed = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2014-12-05 21:28:19 +00:00
|
|
|
/* TODO: This indent party here got ugly, clean it! */
|
2012-09-20 01:51:07 +00:00
|
|
|
/* Check whether one flag was changed */
|
2014-11-27 21:36:53 +00:00
|
|
|
if (oldflags != lcd.flags) {
|
2010-06-11 21:27:36 +00:00
|
|
|
/* check whether one of B,C,D flags were changed */
|
2014-11-27 21:36:53 +00:00
|
|
|
if ((oldflags ^ lcd.flags) &
|
2010-06-11 21:27:36 +00:00
|
|
|
(LCD_FLAG_B | LCD_FLAG_C | LCD_FLAG_D))
|
|
|
|
/* set display mode */
|
2014-12-05 21:28:19 +00:00
|
|
|
lcd_write_cmd(LCD_CMD_DISPLAY_CTRL
|
|
|
|
| ((lcd.flags & LCD_FLAG_D)
|
|
|
|
? LCD_CMD_DISPLAY_ON : 0)
|
|
|
|
| ((lcd.flags & LCD_FLAG_C)
|
|
|
|
? LCD_CMD_CURSOR_ON : 0)
|
|
|
|
| ((lcd.flags & LCD_FLAG_B)
|
|
|
|
? LCD_CMD_BLINK_ON : 0));
|
2010-06-11 21:27:36 +00:00
|
|
|
/* check whether one of F,N flags was changed */
|
2014-11-27 21:36:53 +00:00
|
|
|
else if ((oldflags ^ lcd.flags) & (LCD_FLAG_F | LCD_FLAG_N))
|
2014-12-05 21:28:19 +00:00
|
|
|
lcd_write_cmd(LCD_CMD_FUNCTION_SET
|
|
|
|
| LCD_CMD_DATA_LEN_8BITS
|
|
|
|
| ((lcd.flags & LCD_FLAG_F)
|
|
|
|
? LCD_CMD_FONT_5X10_DOTS
|
2017-02-06 14:38:03 +00:00
|
|
|
: 0)
|
|
|
|
| ((lcd.flags & LCD_FLAG_N)
|
|
|
|
? LCD_CMD_TWO_LINES
|
2014-12-05 21:28:19 +00:00
|
|
|
: 0));
|
2012-09-20 01:51:07 +00:00
|
|
|
/* check whether L flag was changed */
|
2017-02-06 14:38:10 +00:00
|
|
|
else if ((oldflags ^ lcd.flags) & (LCD_FLAG_L))
|
|
|
|
lcd_backlight(!!(lcd.flags & LCD_FLAG_L));
|
2010-06-11 21:27:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return processed;
|
|
|
|
}
|
|
|
|
|
2014-04-18 16:10:57 +00:00
|
|
|
static void lcd_write_char(char c)
|
|
|
|
{
|
|
|
|
/* first, we'll test if we're in escape mode */
|
2014-11-27 21:36:53 +00:00
|
|
|
if ((c != '\n') && lcd.esc_seq.len >= 0) {
|
2014-04-18 16:10:57 +00:00
|
|
|
/* yes, let's add this char to the buffer */
|
2014-11-27 21:36:53 +00:00
|
|
|
lcd.esc_seq.buf[lcd.esc_seq.len++] = c;
|
|
|
|
lcd.esc_seq.buf[lcd.esc_seq.len] = 0;
|
2014-04-18 16:10:57 +00:00
|
|
|
} else {
|
|
|
|
/* aborts any previous escape sequence */
|
2014-11-27 21:36:53 +00:00
|
|
|
lcd.esc_seq.len = -1;
|
2014-04-18 16:10:57 +00:00
|
|
|
|
|
|
|
switch (c) {
|
|
|
|
case LCD_ESCAPE_CHAR:
|
|
|
|
/* start of an escape sequence */
|
2014-11-27 21:36:53 +00:00
|
|
|
lcd.esc_seq.len = 0;
|
|
|
|
lcd.esc_seq.buf[lcd.esc_seq.len] = 0;
|
2014-04-18 16:10:57 +00:00
|
|
|
break;
|
|
|
|
case '\b':
|
|
|
|
/* go back one char and clear it */
|
2014-11-27 21:36:53 +00:00
|
|
|
if (lcd.addr.x > 0) {
|
2015-08-27 15:32:46 +00:00
|
|
|
/*
|
|
|
|
* check if we're not at the
|
|
|
|
* end of the line
|
|
|
|
*/
|
2014-11-27 21:36:53 +00:00
|
|
|
if (lcd.addr.x < lcd.bwidth)
|
2014-04-18 16:10:57 +00:00
|
|
|
/* back one char */
|
2014-12-05 21:28:19 +00:00
|
|
|
lcd_write_cmd(LCD_CMD_SHIFT);
|
2014-11-27 21:36:53 +00:00
|
|
|
lcd.addr.x--;
|
2014-04-18 16:10:57 +00:00
|
|
|
}
|
|
|
|
/* replace with a space */
|
|
|
|
lcd_write_data(' ');
|
|
|
|
/* back one char again */
|
2014-12-05 21:28:19 +00:00
|
|
|
lcd_write_cmd(LCD_CMD_SHIFT);
|
2014-04-18 16:10:57 +00:00
|
|
|
break;
|
|
|
|
case '\014':
|
|
|
|
/* quickly clear the display */
|
|
|
|
lcd_clear_fast();
|
|
|
|
break;
|
|
|
|
case '\n':
|
2015-08-27 15:32:46 +00:00
|
|
|
/*
|
|
|
|
* flush the remainder of the current line and
|
|
|
|
* go to the beginning of the next line
|
|
|
|
*/
|
2014-11-27 21:36:53 +00:00
|
|
|
for (; lcd.addr.x < lcd.bwidth; lcd.addr.x++)
|
2014-04-18 16:10:57 +00:00
|
|
|
lcd_write_data(' ');
|
2014-11-27 21:36:53 +00:00
|
|
|
lcd.addr.x = 0;
|
|
|
|
lcd.addr.y = (lcd.addr.y + 1) % lcd.height;
|
2014-04-18 16:10:57 +00:00
|
|
|
lcd_gotoxy();
|
|
|
|
break;
|
|
|
|
case '\r':
|
|
|
|
/* go to the beginning of the same line */
|
2014-11-27 21:36:53 +00:00
|
|
|
lcd.addr.x = 0;
|
2014-04-18 16:10:57 +00:00
|
|
|
lcd_gotoxy();
|
|
|
|
break;
|
|
|
|
case '\t':
|
|
|
|
/* print a space instead of the tab */
|
|
|
|
lcd_print(' ');
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
/* simply print this char */
|
|
|
|
lcd_print(c);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-27 15:32:46 +00:00
|
|
|
/*
|
|
|
|
* now we'll see if we're in an escape mode and if the current
|
|
|
|
* escape sequence can be understood.
|
|
|
|
*/
|
2014-11-27 21:36:53 +00:00
|
|
|
if (lcd.esc_seq.len >= 2) {
|
2014-04-18 16:10:57 +00:00
|
|
|
int processed = 0;
|
|
|
|
|
2014-11-27 21:36:53 +00:00
|
|
|
if (!strcmp(lcd.esc_seq.buf, "[2J")) {
|
2014-04-18 16:10:57 +00:00
|
|
|
/* clear the display */
|
|
|
|
lcd_clear_fast();
|
|
|
|
processed = 1;
|
2014-11-27 21:36:53 +00:00
|
|
|
} else if (!strcmp(lcd.esc_seq.buf, "[H")) {
|
2014-04-18 16:10:57 +00:00
|
|
|
/* cursor to home */
|
2017-02-06 14:38:09 +00:00
|
|
|
lcd_home();
|
2014-04-18 16:10:57 +00:00
|
|
|
processed = 1;
|
|
|
|
}
|
|
|
|
/* codes starting with ^[[L */
|
2014-11-27 21:36:53 +00:00
|
|
|
else if ((lcd.esc_seq.len >= 3) &&
|
|
|
|
(lcd.esc_seq.buf[0] == '[') &&
|
|
|
|
(lcd.esc_seq.buf[1] == 'L')) {
|
2014-04-18 16:10:57 +00:00
|
|
|
processed = handle_lcd_special_code();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* LCD special escape codes */
|
2015-08-27 15:32:46 +00:00
|
|
|
/*
|
|
|
|
* flush the escape sequence if it's been processed
|
|
|
|
* or if it is getting too long.
|
|
|
|
*/
|
2014-11-27 21:36:53 +00:00
|
|
|
if (processed || (lcd.esc_seq.len >= LCD_ESCAPE_LEN))
|
|
|
|
lcd.esc_seq.len = -1;
|
2014-04-18 16:10:57 +00:00
|
|
|
} /* escape codes */
|
|
|
|
}
|
|
|
|
|
2008-11-22 10:29:33 +00:00
|
|
|
static ssize_t lcd_write(struct file *file,
|
2014-05-21 12:10:00 +00:00
|
|
|
const char __user *buf, size_t count, loff_t *ppos)
|
2008-11-22 10:29:33 +00:00
|
|
|
{
|
2014-04-18 16:10:57 +00:00
|
|
|
const char __user *tmp = buf;
|
2008-11-22 10:29:33 +00:00
|
|
|
char c;
|
|
|
|
|
2014-04-18 16:10:57 +00:00
|
|
|
for (; count-- > 0; (*ppos)++, tmp++) {
|
2008-11-22 10:29:33 +00:00
|
|
|
if (!in_interrupt() && (((count + 1) & 0x1f) == 0))
|
2015-08-27 15:32:46 +00:00
|
|
|
/*
|
|
|
|
* let's be a little nice with other processes
|
|
|
|
* that need some CPU
|
|
|
|
*/
|
2010-06-11 21:27:36 +00:00
|
|
|
schedule();
|
2008-11-22 10:29:33 +00:00
|
|
|
|
2014-04-23 17:42:11 +00:00
|
|
|
if (get_user(c, tmp))
|
2008-11-22 10:29:33 +00:00
|
|
|
return -EFAULT;
|
|
|
|
|
2014-04-18 16:10:57 +00:00
|
|
|
lcd_write_char(c);
|
2008-11-22 10:29:33 +00:00
|
|
|
}
|
2008-11-14 01:18:59 +00:00
|
|
|
|
2008-11-22 10:29:33 +00:00
|
|
|
return tmp - buf;
|
2008-11-14 01:18:59 +00:00
|
|
|
}
|
|
|
|
|
2008-11-22 10:29:33 +00:00
|
|
|
static int lcd_open(struct inode *inode, struct file *file)
|
|
|
|
{
|
2014-11-04 21:47:19 +00:00
|
|
|
if (!atomic_dec_and_test(&lcd_available))
|
2008-11-22 10:29:33 +00:00
|
|
|
return -EBUSY; /* open only once at a time */
|
2008-11-14 01:18:59 +00:00
|
|
|
|
2008-11-22 10:29:33 +00:00
|
|
|
if (file->f_mode & FMODE_READ) /* device is write-only */
|
|
|
|
return -EPERM;
|
2008-11-14 01:18:59 +00:00
|
|
|
|
2014-11-27 21:36:53 +00:00
|
|
|
if (lcd.must_clear) {
|
2008-11-22 10:29:33 +00:00
|
|
|
lcd_clear_display();
|
2014-11-27 21:36:53 +00:00
|
|
|
lcd.must_clear = false;
|
2008-11-22 10:29:33 +00:00
|
|
|
}
|
2010-07-07 21:40:09 +00:00
|
|
|
return nonseekable_open(inode, file);
|
2008-11-14 01:18:59 +00:00
|
|
|
}
|
|
|
|
|
2008-11-22 10:29:33 +00:00
|
|
|
static int lcd_release(struct inode *inode, struct file *file)
|
|
|
|
{
|
2014-11-04 21:47:19 +00:00
|
|
|
atomic_inc(&lcd_available);
|
2008-11-22 10:29:33 +00:00
|
|
|
return 0;
|
2008-11-14 01:18:59 +00:00
|
|
|
}
|
|
|
|
|
2010-06-11 21:27:36 +00:00
|
|
|
static const struct file_operations lcd_fops = {
|
2008-11-22 10:29:33 +00:00
|
|
|
.write = lcd_write,
|
|
|
|
.open = lcd_open,
|
|
|
|
.release = lcd_release,
|
2010-07-07 21:40:09 +00:00
|
|
|
.llseek = no_llseek,
|
2008-11-14 01:18:59 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static struct miscdevice lcd_dev = {
|
2014-10-29 22:32:30 +00:00
|
|
|
.minor = LCD_MINOR,
|
|
|
|
.name = "lcd",
|
|
|
|
.fops = &lcd_fops,
|
2008-11-14 01:18:59 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* public function usable from the kernel for any purpose */
|
2013-02-15 12:47:05 +00:00
|
|
|
static void panel_lcd_print(const char *s)
|
2008-11-22 10:29:33 +00:00
|
|
|
{
|
2014-04-18 16:10:57 +00:00
|
|
|
const char *tmp = s;
|
|
|
|
int count = strlen(s);
|
|
|
|
|
2014-11-27 21:36:53 +00:00
|
|
|
if (lcd.enabled && lcd.initialized) {
|
2014-04-18 16:10:57 +00:00
|
|
|
for (; count-- > 0; tmp++) {
|
|
|
|
if (!in_interrupt() && (((count + 1) & 0x1f) == 0))
|
2015-08-27 15:32:46 +00:00
|
|
|
/*
|
|
|
|
* let's be a little nice with other processes
|
|
|
|
* that need some CPU
|
|
|
|
*/
|
2014-04-18 16:10:57 +00:00
|
|
|
schedule();
|
|
|
|
|
|
|
|
lcd_write_char(*tmp);
|
|
|
|
}
|
|
|
|
}
|
2008-11-14 01:18:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* initialize the LCD driver */
|
2013-02-15 12:47:05 +00:00
|
|
|
static void lcd_init(void)
|
2008-11-22 10:29:33 +00:00
|
|
|
{
|
2014-11-27 21:36:50 +00:00
|
|
|
switch (selected_lcd_type) {
|
2010-06-11 21:27:36 +00:00
|
|
|
case LCD_TYPE_OLD:
|
|
|
|
/* parallel mode, 8 bits */
|
2014-11-27 21:36:51 +00:00
|
|
|
lcd.proto = LCD_PROTO_PARALLEL;
|
|
|
|
lcd.charset = LCD_CHARSET_NORMAL;
|
|
|
|
lcd.pins.e = PIN_STROBE;
|
|
|
|
lcd.pins.rs = PIN_AUTOLF;
|
|
|
|
|
|
|
|
lcd.width = 40;
|
|
|
|
lcd.bwidth = 40;
|
|
|
|
lcd.hwidth = 64;
|
|
|
|
lcd.height = 2;
|
2008-11-14 01:18:59 +00:00
|
|
|
break;
|
2010-06-11 21:27:36 +00:00
|
|
|
case LCD_TYPE_KS0074:
|
|
|
|
/* serial mode, ks0074 */
|
2014-11-27 21:36:51 +00:00
|
|
|
lcd.proto = LCD_PROTO_SERIAL;
|
|
|
|
lcd.charset = LCD_CHARSET_KS0074;
|
|
|
|
lcd.pins.bl = PIN_AUTOLF;
|
|
|
|
lcd.pins.cl = PIN_STROBE;
|
|
|
|
lcd.pins.da = PIN_D0;
|
|
|
|
|
|
|
|
lcd.width = 16;
|
|
|
|
lcd.bwidth = 40;
|
|
|
|
lcd.hwidth = 16;
|
|
|
|
lcd.height = 2;
|
2008-11-14 01:18:59 +00:00
|
|
|
break;
|
2010-06-11 21:27:36 +00:00
|
|
|
case LCD_TYPE_NEXCOM:
|
|
|
|
/* parallel mode, 8 bits, generic */
|
2014-11-27 21:36:51 +00:00
|
|
|
lcd.proto = LCD_PROTO_PARALLEL;
|
|
|
|
lcd.charset = LCD_CHARSET_NORMAL;
|
|
|
|
lcd.pins.e = PIN_AUTOLF;
|
|
|
|
lcd.pins.rs = PIN_SELECP;
|
|
|
|
lcd.pins.rw = PIN_INITP;
|
|
|
|
|
|
|
|
lcd.width = 16;
|
|
|
|
lcd.bwidth = 40;
|
|
|
|
lcd.hwidth = 64;
|
|
|
|
lcd.height = 2;
|
2008-11-14 01:18:59 +00:00
|
|
|
break;
|
2010-06-11 21:27:36 +00:00
|
|
|
case LCD_TYPE_CUSTOM:
|
|
|
|
/* customer-defined */
|
2014-11-27 21:36:51 +00:00
|
|
|
lcd.proto = DEFAULT_LCD_PROTO;
|
|
|
|
lcd.charset = DEFAULT_LCD_CHARSET;
|
2008-11-14 01:18:59 +00:00
|
|
|
/* default geometry will be set later */
|
|
|
|
break;
|
2010-06-11 21:27:36 +00:00
|
|
|
case LCD_TYPE_HANTRONIX:
|
|
|
|
/* parallel mode, 8 bits, hantronix-like */
|
2008-11-22 10:29:33 +00:00
|
|
|
default:
|
2014-11-27 21:36:51 +00:00
|
|
|
lcd.proto = LCD_PROTO_PARALLEL;
|
|
|
|
lcd.charset = LCD_CHARSET_NORMAL;
|
|
|
|
lcd.pins.e = PIN_STROBE;
|
|
|
|
lcd.pins.rs = PIN_SELECP;
|
|
|
|
|
|
|
|
lcd.width = 16;
|
|
|
|
lcd.bwidth = 40;
|
|
|
|
lcd.hwidth = 64;
|
|
|
|
lcd.height = 2;
|
2008-11-14 01:18:59 +00:00
|
|
|
break;
|
2008-11-22 10:29:33 +00:00
|
|
|
}
|
2008-11-14 01:18:59 +00:00
|
|
|
|
2014-11-27 21:36:51 +00:00
|
|
|
/* Overwrite with module params set on loading */
|
2014-11-27 21:36:52 +00:00
|
|
|
if (lcd_height != NOT_SET)
|
2014-11-27 21:36:51 +00:00
|
|
|
lcd.height = lcd_height;
|
2014-11-27 21:36:52 +00:00
|
|
|
if (lcd_width != NOT_SET)
|
2014-11-27 21:36:51 +00:00
|
|
|
lcd.width = lcd_width;
|
2014-11-27 21:36:52 +00:00
|
|
|
if (lcd_bwidth != NOT_SET)
|
2014-11-27 21:36:51 +00:00
|
|
|
lcd.bwidth = lcd_bwidth;
|
2014-11-27 21:36:52 +00:00
|
|
|
if (lcd_hwidth != NOT_SET)
|
2014-11-27 21:36:51 +00:00
|
|
|
lcd.hwidth = lcd_hwidth;
|
2014-11-27 21:36:52 +00:00
|
|
|
if (lcd_charset != NOT_SET)
|
2014-11-27 21:36:51 +00:00
|
|
|
lcd.charset = lcd_charset;
|
2014-11-27 21:36:52 +00:00
|
|
|
if (lcd_proto != NOT_SET)
|
2014-11-27 21:36:51 +00:00
|
|
|
lcd.proto = lcd_proto;
|
|
|
|
if (lcd_e_pin != PIN_NOT_SET)
|
|
|
|
lcd.pins.e = lcd_e_pin;
|
|
|
|
if (lcd_rs_pin != PIN_NOT_SET)
|
|
|
|
lcd.pins.rs = lcd_rs_pin;
|
|
|
|
if (lcd_rw_pin != PIN_NOT_SET)
|
|
|
|
lcd.pins.rw = lcd_rw_pin;
|
|
|
|
if (lcd_cl_pin != PIN_NOT_SET)
|
|
|
|
lcd.pins.cl = lcd_cl_pin;
|
|
|
|
if (lcd_da_pin != PIN_NOT_SET)
|
|
|
|
lcd.pins.da = lcd_da_pin;
|
|
|
|
if (lcd_bl_pin != PIN_NOT_SET)
|
|
|
|
lcd.pins.bl = lcd_bl_pin;
|
|
|
|
|
2008-11-22 10:29:33 +00:00
|
|
|
/* this is used to catch wrong and default values */
|
2014-11-27 21:36:51 +00:00
|
|
|
if (lcd.width <= 0)
|
|
|
|
lcd.width = DEFAULT_LCD_WIDTH;
|
|
|
|
if (lcd.bwidth <= 0)
|
|
|
|
lcd.bwidth = DEFAULT_LCD_BWIDTH;
|
|
|
|
if (lcd.hwidth <= 0)
|
|
|
|
lcd.hwidth = DEFAULT_LCD_HWIDTH;
|
|
|
|
if (lcd.height <= 0)
|
|
|
|
lcd.height = DEFAULT_LCD_HEIGHT;
|
|
|
|
|
|
|
|
if (lcd.proto == LCD_PROTO_SERIAL) { /* SERIAL */
|
2008-11-22 10:29:33 +00:00
|
|
|
lcd_write_cmd = lcd_write_cmd_s;
|
|
|
|
lcd_write_data = lcd_write_data_s;
|
|
|
|
lcd_clear_fast = lcd_clear_fast_s;
|
|
|
|
|
2014-11-27 21:36:51 +00:00
|
|
|
if (lcd.pins.cl == PIN_NOT_SET)
|
|
|
|
lcd.pins.cl = DEFAULT_LCD_PIN_SCL;
|
|
|
|
if (lcd.pins.da == PIN_NOT_SET)
|
|
|
|
lcd.pins.da = DEFAULT_LCD_PIN_SDA;
|
2008-11-22 10:29:33 +00:00
|
|
|
|
2014-11-27 21:36:51 +00:00
|
|
|
} else if (lcd.proto == LCD_PROTO_PARALLEL) { /* PARALLEL */
|
2008-11-22 10:29:33 +00:00
|
|
|
lcd_write_cmd = lcd_write_cmd_p8;
|
|
|
|
lcd_write_data = lcd_write_data_p8;
|
|
|
|
lcd_clear_fast = lcd_clear_fast_p8;
|
|
|
|
|
2014-11-27 21:36:51 +00:00
|
|
|
if (lcd.pins.e == PIN_NOT_SET)
|
|
|
|
lcd.pins.e = DEFAULT_LCD_PIN_E;
|
|
|
|
if (lcd.pins.rs == PIN_NOT_SET)
|
|
|
|
lcd.pins.rs = DEFAULT_LCD_PIN_RS;
|
|
|
|
if (lcd.pins.rw == PIN_NOT_SET)
|
|
|
|
lcd.pins.rw = DEFAULT_LCD_PIN_RW;
|
2009-08-20 22:13:18 +00:00
|
|
|
} else {
|
|
|
|
lcd_write_cmd = lcd_write_cmd_tilcd;
|
|
|
|
lcd_write_data = lcd_write_data_tilcd;
|
|
|
|
lcd_clear_fast = lcd_clear_fast_tilcd;
|
2008-11-22 10:29:33 +00:00
|
|
|
}
|
2008-11-14 01:18:59 +00:00
|
|
|
|
2014-11-27 21:36:51 +00:00
|
|
|
if (lcd.pins.bl == PIN_NOT_SET)
|
|
|
|
lcd.pins.bl = DEFAULT_LCD_PIN_BL;
|
|
|
|
|
|
|
|
if (lcd.pins.e == PIN_NOT_SET)
|
|
|
|
lcd.pins.e = PIN_NONE;
|
|
|
|
if (lcd.pins.rs == PIN_NOT_SET)
|
|
|
|
lcd.pins.rs = PIN_NONE;
|
|
|
|
if (lcd.pins.rw == PIN_NOT_SET)
|
|
|
|
lcd.pins.rw = PIN_NONE;
|
|
|
|
if (lcd.pins.bl == PIN_NOT_SET)
|
|
|
|
lcd.pins.bl = PIN_NONE;
|
|
|
|
if (lcd.pins.cl == PIN_NOT_SET)
|
|
|
|
lcd.pins.cl = PIN_NONE;
|
|
|
|
if (lcd.pins.da == PIN_NOT_SET)
|
|
|
|
lcd.pins.da = PIN_NONE;
|
|
|
|
|
|
|
|
if (lcd.charset == NOT_SET)
|
|
|
|
lcd.charset = DEFAULT_LCD_CHARSET;
|
|
|
|
|
|
|
|
if (lcd.charset == LCD_CHARSET_KS0074)
|
2008-11-22 10:29:33 +00:00
|
|
|
lcd_char_conv = lcd_char_conv_ks0074;
|
|
|
|
else
|
|
|
|
lcd_char_conv = NULL;
|
|
|
|
|
2017-02-06 14:38:10 +00:00
|
|
|
if (lcd.pins.bl != PIN_NONE) {
|
|
|
|
mutex_init(&lcd.bl_tempo_lock);
|
|
|
|
INIT_DELAYED_WORK(&lcd.bl_work, lcd_bl_off);
|
|
|
|
}
|
2008-11-22 10:29:33 +00:00
|
|
|
|
2014-11-27 21:36:51 +00:00
|
|
|
pin_to_bits(lcd.pins.e, lcd_bits[LCD_PORT_D][LCD_BIT_E],
|
2008-11-22 10:29:33 +00:00
|
|
|
lcd_bits[LCD_PORT_C][LCD_BIT_E]);
|
2014-11-27 21:36:51 +00:00
|
|
|
pin_to_bits(lcd.pins.rs, lcd_bits[LCD_PORT_D][LCD_BIT_RS],
|
2008-11-22 10:29:33 +00:00
|
|
|
lcd_bits[LCD_PORT_C][LCD_BIT_RS]);
|
2014-11-27 21:36:51 +00:00
|
|
|
pin_to_bits(lcd.pins.rw, lcd_bits[LCD_PORT_D][LCD_BIT_RW],
|
2008-11-22 10:29:33 +00:00
|
|
|
lcd_bits[LCD_PORT_C][LCD_BIT_RW]);
|
2014-11-27 21:36:51 +00:00
|
|
|
pin_to_bits(lcd.pins.bl, lcd_bits[LCD_PORT_D][LCD_BIT_BL],
|
2008-11-22 10:29:33 +00:00
|
|
|
lcd_bits[LCD_PORT_C][LCD_BIT_BL]);
|
2014-11-27 21:36:51 +00:00
|
|
|
pin_to_bits(lcd.pins.cl, lcd_bits[LCD_PORT_D][LCD_BIT_CL],
|
2008-11-22 10:29:33 +00:00
|
|
|
lcd_bits[LCD_PORT_C][LCD_BIT_CL]);
|
2014-11-27 21:36:51 +00:00
|
|
|
pin_to_bits(lcd.pins.da, lcd_bits[LCD_PORT_D][LCD_BIT_DA],
|
2008-11-22 10:29:33 +00:00
|
|
|
lcd_bits[LCD_PORT_C][LCD_BIT_DA]);
|
|
|
|
|
2015-08-27 15:32:46 +00:00
|
|
|
/*
|
|
|
|
* before this line, we must NOT send anything to the display.
|
2008-11-22 10:29:33 +00:00
|
|
|
* Since lcd_init_display() needs to write data, we have to
|
2015-08-27 15:32:46 +00:00
|
|
|
* enable mark the LCD initialized just before.
|
|
|
|
*/
|
2014-11-27 21:36:53 +00:00
|
|
|
lcd.initialized = true;
|
2008-11-22 10:29:33 +00:00
|
|
|
lcd_init_display();
|
2008-11-14 01:18:59 +00:00
|
|
|
|
2008-11-22 10:29:33 +00:00
|
|
|
/* display a short message */
|
2008-11-14 01:18:59 +00:00
|
|
|
#ifdef CONFIG_PANEL_CHANGE_MESSAGE
|
|
|
|
#ifdef CONFIG_PANEL_BOOT_MESSAGE
|
2008-11-22 10:29:33 +00:00
|
|
|
panel_lcd_print("\x1b[Lc\x1b[Lb\x1b[L*" CONFIG_PANEL_BOOT_MESSAGE);
|
2008-11-14 01:18:59 +00:00
|
|
|
#endif
|
|
|
|
#else
|
2017-02-06 14:38:04 +00:00
|
|
|
panel_lcd_print("\x1b[Lc\x1b[Lb\x1b[L*Linux-" UTS_RELEASE);
|
2008-11-14 01:18:59 +00:00
|
|
|
#endif
|
2010-06-11 21:27:36 +00:00
|
|
|
/* clear the display on the next device opening */
|
2014-11-27 21:36:53 +00:00
|
|
|
lcd.must_clear = true;
|
2017-02-06 14:38:09 +00:00
|
|
|
lcd_home();
|
2008-11-14 01:18:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* These are the file operation function for user access to /dev/keypad
|
|
|
|
*/
|
|
|
|
|
2008-11-22 10:29:33 +00:00
|
|
|
static ssize_t keypad_read(struct file *file,
|
2014-04-18 16:10:08 +00:00
|
|
|
char __user *buf, size_t count, loff_t *ppos)
|
2008-11-22 10:29:33 +00:00
|
|
|
{
|
|
|
|
unsigned i = *ppos;
|
2014-04-18 16:10:08 +00:00
|
|
|
char __user *tmp = buf;
|
2008-11-14 01:18:59 +00:00
|
|
|
|
2008-11-22 10:29:33 +00:00
|
|
|
if (keypad_buflen == 0) {
|
|
|
|
if (file->f_flags & O_NONBLOCK)
|
|
|
|
return -EAGAIN;
|
2008-11-14 01:18:59 +00:00
|
|
|
|
2014-01-02 12:07:35 +00:00
|
|
|
if (wait_event_interruptible(keypad_read_wait,
|
|
|
|
keypad_buflen != 0))
|
2008-11-22 10:29:33 +00:00
|
|
|
return -EINTR;
|
|
|
|
}
|
2008-11-14 01:18:59 +00:00
|
|
|
|
2010-06-11 21:27:36 +00:00
|
|
|
for (; count-- > 0 && (keypad_buflen > 0);
|
|
|
|
++i, ++tmp, --keypad_buflen) {
|
2008-11-22 10:29:33 +00:00
|
|
|
put_user(keypad_buffer[keypad_start], tmp);
|
|
|
|
keypad_start = (keypad_start + 1) % KEYPAD_BUFFER;
|
|
|
|
}
|
|
|
|
*ppos = i;
|
2008-11-14 01:18:59 +00:00
|
|
|
|
2008-11-22 10:29:33 +00:00
|
|
|
return tmp - buf;
|
2008-11-14 01:18:59 +00:00
|
|
|
}
|
|
|
|
|
2008-11-22 10:29:33 +00:00
|
|
|
static int keypad_open(struct inode *inode, struct file *file)
|
|
|
|
{
|
2014-11-04 21:47:19 +00:00
|
|
|
if (!atomic_dec_and_test(&keypad_available))
|
2008-11-22 10:29:33 +00:00
|
|
|
return -EBUSY; /* open only once at a time */
|
2008-11-14 01:18:59 +00:00
|
|
|
|
2008-11-22 10:29:33 +00:00
|
|
|
if (file->f_mode & FMODE_WRITE) /* device is read-only */
|
|
|
|
return -EPERM;
|
2008-11-14 01:18:59 +00:00
|
|
|
|
2008-11-22 10:29:33 +00:00
|
|
|
keypad_buflen = 0; /* flush the buffer on opening */
|
|
|
|
return 0;
|
2008-11-14 01:18:59 +00:00
|
|
|
}
|
|
|
|
|
2008-11-22 10:29:33 +00:00
|
|
|
static int keypad_release(struct inode *inode, struct file *file)
|
|
|
|
{
|
2014-11-04 21:47:19 +00:00
|
|
|
atomic_inc(&keypad_available);
|
2008-11-22 10:29:33 +00:00
|
|
|
return 0;
|
2008-11-14 01:18:59 +00:00
|
|
|
}
|
|
|
|
|
2010-06-11 21:27:36 +00:00
|
|
|
static const struct file_operations keypad_fops = {
|
2008-11-22 10:29:33 +00:00
|
|
|
.read = keypad_read, /* read */
|
|
|
|
.open = keypad_open, /* open */
|
|
|
|
.release = keypad_release, /* close */
|
llseek: automatically add .llseek fop
All file_operations should get a .llseek operation so we can make
nonseekable_open the default for future file operations without a
.llseek pointer.
The three cases that we can automatically detect are no_llseek, seq_lseek
and default_llseek. For cases where we can we can automatically prove that
the file offset is always ignored, we use noop_llseek, which maintains
the current behavior of not returning an error from a seek.
New drivers should normally not use noop_llseek but instead use no_llseek
and call nonseekable_open at open time. Existing drivers can be converted
to do the same when the maintainer knows for certain that no user code
relies on calling seek on the device file.
The generated code is often incorrectly indented and right now contains
comments that clarify for each added line why a specific variant was
chosen. In the version that gets submitted upstream, the comments will
be gone and I will manually fix the indentation, because there does not
seem to be a way to do that using coccinelle.
Some amount of new code is currently sitting in linux-next that should get
the same modifications, which I will do at the end of the merge window.
Many thanks to Julia Lawall for helping me learn to write a semantic
patch that does all this.
===== begin semantic patch =====
// This adds an llseek= method to all file operations,
// as a preparation for making no_llseek the default.
//
// The rules are
// - use no_llseek explicitly if we do nonseekable_open
// - use seq_lseek for sequential files
// - use default_llseek if we know we access f_pos
// - use noop_llseek if we know we don't access f_pos,
// but we still want to allow users to call lseek
//
@ open1 exists @
identifier nested_open;
@@
nested_open(...)
{
<+...
nonseekable_open(...)
...+>
}
@ open exists@
identifier open_f;
identifier i, f;
identifier open1.nested_open;
@@
int open_f(struct inode *i, struct file *f)
{
<+...
(
nonseekable_open(...)
|
nested_open(...)
)
...+>
}
@ read disable optional_qualifier exists @
identifier read_f;
identifier f, p, s, off;
type ssize_t, size_t, loff_t;
expression E;
identifier func;
@@
ssize_t read_f(struct file *f, char *p, size_t s, loff_t *off)
{
<+...
(
*off = E
|
*off += E
|
func(..., off, ...)
|
E = *off
)
...+>
}
@ read_no_fpos disable optional_qualifier exists @
identifier read_f;
identifier f, p, s, off;
type ssize_t, size_t, loff_t;
@@
ssize_t read_f(struct file *f, char *p, size_t s, loff_t *off)
{
... when != off
}
@ write @
identifier write_f;
identifier f, p, s, off;
type ssize_t, size_t, loff_t;
expression E;
identifier func;
@@
ssize_t write_f(struct file *f, const char *p, size_t s, loff_t *off)
{
<+...
(
*off = E
|
*off += E
|
func(..., off, ...)
|
E = *off
)
...+>
}
@ write_no_fpos @
identifier write_f;
identifier f, p, s, off;
type ssize_t, size_t, loff_t;
@@
ssize_t write_f(struct file *f, const char *p, size_t s, loff_t *off)
{
... when != off
}
@ fops0 @
identifier fops;
@@
struct file_operations fops = {
...
};
@ has_llseek depends on fops0 @
identifier fops0.fops;
identifier llseek_f;
@@
struct file_operations fops = {
...
.llseek = llseek_f,
...
};
@ has_read depends on fops0 @
identifier fops0.fops;
identifier read_f;
@@
struct file_operations fops = {
...
.read = read_f,
...
};
@ has_write depends on fops0 @
identifier fops0.fops;
identifier write_f;
@@
struct file_operations fops = {
...
.write = write_f,
...
};
@ has_open depends on fops0 @
identifier fops0.fops;
identifier open_f;
@@
struct file_operations fops = {
...
.open = open_f,
...
};
// use no_llseek if we call nonseekable_open
////////////////////////////////////////////
@ nonseekable1 depends on !has_llseek && has_open @
identifier fops0.fops;
identifier nso ~= "nonseekable_open";
@@
struct file_operations fops = {
... .open = nso, ...
+.llseek = no_llseek, /* nonseekable */
};
@ nonseekable2 depends on !has_llseek @
identifier fops0.fops;
identifier open.open_f;
@@
struct file_operations fops = {
... .open = open_f, ...
+.llseek = no_llseek, /* open uses nonseekable */
};
// use seq_lseek for sequential files
/////////////////////////////////////
@ seq depends on !has_llseek @
identifier fops0.fops;
identifier sr ~= "seq_read";
@@
struct file_operations fops = {
... .read = sr, ...
+.llseek = seq_lseek, /* we have seq_read */
};
// use default_llseek if there is a readdir
///////////////////////////////////////////
@ fops1 depends on !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
identifier readdir_e;
@@
// any other fop is used that changes pos
struct file_operations fops = {
... .readdir = readdir_e, ...
+.llseek = default_llseek, /* readdir is present */
};
// use default_llseek if at least one of read/write touches f_pos
/////////////////////////////////////////////////////////////////
@ fops2 depends on !fops1 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
identifier read.read_f;
@@
// read fops use offset
struct file_operations fops = {
... .read = read_f, ...
+.llseek = default_llseek, /* read accesses f_pos */
};
@ fops3 depends on !fops1 && !fops2 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
identifier write.write_f;
@@
// write fops use offset
struct file_operations fops = {
... .write = write_f, ...
+ .llseek = default_llseek, /* write accesses f_pos */
};
// Use noop_llseek if neither read nor write accesses f_pos
///////////////////////////////////////////////////////////
@ fops4 depends on !fops1 && !fops2 && !fops3 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
identifier read_no_fpos.read_f;
identifier write_no_fpos.write_f;
@@
// write fops use offset
struct file_operations fops = {
...
.write = write_f,
.read = read_f,
...
+.llseek = noop_llseek, /* read and write both use no f_pos */
};
@ depends on has_write && !has_read && !fops1 && !fops2 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
identifier write_no_fpos.write_f;
@@
struct file_operations fops = {
... .write = write_f, ...
+.llseek = noop_llseek, /* write uses no f_pos */
};
@ depends on has_read && !has_write && !fops1 && !fops2 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
identifier read_no_fpos.read_f;
@@
struct file_operations fops = {
... .read = read_f, ...
+.llseek = noop_llseek, /* read uses no f_pos */
};
@ depends on !has_read && !has_write && !fops1 && !fops2 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
@@
struct file_operations fops = {
...
+.llseek = noop_llseek, /* no read or write fn */
};
===== End semantic patch =====
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Cc: Julia Lawall <julia@diku.dk>
Cc: Christoph Hellwig <hch@infradead.org>
2010-08-15 16:52:59 +00:00
|
|
|
.llseek = default_llseek,
|
2008-11-14 01:18:59 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static struct miscdevice keypad_dev = {
|
2014-10-29 22:32:30 +00:00
|
|
|
.minor = KEYPAD_MINOR,
|
|
|
|
.name = "keypad",
|
|
|
|
.fops = &keypad_fops,
|
2008-11-14 01:18:59 +00:00
|
|
|
};
|
|
|
|
|
2013-02-15 12:47:05 +00:00
|
|
|
static void keypad_send_key(const char *string, int max_len)
|
2008-11-22 10:29:33 +00:00
|
|
|
{
|
|
|
|
/* send the key to the device only if a process is attached to it. */
|
2014-11-04 21:47:19 +00:00
|
|
|
if (!atomic_read(&keypad_available)) {
|
2008-11-22 10:29:33 +00:00
|
|
|
while (max_len-- && keypad_buflen < KEYPAD_BUFFER && *string) {
|
|
|
|
keypad_buffer[(keypad_start + keypad_buflen++) %
|
|
|
|
KEYPAD_BUFFER] = *string++;
|
|
|
|
}
|
|
|
|
wake_up_interruptible(&keypad_read_wait);
|
2008-11-14 01:18:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-06-11 21:27:36 +00:00
|
|
|
/* this function scans all the bits involving at least one logical signal,
|
|
|
|
* and puts the results in the bitfield "phys_read" (one bit per established
|
|
|
|
* contact), and sets "phys_read_prev" to "phys_read".
|
2008-11-14 01:18:59 +00:00
|
|
|
*
|
2010-06-11 21:27:36 +00:00
|
|
|
* Note: to debounce input signals, we will only consider as switched a signal
|
|
|
|
* which is stable across 2 measures. Signals which are different between two
|
|
|
|
* reads will be kept as they previously were in their logical form (phys_prev).
|
|
|
|
* A signal which has just switched will have a 1 in
|
|
|
|
* (phys_read ^ phys_read_prev).
|
2008-11-14 01:18:59 +00:00
|
|
|
*/
|
2008-11-22 10:29:33 +00:00
|
|
|
static void phys_scan_contacts(void)
|
|
|
|
{
|
|
|
|
int bit, bitval;
|
|
|
|
char oldval;
|
|
|
|
char bitmask;
|
|
|
|
char gndmask;
|
|
|
|
|
|
|
|
phys_prev = phys_curr;
|
|
|
|
phys_read_prev = phys_read;
|
|
|
|
phys_read = 0; /* flush all signals */
|
|
|
|
|
2010-06-11 21:27:36 +00:00
|
|
|
/* keep track of old value, with all outputs disabled */
|
|
|
|
oldval = r_dtr(pprt) | scan_mask_o;
|
|
|
|
/* activate all keyboard outputs (active low) */
|
|
|
|
w_dtr(pprt, oldval & ~scan_mask_o);
|
|
|
|
|
|
|
|
/* will have a 1 for each bit set to gnd */
|
|
|
|
bitmask = PNL_PINPUT(r_str(pprt)) & scan_mask_i;
|
|
|
|
/* disable all matrix signals */
|
|
|
|
w_dtr(pprt, oldval);
|
2008-11-22 10:29:33 +00:00
|
|
|
|
|
|
|
/* now that all outputs are cleared, the only active input bits are
|
|
|
|
* directly connected to the ground
|
2008-11-14 01:18:59 +00:00
|
|
|
*/
|
2008-11-22 10:29:33 +00:00
|
|
|
|
2010-06-11 21:27:36 +00:00
|
|
|
/* 1 for each grounded input */
|
|
|
|
gndmask = PNL_PINPUT(r_str(pprt)) & scan_mask_i;
|
|
|
|
|
|
|
|
/* grounded inputs are signals 40-44 */
|
2016-01-03 19:40:58 +00:00
|
|
|
phys_read |= (__u64)gndmask << 40;
|
2008-11-14 01:18:59 +00:00
|
|
|
|
2008-11-22 10:29:33 +00:00
|
|
|
if (bitmask != gndmask) {
|
2015-08-27 15:32:46 +00:00
|
|
|
/*
|
|
|
|
* since clearing the outputs changed some inputs, we know
|
2010-06-11 21:27:36 +00:00
|
|
|
* that some input signals are currently tied to some outputs.
|
|
|
|
* So we'll scan them.
|
2008-11-22 10:29:33 +00:00
|
|
|
*/
|
|
|
|
for (bit = 0; bit < 8; bit++) {
|
2015-10-16 16:41:36 +00:00
|
|
|
bitval = BIT(bit);
|
2008-11-14 01:18:59 +00:00
|
|
|
|
2008-11-22 10:29:33 +00:00
|
|
|
if (!(scan_mask_o & bitval)) /* skip unused bits */
|
|
|
|
continue;
|
|
|
|
|
|
|
|
w_dtr(pprt, oldval & ~bitval); /* enable this output */
|
|
|
|
bitmask = PNL_PINPUT(r_str(pprt)) & ~gndmask;
|
2016-01-03 19:40:58 +00:00
|
|
|
phys_read |= (__u64)bitmask << (5 * bit);
|
2008-11-22 10:29:33 +00:00
|
|
|
}
|
|
|
|
w_dtr(pprt, oldval); /* disable all outputs */
|
2008-11-14 01:18:59 +00:00
|
|
|
}
|
2015-08-27 15:32:46 +00:00
|
|
|
/*
|
|
|
|
* this is easy: use old bits when they are flapping,
|
|
|
|
* use new ones when stable
|
|
|
|
*/
|
2010-06-11 21:27:36 +00:00
|
|
|
phys_curr = (phys_prev & (phys_read ^ phys_read_prev)) |
|
|
|
|
(phys_read & ~(phys_read ^ phys_read_prev));
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int input_state_high(struct logical_input *input)
|
|
|
|
{
|
|
|
|
#if 0
|
|
|
|
/* FIXME:
|
|
|
|
* this is an invalid test. It tries to catch
|
|
|
|
* transitions from single-key to multiple-key, but
|
|
|
|
* doesn't take into account the contacts polarity.
|
|
|
|
* The only solution to the problem is to parse keys
|
|
|
|
* from the most complex to the simplest combinations,
|
|
|
|
* and mark them as 'caught' once a combination
|
|
|
|
* matches, then unmatch it for all other ones.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* try to catch dangerous transitions cases :
|
|
|
|
* someone adds a bit, so this signal was a false
|
|
|
|
* positive resulting from a transition. We should
|
|
|
|
* invalidate the signal immediately and not call the
|
|
|
|
* release function.
|
|
|
|
* eg: 0 -(press A)-> A -(press B)-> AB : don't match A's release.
|
|
|
|
*/
|
2014-05-21 12:10:00 +00:00
|
|
|
if (((phys_prev & input->mask) == input->value) &&
|
|
|
|
((phys_curr & input->mask) > input->value)) {
|
2010-06-11 21:27:36 +00:00
|
|
|
input->state = INPUT_ST_LOW; /* invalidate */
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if ((phys_curr & input->mask) == input->value) {
|
|
|
|
if ((input->type == INPUT_TYPE_STD) &&
|
|
|
|
(input->high_timer == 0)) {
|
|
|
|
input->high_timer++;
|
2015-10-03 11:52:09 +00:00
|
|
|
if (input->u.std.press_fct)
|
2010-06-11 21:27:36 +00:00
|
|
|
input->u.std.press_fct(input->u.std.press_data);
|
|
|
|
} else if (input->type == INPUT_TYPE_KBD) {
|
|
|
|
/* will turn on the light */
|
|
|
|
keypressed = 1;
|
|
|
|
|
|
|
|
if (input->high_timer == 0) {
|
|
|
|
char *press_str = input->u.kbd.press_str;
|
2014-04-04 19:45:07 +00:00
|
|
|
|
2013-05-04 15:21:17 +00:00
|
|
|
if (press_str[0]) {
|
|
|
|
int s = sizeof(input->u.kbd.press_str);
|
2014-04-04 19:45:07 +00:00
|
|
|
|
2013-05-04 15:21:17 +00:00
|
|
|
keypad_send_key(press_str, s);
|
|
|
|
}
|
2010-06-11 21:27:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (input->u.kbd.repeat_str[0]) {
|
|
|
|
char *repeat_str = input->u.kbd.repeat_str;
|
2014-04-04 19:45:07 +00:00
|
|
|
|
2010-06-11 21:27:36 +00:00
|
|
|
if (input->high_timer >= KEYPAD_REP_START) {
|
2013-05-04 15:21:17 +00:00
|
|
|
int s = sizeof(input->u.kbd.repeat_str);
|
2014-04-04 19:45:07 +00:00
|
|
|
|
2010-06-11 21:27:36 +00:00
|
|
|
input->high_timer -= KEYPAD_REP_DELAY;
|
2013-05-04 15:21:17 +00:00
|
|
|
keypad_send_key(repeat_str, s);
|
2010-06-11 21:27:36 +00:00
|
|
|
}
|
|
|
|
/* we will need to come back here soon */
|
|
|
|
inputs_stable = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (input->high_timer < 255)
|
|
|
|
input->high_timer++;
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
2014-07-10 10:34:28 +00:00
|
|
|
|
|
|
|
/* else signal falling down. Let's fall through. */
|
|
|
|
input->state = INPUT_ST_FALLING;
|
|
|
|
input->fall_timer = 0;
|
|
|
|
|
2010-06-11 21:27:36 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void input_state_falling(struct logical_input *input)
|
|
|
|
{
|
|
|
|
#if 0
|
|
|
|
/* FIXME !!! same comment as in input_state_high */
|
2014-05-21 12:10:00 +00:00
|
|
|
if (((phys_prev & input->mask) == input->value) &&
|
|
|
|
((phys_curr & input->mask) > input->value)) {
|
2010-06-11 21:27:36 +00:00
|
|
|
input->state = INPUT_ST_LOW; /* invalidate */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if ((phys_curr & input->mask) == input->value) {
|
|
|
|
if (input->type == INPUT_TYPE_KBD) {
|
|
|
|
/* will turn on the light */
|
|
|
|
keypressed = 1;
|
|
|
|
|
|
|
|
if (input->u.kbd.repeat_str[0]) {
|
|
|
|
char *repeat_str = input->u.kbd.repeat_str;
|
2014-04-04 19:45:07 +00:00
|
|
|
|
2013-05-04 15:21:17 +00:00
|
|
|
if (input->high_timer >= KEYPAD_REP_START) {
|
|
|
|
int s = sizeof(input->u.kbd.repeat_str);
|
2014-04-04 19:45:07 +00:00
|
|
|
|
2010-06-11 21:27:36 +00:00
|
|
|
input->high_timer -= KEYPAD_REP_DELAY;
|
2013-05-04 15:21:17 +00:00
|
|
|
keypad_send_key(repeat_str, s);
|
|
|
|
}
|
2010-06-11 21:27:36 +00:00
|
|
|
/* we will need to come back here soon */
|
|
|
|
inputs_stable = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (input->high_timer < 255)
|
|
|
|
input->high_timer++;
|
|
|
|
}
|
|
|
|
input->state = INPUT_ST_HIGH;
|
|
|
|
} else if (input->fall_timer >= input->fall_time) {
|
|
|
|
/* call release event */
|
|
|
|
if (input->type == INPUT_TYPE_STD) {
|
|
|
|
void (*release_fct)(int) = input->u.std.release_fct;
|
2014-04-04 19:45:07 +00:00
|
|
|
|
2015-10-03 11:52:09 +00:00
|
|
|
if (release_fct)
|
2010-06-11 21:27:36 +00:00
|
|
|
release_fct(input->u.std.release_data);
|
|
|
|
} else if (input->type == INPUT_TYPE_KBD) {
|
|
|
|
char *release_str = input->u.kbd.release_str;
|
2014-04-04 19:45:07 +00:00
|
|
|
|
2013-05-04 15:21:17 +00:00
|
|
|
if (release_str[0]) {
|
|
|
|
int s = sizeof(input->u.kbd.release_str);
|
2014-04-04 19:45:07 +00:00
|
|
|
|
2013-05-04 15:21:17 +00:00
|
|
|
keypad_send_key(release_str, s);
|
|
|
|
}
|
2010-06-11 21:27:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
input->state = INPUT_ST_LOW;
|
|
|
|
} else {
|
|
|
|
input->fall_timer++;
|
|
|
|
inputs_stable = 0;
|
|
|
|
}
|
2008-11-14 01:18:59 +00:00
|
|
|
}
|
|
|
|
|
2008-11-22 10:29:33 +00:00
|
|
|
static void panel_process_inputs(void)
|
|
|
|
{
|
|
|
|
struct list_head *item;
|
|
|
|
struct logical_input *input;
|
2008-11-14 01:18:59 +00:00
|
|
|
|
2008-11-22 10:29:33 +00:00
|
|
|
keypressed = 0;
|
|
|
|
inputs_stable = 1;
|
|
|
|
list_for_each(item, &logical_inputs) {
|
|
|
|
input = list_entry(item, struct logical_input, list);
|
|
|
|
|
|
|
|
switch (input->state) {
|
|
|
|
case INPUT_ST_LOW:
|
|
|
|
if ((phys_curr & input->mask) != input->value)
|
|
|
|
break;
|
2010-06-11 21:27:36 +00:00
|
|
|
/* if all needed ones were already set previously,
|
|
|
|
* this means that this logical signal has been
|
|
|
|
* activated by the releasing of another combined
|
|
|
|
* signal, so we don't want to match.
|
|
|
|
* eg: AB -(release B)-> A -(release A)-> 0 :
|
|
|
|
* don't match A.
|
2008-11-22 10:29:33 +00:00
|
|
|
*/
|
|
|
|
if ((phys_prev & input->mask) == input->value)
|
|
|
|
break;
|
|
|
|
input->rise_timer = 0;
|
|
|
|
input->state = INPUT_ST_RISING;
|
|
|
|
/* no break here, fall through */
|
|
|
|
case INPUT_ST_RISING:
|
|
|
|
if ((phys_curr & input->mask) != input->value) {
|
|
|
|
input->state = INPUT_ST_LOW;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (input->rise_timer < input->rise_time) {
|
|
|
|
inputs_stable = 0;
|
|
|
|
input->rise_timer++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
input->high_timer = 0;
|
|
|
|
input->state = INPUT_ST_HIGH;
|
|
|
|
/* no break here, fall through */
|
|
|
|
case INPUT_ST_HIGH:
|
2010-06-11 21:27:36 +00:00
|
|
|
if (input_state_high(input))
|
2008-11-22 10:29:33 +00:00
|
|
|
break;
|
|
|
|
/* no break here, fall through */
|
|
|
|
case INPUT_ST_FALLING:
|
2010-06-11 21:27:36 +00:00
|
|
|
input_state_falling(input);
|
2008-11-22 10:29:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-11-14 01:18:59 +00:00
|
|
|
|
2008-11-22 10:29:33 +00:00
|
|
|
static void panel_scan_timer(void)
|
|
|
|
{
|
2014-11-27 21:36:49 +00:00
|
|
|
if (keypad.enabled && keypad_initialized) {
|
2012-09-09 08:23:46 +00:00
|
|
|
if (spin_trylock_irq(&pprt_lock)) {
|
2008-11-22 10:29:33 +00:00
|
|
|
phys_scan_contacts();
|
2010-06-11 21:27:36 +00:00
|
|
|
|
|
|
|
/* no need for the parport anymore */
|
2012-09-09 08:23:46 +00:00
|
|
|
spin_unlock_irq(&pprt_lock);
|
2008-11-14 01:18:59 +00:00
|
|
|
}
|
|
|
|
|
2008-11-22 10:29:33 +00:00
|
|
|
if (!inputs_stable || phys_curr != phys_prev)
|
|
|
|
panel_process_inputs();
|
2008-11-14 01:18:59 +00:00
|
|
|
}
|
|
|
|
|
2017-02-06 14:38:10 +00:00
|
|
|
if (keypressed && lcd.enabled && lcd.initialized)
|
|
|
|
lcd_poke();
|
2008-11-22 10:29:33 +00:00
|
|
|
|
|
|
|
mod_timer(&scan_timer, jiffies + INPUT_POLL_TIME);
|
2008-11-14 01:18:59 +00:00
|
|
|
}
|
|
|
|
|
2008-11-22 10:29:33 +00:00
|
|
|
static void init_scan_timer(void)
|
|
|
|
{
|
2015-10-03 11:52:09 +00:00
|
|
|
if (scan_timer.function)
|
2008-11-22 10:29:33 +00:00
|
|
|
return; /* already started */
|
|
|
|
|
2015-02-19 05:58:29 +00:00
|
|
|
setup_timer(&scan_timer, (void *)&panel_scan_timer, 0);
|
2008-11-22 10:29:33 +00:00
|
|
|
scan_timer.expires = jiffies + INPUT_POLL_TIME;
|
|
|
|
add_timer(&scan_timer);
|
2008-11-14 01:18:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* converts a name of the form "({BbAaPpSsEe}{01234567-})*" to a series of bits.
|
2010-06-11 21:27:36 +00:00
|
|
|
* if <omask> or <imask> are non-null, they will be or'ed with the bits
|
|
|
|
* corresponding to out and in bits respectively.
|
2008-11-14 01:18:59 +00:00
|
|
|
* returns 1 if ok, 0 if error (in which case, nothing is written).
|
|
|
|
*/
|
2016-01-03 19:40:58 +00:00
|
|
|
static u8 input_name2mask(const char *name, __u64 *mask, __u64 *value,
|
2016-01-03 19:39:49 +00:00
|
|
|
u8 *imask, u8 *omask)
|
2008-11-22 10:29:33 +00:00
|
|
|
{
|
2016-01-03 19:44:44 +00:00
|
|
|
const char sigtab[] = "EeSsPpAaBb";
|
2016-01-03 19:39:49 +00:00
|
|
|
u8 im, om;
|
2016-01-03 19:40:58 +00:00
|
|
|
__u64 m, v;
|
2008-11-22 10:29:33 +00:00
|
|
|
|
2016-01-03 19:42:26 +00:00
|
|
|
om = 0;
|
|
|
|
im = 0;
|
2014-05-23 23:35:24 +00:00
|
|
|
m = 0ULL;
|
|
|
|
v = 0ULL;
|
2008-11-22 10:29:33 +00:00
|
|
|
while (*name) {
|
|
|
|
int in, out, bit, neg;
|
2016-01-03 19:44:44 +00:00
|
|
|
const char *idx;
|
2014-04-04 19:45:07 +00:00
|
|
|
|
2016-01-03 19:44:44 +00:00
|
|
|
idx = strchr(sigtab, *name);
|
|
|
|
if (!idx)
|
2008-11-22 10:29:33 +00:00
|
|
|
return 0; /* input name not found */
|
2016-01-03 19:44:44 +00:00
|
|
|
|
|
|
|
in = idx - sigtab;
|
2008-11-22 10:29:33 +00:00
|
|
|
neg = (in & 1); /* odd (lower) names are negated */
|
|
|
|
in >>= 1;
|
2015-10-16 16:41:36 +00:00
|
|
|
im |= BIT(in);
|
2008-11-22 10:29:33 +00:00
|
|
|
|
|
|
|
name++;
|
2016-01-03 19:43:27 +00:00
|
|
|
if (*name >= '0' && *name <= '7') {
|
2008-11-22 10:29:33 +00:00
|
|
|
out = *name - '0';
|
2015-10-16 16:41:36 +00:00
|
|
|
om |= BIT(out);
|
2014-05-21 12:09:59 +00:00
|
|
|
} else if (*name == '-') {
|
2008-11-22 10:29:33 +00:00
|
|
|
out = 8;
|
2014-05-21 12:09:59 +00:00
|
|
|
} else {
|
2008-11-22 10:29:33 +00:00
|
|
|
return 0; /* unknown bit name */
|
2014-05-21 12:09:59 +00:00
|
|
|
}
|
2008-11-22 10:29:33 +00:00
|
|
|
|
|
|
|
bit = (out * 5) + in;
|
|
|
|
|
|
|
|
m |= 1ULL << bit;
|
|
|
|
if (!neg)
|
|
|
|
v |= 1ULL << bit;
|
|
|
|
name++;
|
2008-11-14 01:18:59 +00:00
|
|
|
}
|
2008-11-22 10:29:33 +00:00
|
|
|
*mask = m;
|
|
|
|
*value = v;
|
|
|
|
if (imask)
|
|
|
|
*imask |= im;
|
|
|
|
if (omask)
|
|
|
|
*omask |= om;
|
|
|
|
return 1;
|
2008-11-14 01:18:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* tries to bind a key to the signal name <name>. The key will send the
|
|
|
|
* strings <press>, <repeat>, <release> for these respective events.
|
|
|
|
* Returns the pointer to the new key if ok, NULL if the key could not be bound.
|
|
|
|
*/
|
2013-02-15 12:47:05 +00:00
|
|
|
static struct logical_input *panel_bind_key(const char *name, const char *press,
|
|
|
|
const char *repeat,
|
|
|
|
const char *release)
|
2008-11-22 10:29:33 +00:00
|
|
|
{
|
|
|
|
struct logical_input *key;
|
|
|
|
|
2014-05-21 12:10:00 +00:00
|
|
|
key = kzalloc(sizeof(*key), GFP_KERNEL);
|
2012-07-12 13:01:17 +00:00
|
|
|
if (!key)
|
2008-11-22 10:29:33 +00:00
|
|
|
return NULL;
|
2012-07-12 13:01:17 +00:00
|
|
|
|
2008-11-22 10:29:33 +00:00
|
|
|
if (!input_name2mask(name, &key->mask, &key->value, &scan_mask_i,
|
2010-07-12 14:48:24 +00:00
|
|
|
&scan_mask_o)) {
|
|
|
|
kfree(key);
|
2008-11-22 10:29:33 +00:00
|
|
|
return NULL;
|
2010-07-12 14:48:24 +00:00
|
|
|
}
|
2008-11-22 10:29:33 +00:00
|
|
|
|
|
|
|
key->type = INPUT_TYPE_KBD;
|
|
|
|
key->state = INPUT_ST_LOW;
|
|
|
|
key->rise_time = 1;
|
|
|
|
key->fall_time = 1;
|
2008-11-14 01:18:59 +00:00
|
|
|
|
2008-11-22 10:29:33 +00:00
|
|
|
strncpy(key->u.kbd.press_str, press, sizeof(key->u.kbd.press_str));
|
|
|
|
strncpy(key->u.kbd.repeat_str, repeat, sizeof(key->u.kbd.repeat_str));
|
|
|
|
strncpy(key->u.kbd.release_str, release,
|
|
|
|
sizeof(key->u.kbd.release_str));
|
|
|
|
list_add(&key->list, &logical_inputs);
|
|
|
|
return key;
|
2008-11-14 01:18:59 +00:00
|
|
|
}
|
|
|
|
|
2008-11-22 11:52:18 +00:00
|
|
|
#if 0
|
2008-11-14 01:18:59 +00:00
|
|
|
/* tries to bind a callback function to the signal name <name>. The function
|
|
|
|
* <press_fct> will be called with the <press_data> arg when the signal is
|
|
|
|
* activated, and so on for <release_fct>/<release_data>
|
2010-06-11 21:27:36 +00:00
|
|
|
* Returns the pointer to the new signal if ok, NULL if the signal could not
|
|
|
|
* be bound.
|
2008-11-14 01:18:59 +00:00
|
|
|
*/
|
|
|
|
static struct logical_input *panel_bind_callback(char *name,
|
2014-02-25 14:10:49 +00:00
|
|
|
void (*press_fct)(int),
|
2008-11-22 10:29:33 +00:00
|
|
|
int press_data,
|
2014-02-25 14:10:49 +00:00
|
|
|
void (*release_fct)(int),
|
2008-11-22 10:29:33 +00:00
|
|
|
int release_data)
|
|
|
|
{
|
|
|
|
struct logical_input *callback;
|
|
|
|
|
2014-05-21 12:10:00 +00:00
|
|
|
callback = kmalloc(sizeof(*callback), GFP_KERNEL);
|
2012-07-12 13:01:17 +00:00
|
|
|
if (!callback)
|
2008-11-22 10:29:33 +00:00
|
|
|
return NULL;
|
2012-07-12 13:01:17 +00:00
|
|
|
|
2008-11-22 10:29:33 +00:00
|
|
|
memset(callback, 0, sizeof(struct logical_input));
|
|
|
|
if (!input_name2mask(name, &callback->mask, &callback->value,
|
|
|
|
&scan_mask_i, &scan_mask_o))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
callback->type = INPUT_TYPE_STD;
|
|
|
|
callback->state = INPUT_ST_LOW;
|
|
|
|
callback->rise_time = 1;
|
|
|
|
callback->fall_time = 1;
|
|
|
|
callback->u.std.press_fct = press_fct;
|
|
|
|
callback->u.std.press_data = press_data;
|
|
|
|
callback->u.std.release_fct = release_fct;
|
|
|
|
callback->u.std.release_data = release_data;
|
|
|
|
list_add(&callback->list, &logical_inputs);
|
|
|
|
return callback;
|
2008-11-14 01:18:59 +00:00
|
|
|
}
|
2008-11-22 11:52:18 +00:00
|
|
|
#endif
|
2008-11-14 01:18:59 +00:00
|
|
|
|
2008-11-22 10:29:33 +00:00
|
|
|
static void keypad_init(void)
|
|
|
|
{
|
|
|
|
int keynum;
|
2014-04-04 19:45:07 +00:00
|
|
|
|
2008-11-22 10:29:33 +00:00
|
|
|
init_waitqueue_head(&keypad_read_wait);
|
|
|
|
keypad_buflen = 0; /* flushes any eventual noisy keystroke */
|
2008-11-14 01:18:59 +00:00
|
|
|
|
2008-11-22 10:29:33 +00:00
|
|
|
/* Let's create all known keys */
|
2008-11-14 01:18:59 +00:00
|
|
|
|
2008-11-22 10:29:33 +00:00
|
|
|
for (keynum = 0; keypad_profile[keynum][0][0]; keynum++) {
|
|
|
|
panel_bind_key(keypad_profile[keynum][0],
|
|
|
|
keypad_profile[keynum][1],
|
|
|
|
keypad_profile[keynum][2],
|
|
|
|
keypad_profile[keynum][3]);
|
|
|
|
}
|
2008-11-14 01:18:59 +00:00
|
|
|
|
2008-11-22 10:29:33 +00:00
|
|
|
init_scan_timer();
|
|
|
|
keypad_initialized = 1;
|
2008-11-14 01:18:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************/
|
|
|
|
/* device initialization */
|
|
|
|
/**************************************************/
|
|
|
|
|
2008-11-22 10:29:33 +00:00
|
|
|
static int panel_notify_sys(struct notifier_block *this, unsigned long code,
|
|
|
|
void *unused)
|
|
|
|
{
|
2014-11-27 21:36:53 +00:00
|
|
|
if (lcd.enabled && lcd.initialized) {
|
2008-11-22 10:29:33 +00:00
|
|
|
switch (code) {
|
|
|
|
case SYS_DOWN:
|
|
|
|
panel_lcd_print
|
|
|
|
("\x0cReloading\nSystem...\x1b[Lc\x1b[Lb\x1b[L+");
|
|
|
|
break;
|
|
|
|
case SYS_HALT:
|
|
|
|
panel_lcd_print
|
|
|
|
("\x0cSystem Halted.\x1b[Lc\x1b[Lb\x1b[L+");
|
|
|
|
break;
|
|
|
|
case SYS_POWER_OFF:
|
|
|
|
panel_lcd_print("\x0cPower off.\x1b[Lc\x1b[Lb\x1b[L+");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2008-11-14 01:18:59 +00:00
|
|
|
}
|
2008-11-22 10:29:33 +00:00
|
|
|
return NOTIFY_DONE;
|
2008-11-14 01:18:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static struct notifier_block panel_notifier = {
|
|
|
|
panel_notify_sys,
|
|
|
|
NULL,
|
|
|
|
0
|
|
|
|
};
|
|
|
|
|
2008-11-22 10:29:33 +00:00
|
|
|
static void panel_attach(struct parport *port)
|
2008-11-14 01:18:59 +00:00
|
|
|
{
|
2015-05-20 15:26:58 +00:00
|
|
|
struct pardev_cb panel_cb;
|
|
|
|
|
2008-11-22 10:29:33 +00:00
|
|
|
if (port->number != parport)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (pprt) {
|
2012-07-12 13:01:17 +00:00
|
|
|
pr_err("%s: port->number=%d parport=%d, already registered!\n",
|
|
|
|
__func__, port->number, parport);
|
2008-11-22 10:29:33 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-05-20 15:26:58 +00:00
|
|
|
memset(&panel_cb, 0, sizeof(panel_cb));
|
|
|
|
panel_cb.private = &pprt;
|
|
|
|
/* panel_cb.flags = 0 should be PARPORT_DEV_EXCL? */
|
|
|
|
|
|
|
|
pprt = parport_register_dev_model(port, "panel", &panel_cb, 0);
|
2015-10-03 11:52:09 +00:00
|
|
|
if (!pprt) {
|
2012-07-12 13:01:17 +00:00
|
|
|
pr_err("%s: port->number=%d parport=%d, parport_register_device() failed\n",
|
|
|
|
__func__, port->number, parport);
|
2010-07-30 11:08:20 +00:00
|
|
|
return;
|
|
|
|
}
|
2008-11-22 10:29:33 +00:00
|
|
|
|
|
|
|
if (parport_claim(pprt)) {
|
2012-07-12 13:01:17 +00:00
|
|
|
pr_err("could not claim access to parport%d. Aborting.\n",
|
|
|
|
parport);
|
2010-07-30 11:08:20 +00:00
|
|
|
goto err_unreg_device;
|
2008-11-22 10:29:33 +00:00
|
|
|
}
|
|
|
|
|
2010-06-11 21:27:36 +00:00
|
|
|
/* must init LCD first, just in case an IRQ from the keypad is
|
|
|
|
* generated at keypad init
|
|
|
|
*/
|
2014-11-27 21:36:49 +00:00
|
|
|
if (lcd.enabled) {
|
2008-11-22 10:29:33 +00:00
|
|
|
lcd_init();
|
2010-07-30 11:08:20 +00:00
|
|
|
if (misc_register(&lcd_dev))
|
|
|
|
goto err_unreg_device;
|
2008-11-22 10:29:33 +00:00
|
|
|
}
|
|
|
|
|
2014-11-27 21:36:49 +00:00
|
|
|
if (keypad.enabled) {
|
2008-11-22 10:29:33 +00:00
|
|
|
keypad_init();
|
2010-07-30 11:08:20 +00:00
|
|
|
if (misc_register(&keypad_dev))
|
|
|
|
goto err_lcd_unreg;
|
2008-11-22 10:29:33 +00:00
|
|
|
}
|
2015-03-09 14:38:23 +00:00
|
|
|
register_reboot_notifier(&panel_notifier);
|
2010-07-30 11:08:20 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
err_lcd_unreg:
|
2014-11-27 21:36:49 +00:00
|
|
|
if (lcd.enabled)
|
2010-07-30 11:08:20 +00:00
|
|
|
misc_deregister(&lcd_dev);
|
|
|
|
err_unreg_device:
|
|
|
|
parport_unregister_device(pprt);
|
|
|
|
pprt = NULL;
|
2008-11-14 01:18:59 +00:00
|
|
|
}
|
|
|
|
|
2008-11-22 10:29:33 +00:00
|
|
|
static void panel_detach(struct parport *port)
|
2008-11-14 01:18:59 +00:00
|
|
|
{
|
2008-11-22 10:29:33 +00:00
|
|
|
if (port->number != parport)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!pprt) {
|
2012-07-12 13:01:17 +00:00
|
|
|
pr_err("%s: port->number=%d parport=%d, nothing to unregister.\n",
|
|
|
|
__func__, port->number, parport);
|
2008-11-22 10:29:33 +00:00
|
|
|
return;
|
|
|
|
}
|
2015-10-03 11:52:09 +00:00
|
|
|
if (scan_timer.function)
|
2015-05-12 12:06:08 +00:00
|
|
|
del_timer_sync(&scan_timer);
|
2008-11-22 10:29:33 +00:00
|
|
|
|
2017-02-06 14:38:08 +00:00
|
|
|
if (keypad.enabled) {
|
|
|
|
misc_deregister(&keypad_dev);
|
|
|
|
keypad_initialized = 0;
|
|
|
|
}
|
2008-11-22 10:29:33 +00:00
|
|
|
|
2017-02-06 14:38:08 +00:00
|
|
|
if (lcd.enabled) {
|
|
|
|
panel_lcd_print("\x0cLCD driver unloaded.\x1b[Lc\x1b[Lb\x1b[L-");
|
|
|
|
misc_deregister(&lcd_dev);
|
2017-02-06 14:38:10 +00:00
|
|
|
if (lcd.pins.bl != PIN_NONE) {
|
|
|
|
cancel_delayed_work_sync(&lcd.bl_work);
|
|
|
|
__lcd_backlight(0);
|
|
|
|
}
|
2017-02-06 14:38:08 +00:00
|
|
|
lcd.initialized = false;
|
2009-09-28 23:22:40 +00:00
|
|
|
}
|
2017-02-06 14:38:08 +00:00
|
|
|
|
|
|
|
/* TODO: free all input signals */
|
|
|
|
parport_release(pprt);
|
|
|
|
parport_unregister_device(pprt);
|
|
|
|
pprt = NULL;
|
|
|
|
unregister_reboot_notifier(&panel_notifier);
|
2008-11-14 01:18:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static struct parport_driver panel_driver = {
|
2008-11-22 10:29:33 +00:00
|
|
|
.name = "panel",
|
2015-05-20 15:26:58 +00:00
|
|
|
.match_port = panel_attach,
|
2008-11-22 10:29:33 +00:00
|
|
|
.detach = panel_detach,
|
2015-05-20 15:26:58 +00:00
|
|
|
.devmodel = true,
|
2008-11-14 01:18:59 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* init function */
|
2014-11-27 21:36:46 +00:00
|
|
|
static int __init panel_init_module(void)
|
2008-11-22 10:29:33 +00:00
|
|
|
{
|
2015-03-09 14:38:24 +00:00
|
|
|
int selected_keypad_type = NOT_SET, err;
|
2008-11-22 10:29:33 +00:00
|
|
|
|
|
|
|
/* take care of an eventual profile */
|
|
|
|
switch (profile) {
|
2010-06-11 21:27:36 +00:00
|
|
|
case PANEL_PROFILE_CUSTOM:
|
|
|
|
/* custom profile */
|
2014-11-27 21:36:50 +00:00
|
|
|
selected_keypad_type = DEFAULT_KEYPAD_TYPE;
|
|
|
|
selected_lcd_type = DEFAULT_LCD_TYPE;
|
2008-11-22 10:29:33 +00:00
|
|
|
break;
|
2010-06-11 21:27:36 +00:00
|
|
|
case PANEL_PROFILE_OLD:
|
|
|
|
/* 8 bits, 2*16, old keypad */
|
2014-11-27 21:36:50 +00:00
|
|
|
selected_keypad_type = KEYPAD_TYPE_OLD;
|
|
|
|
selected_lcd_type = LCD_TYPE_OLD;
|
|
|
|
|
|
|
|
/* TODO: This two are a little hacky, sort it out later */
|
2014-11-27 21:36:48 +00:00
|
|
|
if (lcd_width == NOT_SET)
|
2008-11-22 10:29:33 +00:00
|
|
|
lcd_width = 16;
|
2014-11-27 21:36:48 +00:00
|
|
|
if (lcd_hwidth == NOT_SET)
|
2008-11-22 10:29:33 +00:00
|
|
|
lcd_hwidth = 16;
|
|
|
|
break;
|
2010-06-11 21:27:36 +00:00
|
|
|
case PANEL_PROFILE_NEW:
|
|
|
|
/* serial, 2*16, new keypad */
|
2014-11-27 21:36:50 +00:00
|
|
|
selected_keypad_type = KEYPAD_TYPE_NEW;
|
|
|
|
selected_lcd_type = LCD_TYPE_KS0074;
|
2008-11-22 10:29:33 +00:00
|
|
|
break;
|
2010-06-11 21:27:36 +00:00
|
|
|
case PANEL_PROFILE_HANTRONIX:
|
|
|
|
/* 8 bits, 2*16 hantronix-like, no keypad */
|
2014-11-27 21:36:50 +00:00
|
|
|
selected_keypad_type = KEYPAD_TYPE_NONE;
|
|
|
|
selected_lcd_type = LCD_TYPE_HANTRONIX;
|
2008-11-22 10:29:33 +00:00
|
|
|
break;
|
2010-06-11 21:27:36 +00:00
|
|
|
case PANEL_PROFILE_NEXCOM:
|
|
|
|
/* generic 8 bits, 2*16, nexcom keypad, eg. Nexcom. */
|
2014-11-27 21:36:50 +00:00
|
|
|
selected_keypad_type = KEYPAD_TYPE_NEXCOM;
|
|
|
|
selected_lcd_type = LCD_TYPE_NEXCOM;
|
2008-11-22 10:29:33 +00:00
|
|
|
break;
|
2010-06-11 21:27:36 +00:00
|
|
|
case PANEL_PROFILE_LARGE:
|
|
|
|
/* 8 bits, 2*40, old keypad */
|
2014-11-27 21:36:50 +00:00
|
|
|
selected_keypad_type = KEYPAD_TYPE_OLD;
|
|
|
|
selected_lcd_type = LCD_TYPE_OLD;
|
2008-11-22 10:29:33 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2014-11-27 21:36:50 +00:00
|
|
|
/*
|
|
|
|
* Overwrite selection with module param values (both keypad and lcd),
|
|
|
|
* where the deprecated params have lower prio.
|
|
|
|
*/
|
2014-11-27 21:36:52 +00:00
|
|
|
if (keypad_enabled != NOT_SET)
|
2014-11-27 21:36:50 +00:00
|
|
|
selected_keypad_type = keypad_enabled;
|
2014-11-27 21:36:52 +00:00
|
|
|
if (keypad_type != NOT_SET)
|
2014-11-27 21:36:50 +00:00
|
|
|
selected_keypad_type = keypad_type;
|
|
|
|
|
|
|
|
keypad.enabled = (selected_keypad_type > 0);
|
|
|
|
|
2014-11-27 21:36:52 +00:00
|
|
|
if (lcd_enabled != NOT_SET)
|
2014-11-27 21:36:50 +00:00
|
|
|
selected_lcd_type = lcd_enabled;
|
2014-11-27 21:36:52 +00:00
|
|
|
if (lcd_type != NOT_SET)
|
2014-11-27 21:36:50 +00:00
|
|
|
selected_lcd_type = lcd_type;
|
|
|
|
|
|
|
|
lcd.enabled = (selected_lcd_type > 0);
|
2008-11-22 10:29:33 +00:00
|
|
|
|
2015-02-11 11:27:08 +00:00
|
|
|
if (lcd.enabled) {
|
|
|
|
/*
|
|
|
|
* Init lcd struct with load-time values to preserve exact
|
|
|
|
* current functionality (at least for now).
|
|
|
|
*/
|
|
|
|
lcd.height = lcd_height;
|
|
|
|
lcd.width = lcd_width;
|
|
|
|
lcd.bwidth = lcd_bwidth;
|
|
|
|
lcd.hwidth = lcd_hwidth;
|
|
|
|
lcd.charset = lcd_charset;
|
|
|
|
lcd.proto = lcd_proto;
|
|
|
|
lcd.pins.e = lcd_e_pin;
|
|
|
|
lcd.pins.rs = lcd_rs_pin;
|
|
|
|
lcd.pins.rw = lcd_rw_pin;
|
|
|
|
lcd.pins.cl = lcd_cl_pin;
|
|
|
|
lcd.pins.da = lcd_da_pin;
|
|
|
|
lcd.pins.bl = lcd_bl_pin;
|
|
|
|
|
|
|
|
/* Leave it for now, just in case */
|
|
|
|
lcd.esc_seq.len = -1;
|
|
|
|
}
|
|
|
|
|
2014-11-27 21:36:50 +00:00
|
|
|
switch (selected_keypad_type) {
|
2008-11-22 10:29:33 +00:00
|
|
|
case KEYPAD_TYPE_OLD:
|
|
|
|
keypad_profile = old_keypad_profile;
|
|
|
|
break;
|
|
|
|
case KEYPAD_TYPE_NEW:
|
|
|
|
keypad_profile = new_keypad_profile;
|
|
|
|
break;
|
|
|
|
case KEYPAD_TYPE_NEXCOM:
|
|
|
|
keypad_profile = nexcom_keypad_profile;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
keypad_profile = NULL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2014-11-27 21:36:49 +00:00
|
|
|
if (!lcd.enabled && !keypad.enabled) {
|
2015-02-10 11:56:02 +00:00
|
|
|
/* no device enabled, let's exit */
|
2017-02-06 14:38:04 +00:00
|
|
|
pr_err("panel driver disabled.\n");
|
2008-11-22 10:29:33 +00:00
|
|
|
return -ENODEV;
|
2008-11-14 01:18:59 +00:00
|
|
|
}
|
|
|
|
|
2015-03-09 14:38:24 +00:00
|
|
|
err = parport_register_driver(&panel_driver);
|
|
|
|
if (err) {
|
2015-02-10 11:56:02 +00:00
|
|
|
pr_err("could not register with parport. Aborting.\n");
|
2015-03-09 14:38:24 +00:00
|
|
|
return err;
|
2015-02-10 11:56:02 +00:00
|
|
|
}
|
|
|
|
|
2008-11-22 10:29:33 +00:00
|
|
|
if (pprt)
|
2017-02-06 14:38:04 +00:00
|
|
|
pr_info("panel driver registered on parport%d (io=0x%lx).\n",
|
|
|
|
parport, pprt->port->base);
|
2008-11-22 10:29:33 +00:00
|
|
|
else
|
2017-02-06 14:38:04 +00:00
|
|
|
pr_info("panel driver not yet registered\n");
|
2008-11-22 10:29:33 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2008-11-14 01:18:59 +00:00
|
|
|
|
2008-11-22 11:04:19 +00:00
|
|
|
static void __exit panel_cleanup_module(void)
|
2008-11-22 10:29:33 +00:00
|
|
|
{
|
|
|
|
parport_unregister_driver(&panel_driver);
|
2008-11-14 01:18:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
module_init(panel_init_module);
|
|
|
|
module_exit(panel_cleanup_module);
|
|
|
|
MODULE_AUTHOR("Willy Tarreau");
|
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Local variables:
|
|
|
|
* c-indent-level: 4
|
|
|
|
* tab-width: 8
|
|
|
|
* End:
|
|
|
|
*/
|