1 /* $NetBSD: hd44780var.h,v 1.8 2015/09/06 06:01:00 dholland Exp $ */ 2 3 /* 4 * Copyright (c) 2002 Dennis I. Chernoivanov 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 3. The name of the author may not be used to endorse or promote products 16 * derived from this software without specific prior written permission 17 * 18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 */ 29 30 #ifndef _DEV_IC_HD44780VAR_H_ 31 #define _DEV_IC_HD44780VAR_H_ 32 33 #include <sys/ioccom.h> 34 35 /* IOCTL definitions */ 36 #define HLCD_DISPCTL _IOW('h', 1, struct hd44780_dispctl) 37 #define HLCD_RESET _IO('h', 2) 38 #define HLCD_CLEAR _IO('h', 3) 39 #define HLCD_CURSOR_LEFT _IO('h', 4) 40 #define HLCD_CURSOR_RIGHT _IO('h', 5) 41 #define HLCD_GET_CURSOR_POS _IOR('h', 6, struct hd44780_io) 42 #define HLCD_SET_CURSOR_POS _IOW('h', 7, struct hd44780_io) 43 #define HLCD_GETC _IOR('h', 8, struct hd44780_io) 44 #define HLCD_PUTC _IOW('h', 9, struct hd44780_io) 45 #define HLCD_SHIFT_LEFT _IO('h', 10) 46 #define HLCD_SHIFT_RIGHT _IO('h', 11) 47 #define HLCD_HOME _IO('h', 12) 48 #define HLCD_WRITE _IOWR('h', 13, struct hd44780_io) 49 #define HLCD_READ _IOWR('h', 14, struct hd44780_io) 50 #define HLCD_REDRAW _IOW('h', 15, struct hd44780_io) 51 #define HLCD_WRITE_INST _IOW('h', 16, struct hd44780_io) 52 #define HLCD_WRITE_DATA _IOW('h', 17, struct hd44780_io) 53 #define HLCD_GET_INFO _IOR('h', 18, struct hd44780_info) 54 #define HLCD_GET_CHIPNO _IOR('h', 19, uint8_t) 55 #define HLCD_SET_CHIPNO _IOW('h', 20, uint8_t) 56 57 struct hd44780_dispctl { 58 uint8_t chip; 59 uint8_t display_on:1, 60 blink_on:1, 61 cursor_on:1; 62 }; 63 64 struct hd44780_io { 65 uint8_t chip; 66 uint8_t dat; 67 uint8_t len; 68 uint8_t buf[HD_MAX_CHARS]; 69 }; 70 71 struct hd44780_info { 72 uint8_t lines; 73 uint8_t phys_rows; 74 uint8_t virt_rows; 75 76 uint8_t is_wide:1, 77 is_bigfont:1, 78 kp_present:1; 79 }; 80 81 #ifdef _KERNEL 82 83 struct hlcd_screen { 84 int hlcd_curon; 85 int hlcd_curx; 86 int hlcd_cury; 87 uint8_t *image; /* characters of screen */ 88 struct hd44780_chip *hlcd_sc; 89 }; 90 91 /* HLCD driver structure */ 92 struct hd44780_chip { 93 #define HD_8BIT 0x01 /* 8-bit if set, 4-bit otherwise */ 94 #define HD_MULTILINE 0x02 /* 2 lines if set, 1 otherwise */ 95 #define HD_BIGFONT 0x04 /* 5x10 if set, 5x8 otherwise */ 96 #define HD_KEYPAD 0x08 /* if set, keypad is connected */ 97 #define HD_UP 0x10 /* if set, lcd has been initialized */ 98 #define HD_TIMEDOUT 0x20 /* lcd has recently stopped talking */ 99 #define HD_MULTICHIP 0x40 /* two HD44780 controllers (4-line) */ 100 uint8_t sc_flags; 101 102 uint8_t sc_cols; /* visible columns */ 103 uint8_t sc_vcols; /* virtual columns (normally 40) */ 104 uint8_t sc_dev_ok; 105 uint8_t sc_curchip; 106 107 bus_space_tag_t sc_iot; 108 109 bus_space_handle_t sc_ioir; /* instruction register */ 110 bus_space_handle_t sc_iodr; /* data register */ 111 112 device_t sc_dev; /* Pointer to parent device */ 113 struct hlcd_screen sc_screen; /* currently displayed screen copy */ 114 struct hlcd_screen *sc_curscr; /* active screen */ 115 struct callout redraw; /* wsdisplay refresh/redraw timer */ 116 117 /* Generic write/read byte entries. */ 118 void (* sc_writereg)(struct hd44780_chip *, uint32_t, uint32_t, 119 uint8_t); 120 uint8_t (* sc_readreg)(struct hd44780_chip *, uint32_t, uint32_t); 121 }; 122 123 #define hd44780_ir_write(sc, en, dat) \ 124 do { \ 125 hd44780_busy_wait(sc, (en)); \ 126 (sc)->sc_writereg((sc), (en), 0, (dat)); \ 127 } while(0) 128 129 #define hd44780_ir_read(sc, en) \ 130 (sc)->sc_readreg((sc), (en), 0) 131 132 #define hd44780_dr_write(sc, en, dat) \ 133 (sc)->sc_writereg((sc), (en), 1, (dat)) 134 135 #define hd44780_dr_read(sc, en) \ 136 (sc)->sc_readreg((sc), (en), 1) 137 138 void hd44780_attach_subr(struct hd44780_chip *); 139 void hd44780_busy_wait(struct hd44780_chip *, uint32_t); 140 int hd44780_init(struct hd44780_chip *); 141 int hd44780_chipinit(struct hd44780_chip *, uint32_t); 142 int hd44780_ioctl_subr(struct hd44780_chip *, u_long, void *); 143 void hd44780_ddram_redraw(struct hd44780_chip *, uint32_t, struct hd44780_io *); 144 145 #define HD_DDRAM_READ 0x0 146 #define HD_DDRAM_WRITE 0x1 147 int hd44780_ddram_io(struct hd44780_chip *, uint32_t, struct hd44780_io *, 148 uint8_t); 149 150 #if defined(HD44780_STD_WIDE) || defined(HD44780_STD_SHORT) 151 void hd44780_writereg(struct hd44780_chip *, uint32_t, uint32_t, uint8_t); 152 uint8_t hd44780_readreg(struct hd44780_chip *, uint32_t, uint32_t); 153 #endif 154 155 #endif /* _KERNEL */ 156 157 #endif /* _DEV_IC_HD44780VAR_H_ */ 158