Lidza Louina | 0b99d58 | 2013-08-01 17:00:20 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2004 Digi International (www.digi.com) |
| 3 | * Scott H Kilau <Scott_Kilau at digi dot com> |
Lidza Louina | 7a97deb | 2013-08-21 11:08:08 -0400 | [diff] [blame] | 4 | * |
Lidza Louina | 0b99d58 | 2013-08-01 17:00:20 -0400 | [diff] [blame] | 5 | * This program is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License as published by |
| 7 | * the Free Software Foundation; either version 2, or (at your option) |
| 8 | * any later version. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY, EXPRESS OR IMPLIED; without even the |
Lidza Louina | 7a97deb | 2013-08-21 11:08:08 -0400 | [diff] [blame] | 12 | * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
Lidza Louina | 0b99d58 | 2013-08-01 17:00:20 -0400 | [diff] [blame] | 13 | * PURPOSE. See the GNU General Public License for more details. |
Lidza Louina | 0b99d58 | 2013-08-01 17:00:20 -0400 | [diff] [blame] | 14 | */ |
| 15 | |
Lidza Louina | 0b99d58 | 2013-08-01 17:00:20 -0400 | [diff] [blame] | 16 | #include <linux/kernel.h> |
Lidza Louina | 0b99d58 | 2013-08-01 17:00:20 -0400 | [diff] [blame] | 17 | #include <linux/module.h> |
| 18 | #include <linux/ctype.h> |
| 19 | #include <linux/string.h> |
| 20 | #include <linux/serial_reg.h> |
| 21 | #include <linux/device.h> |
| 22 | #include <linux/pci.h> |
| 23 | #include <linux/kdev_t.h> |
Lidza Louina | 7a97deb | 2013-08-21 11:08:08 -0400 | [diff] [blame] | 24 | |
Lidza Louina | 0b99d58 | 2013-08-01 17:00:20 -0400 | [diff] [blame] | 25 | #include "dgnc_driver.h" |
Lidza Louina | 0b99d58 | 2013-08-01 17:00:20 -0400 | [diff] [blame] | 26 | #include "dgnc_mgmt.h" |
| 27 | |
Lidza Louina | 0b99d58 | 2013-08-01 17:00:20 -0400 | [diff] [blame] | 28 | static ssize_t dgnc_driver_version_show(struct device_driver *ddp, char *buf) |
| 29 | { |
| 30 | return snprintf(buf, PAGE_SIZE, "%s\n", DG_PART); |
| 31 | } |
| 32 | static DRIVER_ATTR(version, S_IRUSR, dgnc_driver_version_show, NULL); |
| 33 | |
Lidza Louina | 0b99d58 | 2013-08-01 17:00:20 -0400 | [diff] [blame] | 34 | static ssize_t dgnc_driver_boards_show(struct device_driver *ddp, char *buf) |
| 35 | { |
Daeseok Youn | 80e3e24 | 2016-03-23 20:54:36 +0900 | [diff] [blame] | 36 | return snprintf(buf, PAGE_SIZE, "%d\n", dgnc_num_boards); |
Lidza Louina | 0b99d58 | 2013-08-01 17:00:20 -0400 | [diff] [blame] | 37 | } |
| 38 | static DRIVER_ATTR(boards, S_IRUSR, dgnc_driver_boards_show, NULL); |
| 39 | |
Lidza Louina | 0b99d58 | 2013-08-01 17:00:20 -0400 | [diff] [blame] | 40 | static ssize_t dgnc_driver_maxboards_show(struct device_driver *ddp, char *buf) |
| 41 | { |
| 42 | return snprintf(buf, PAGE_SIZE, "%d\n", MAXBOARDS); |
| 43 | } |
| 44 | static DRIVER_ATTR(maxboards, S_IRUSR, dgnc_driver_maxboards_show, NULL); |
| 45 | |
Lidza Louina | 0b99d58 | 2013-08-01 17:00:20 -0400 | [diff] [blame] | 46 | static ssize_t dgnc_driver_pollrate_show(struct device_driver *ddp, char *buf) |
| 47 | { |
| 48 | return snprintf(buf, PAGE_SIZE, "%dms\n", dgnc_poll_tick); |
| 49 | } |
| 50 | |
Wim de With | 8ad524f | 2015-05-20 14:27:39 +0200 | [diff] [blame] | 51 | static ssize_t dgnc_driver_pollrate_store(struct device_driver *ddp, |
| 52 | const char *buf, size_t count) |
Lidza Louina | 0b99d58 | 2013-08-01 17:00:20 -0400 | [diff] [blame] | 53 | { |
Salah Triki | 51abf45c | 2015-10-04 02:49:48 +0100 | [diff] [blame] | 54 | unsigned long flags; |
| 55 | int tick; |
Roberta Dobrescu | fb33aa4 | 2014-09-20 00:01:39 +0300 | [diff] [blame] | 56 | int ret; |
| 57 | |
Salah Triki | 51abf45c | 2015-10-04 02:49:48 +0100 | [diff] [blame] | 58 | ret = sscanf(buf, "%d\n", &tick); |
Roberta Dobrescu | fb33aa4 | 2014-09-20 00:01:39 +0300 | [diff] [blame] | 59 | if (ret != 1) |
| 60 | return -EINVAL; |
Salah Triki | 51abf45c | 2015-10-04 02:49:48 +0100 | [diff] [blame] | 61 | |
| 62 | spin_lock_irqsave(&dgnc_poll_lock, flags); |
| 63 | dgnc_poll_tick = tick; |
| 64 | spin_unlock_irqrestore(&dgnc_poll_lock, flags); |
| 65 | |
Lidza Louina | 0b99d58 | 2013-08-01 17:00:20 -0400 | [diff] [blame] | 66 | return count; |
| 67 | } |
Wim de With | 8ad524f | 2015-05-20 14:27:39 +0200 | [diff] [blame] | 68 | static DRIVER_ATTR(pollrate, (S_IRUSR | S_IWUSR), dgnc_driver_pollrate_show, |
| 69 | dgnc_driver_pollrate_store); |
Lidza Louina | 0b99d58 | 2013-08-01 17:00:20 -0400 | [diff] [blame] | 70 | |
Lidza Louina | 0b99d58 | 2013-08-01 17:00:20 -0400 | [diff] [blame] | 71 | void dgnc_create_driver_sysfiles(struct pci_driver *dgnc_driver) |
| 72 | { |
| 73 | int rc = 0; |
| 74 | struct device_driver *driverfs = &dgnc_driver->driver; |
| 75 | |
| 76 | rc |= driver_create_file(driverfs, &driver_attr_version); |
| 77 | rc |= driver_create_file(driverfs, &driver_attr_boards); |
| 78 | rc |= driver_create_file(driverfs, &driver_attr_maxboards); |
Lidza Louina | 0b99d58 | 2013-08-01 17:00:20 -0400 | [diff] [blame] | 79 | rc |= driver_create_file(driverfs, &driver_attr_pollrate); |
Gulsah Kose | 77b55d8 | 2014-09-21 22:56:15 +0300 | [diff] [blame] | 80 | if (rc) |
Ioana Ciornei | c471c98 | 2015-03-31 02:29:35 +0300 | [diff] [blame] | 81 | pr_err("DGNC: sysfs driver_create_file failed!\n"); |
Lidza Louina | 0b99d58 | 2013-08-01 17:00:20 -0400 | [diff] [blame] | 82 | } |
| 83 | |
Lidza Louina | 0b99d58 | 2013-08-01 17:00:20 -0400 | [diff] [blame] | 84 | void dgnc_remove_driver_sysfiles(struct pci_driver *dgnc_driver) |
| 85 | { |
| 86 | struct device_driver *driverfs = &dgnc_driver->driver; |
Gulsah Kose | e8756d4 | 2014-09-20 19:31:15 +0300 | [diff] [blame] | 87 | |
Lidza Louina | 0b99d58 | 2013-08-01 17:00:20 -0400 | [diff] [blame] | 88 | driver_remove_file(driverfs, &driver_attr_version); |
| 89 | driver_remove_file(driverfs, &driver_attr_boards); |
| 90 | driver_remove_file(driverfs, &driver_attr_maxboards); |
Lidza Louina | 0b99d58 | 2013-08-01 17:00:20 -0400 | [diff] [blame] | 91 | driver_remove_file(driverfs, &driver_attr_pollrate); |
Lidza Louina | 0b99d58 | 2013-08-01 17:00:20 -0400 | [diff] [blame] | 92 | } |
| 93 | |
Jeremiah Mahler | 635c4ef | 2014-07-12 18:26:39 -0700 | [diff] [blame] | 94 | #define DGNC_VERIFY_BOARD(p, bd) \ |
| 95 | do { \ |
| 96 | if (!p) \ |
| 97 | return 0; \ |
| 98 | \ |
| 99 | bd = dev_get_drvdata(p); \ |
| 100 | if (!bd || bd->magic != DGNC_BOARD_MAGIC) \ |
| 101 | return 0; \ |
| 102 | if (bd->state != BOARD_READY) \ |
| 103 | return 0; \ |
| 104 | } while (0) |
Lidza Louina | 0b99d58 | 2013-08-01 17:00:20 -0400 | [diff] [blame] | 105 | |
Wim de With | 8ad524f | 2015-05-20 14:27:39 +0200 | [diff] [blame] | 106 | static ssize_t dgnc_vpd_show(struct device *p, struct device_attribute *attr, |
| 107 | char *buf) |
Lidza Louina | 0b99d58 | 2013-08-01 17:00:20 -0400 | [diff] [blame] | 108 | { |
Lidza Louina | 03425f5 | 2013-09-09 15:01:22 -0400 | [diff] [blame] | 109 | struct dgnc_board *bd; |
Lidza Louina | 0b99d58 | 2013-08-01 17:00:20 -0400 | [diff] [blame] | 110 | int count = 0; |
| 111 | int i = 0; |
| 112 | |
| 113 | DGNC_VERIFY_BOARD(p, bd); |
| 114 | |
Wim de With | 8ad524f | 2015-05-20 14:27:39 +0200 | [diff] [blame] | 115 | count += sprintf(buf + count, |
| 116 | "\n 0 1 2 3 4 5 6 7 8 9 A B C D E F"); |
Lidza Louina | 0b99d58 | 2013-08-01 17:00:20 -0400 | [diff] [blame] | 117 | for (i = 0; i < 0x40 * 2; i++) { |
| 118 | if (!(i % 16)) |
| 119 | count += sprintf(buf + count, "\n%04X ", i * 2); |
| 120 | count += sprintf(buf + count, "%02X ", bd->vpd[i]); |
| 121 | } |
| 122 | count += sprintf(buf + count, "\n"); |
| 123 | |
| 124 | return count; |
| 125 | } |
| 126 | static DEVICE_ATTR(vpd, S_IRUSR, dgnc_vpd_show, NULL); |
| 127 | |
Wim de With | 8ad524f | 2015-05-20 14:27:39 +0200 | [diff] [blame] | 128 | static ssize_t dgnc_serial_number_show(struct device *p, |
| 129 | struct device_attribute *attr, char *buf) |
Lidza Louina | 0b99d58 | 2013-08-01 17:00:20 -0400 | [diff] [blame] | 130 | { |
Lidza Louina | 03425f5 | 2013-09-09 15:01:22 -0400 | [diff] [blame] | 131 | struct dgnc_board *bd; |
Lidza Louina | 0b99d58 | 2013-08-01 17:00:20 -0400 | [diff] [blame] | 132 | int count = 0; |
| 133 | |
| 134 | DGNC_VERIFY_BOARD(p, bd); |
| 135 | |
| 136 | if (bd->serial_num[0] == '\0') |
| 137 | count += sprintf(buf + count, "<UNKNOWN>\n"); |
| 138 | else |
| 139 | count += sprintf(buf + count, "%s\n", bd->serial_num); |
| 140 | |
| 141 | return count; |
| 142 | } |
| 143 | static DEVICE_ATTR(serial_number, S_IRUSR, dgnc_serial_number_show, NULL); |
| 144 | |
Wim de With | 8ad524f | 2015-05-20 14:27:39 +0200 | [diff] [blame] | 145 | static ssize_t dgnc_ports_state_show(struct device *p, |
| 146 | struct device_attribute *attr, char *buf) |
Lidza Louina | 0b99d58 | 2013-08-01 17:00:20 -0400 | [diff] [blame] | 147 | { |
Lidza Louina | 03425f5 | 2013-09-09 15:01:22 -0400 | [diff] [blame] | 148 | struct dgnc_board *bd; |
Lidza Louina | 0b99d58 | 2013-08-01 17:00:20 -0400 | [diff] [blame] | 149 | int count = 0; |
| 150 | int i = 0; |
| 151 | |
| 152 | DGNC_VERIFY_BOARD(p, bd); |
| 153 | |
| 154 | for (i = 0; i < bd->nasync; i++) { |
| 155 | count += snprintf(buf + count, PAGE_SIZE - count, |
| 156 | "%d %s\n", bd->channels[i]->ch_portnum, |
| 157 | bd->channels[i]->ch_open_count ? "Open" : "Closed"); |
| 158 | } |
| 159 | return count; |
| 160 | } |
| 161 | static DEVICE_ATTR(ports_state, S_IRUSR, dgnc_ports_state_show, NULL); |
| 162 | |
Wim de With | 8ad524f | 2015-05-20 14:27:39 +0200 | [diff] [blame] | 163 | static ssize_t dgnc_ports_baud_show(struct device *p, |
| 164 | struct device_attribute *attr, char *buf) |
Lidza Louina | 0b99d58 | 2013-08-01 17:00:20 -0400 | [diff] [blame] | 165 | { |
Lidza Louina | 03425f5 | 2013-09-09 15:01:22 -0400 | [diff] [blame] | 166 | struct dgnc_board *bd; |
Lidza Louina | 0b99d58 | 2013-08-01 17:00:20 -0400 | [diff] [blame] | 167 | int count = 0; |
| 168 | int i = 0; |
| 169 | |
| 170 | DGNC_VERIFY_BOARD(p, bd); |
| 171 | |
| 172 | for (i = 0; i < bd->nasync; i++) { |
| 173 | count += snprintf(buf + count, PAGE_SIZE - count, |
Wim de With | 8ad524f | 2015-05-20 14:27:39 +0200 | [diff] [blame] | 174 | "%d %d\n", bd->channels[i]->ch_portnum, |
| 175 | bd->channels[i]->ch_old_baud); |
Lidza Louina | 0b99d58 | 2013-08-01 17:00:20 -0400 | [diff] [blame] | 176 | } |
| 177 | return count; |
| 178 | } |
| 179 | static DEVICE_ATTR(ports_baud, S_IRUSR, dgnc_ports_baud_show, NULL); |
| 180 | |
Wim de With | 8ad524f | 2015-05-20 14:27:39 +0200 | [diff] [blame] | 181 | static ssize_t dgnc_ports_msignals_show(struct device *p, |
| 182 | struct device_attribute *attr, |
| 183 | char *buf) |
Lidza Louina | 0b99d58 | 2013-08-01 17:00:20 -0400 | [diff] [blame] | 184 | { |
Lidza Louina | 03425f5 | 2013-09-09 15:01:22 -0400 | [diff] [blame] | 185 | struct dgnc_board *bd; |
Lidza Louina | 0b99d58 | 2013-08-01 17:00:20 -0400 | [diff] [blame] | 186 | int count = 0; |
| 187 | int i = 0; |
| 188 | |
| 189 | DGNC_VERIFY_BOARD(p, bd); |
| 190 | |
| 191 | for (i = 0; i < bd->nasync; i++) { |
Daeseok Youn | edd19a2 | 2016-05-09 11:46:50 +0900 | [diff] [blame] | 192 | struct channel_t *ch = bd->channels[i]; |
| 193 | |
| 194 | if (ch->ch_open_count) { |
Lidza Louina | 0b99d58 | 2013-08-01 17:00:20 -0400 | [diff] [blame] | 195 | count += snprintf(buf + count, PAGE_SIZE - count, |
Wim de With | 8ad524f | 2015-05-20 14:27:39 +0200 | [diff] [blame] | 196 | "%d %s %s %s %s %s %s\n", |
Daeseok Youn | edd19a2 | 2016-05-09 11:46:50 +0900 | [diff] [blame] | 197 | ch->ch_portnum, |
| 198 | (ch->ch_mostat & UART_MCR_RTS) ? "RTS" : "", |
| 199 | (ch->ch_mistat & UART_MSR_CTS) ? "CTS" : "", |
| 200 | (ch->ch_mostat & UART_MCR_DTR) ? "DTR" : "", |
| 201 | (ch->ch_mistat & UART_MSR_DSR) ? "DSR" : "", |
| 202 | (ch->ch_mistat & UART_MSR_DCD) ? "DCD" : "", |
| 203 | (ch->ch_mistat & UART_MSR_RI) ? "RI" : ""); |
Lidza Louina | 0b99d58 | 2013-08-01 17:00:20 -0400 | [diff] [blame] | 204 | } else { |
| 205 | count += snprintf(buf + count, PAGE_SIZE - count, |
Daeseok Youn | edd19a2 | 2016-05-09 11:46:50 +0900 | [diff] [blame] | 206 | "%d\n", ch->ch_portnum); |
Lidza Louina | 0b99d58 | 2013-08-01 17:00:20 -0400 | [diff] [blame] | 207 | } |
| 208 | } |
| 209 | return count; |
| 210 | } |
| 211 | static DEVICE_ATTR(ports_msignals, S_IRUSR, dgnc_ports_msignals_show, NULL); |
| 212 | |
Wim de With | 8ad524f | 2015-05-20 14:27:39 +0200 | [diff] [blame] | 213 | static ssize_t dgnc_ports_iflag_show(struct device *p, |
| 214 | struct device_attribute *attr, char *buf) |
Lidza Louina | 0b99d58 | 2013-08-01 17:00:20 -0400 | [diff] [blame] | 215 | { |
Lidza Louina | 03425f5 | 2013-09-09 15:01:22 -0400 | [diff] [blame] | 216 | struct dgnc_board *bd; |
Lidza Louina | 0b99d58 | 2013-08-01 17:00:20 -0400 | [diff] [blame] | 217 | int count = 0; |
| 218 | int i = 0; |
| 219 | |
| 220 | DGNC_VERIFY_BOARD(p, bd); |
| 221 | |
| 222 | for (i = 0; i < bd->nasync; i++) { |
| 223 | count += snprintf(buf + count, PAGE_SIZE - count, "%d %x\n", |
Wim de With | 8ad524f | 2015-05-20 14:27:39 +0200 | [diff] [blame] | 224 | bd->channels[i]->ch_portnum, |
| 225 | bd->channels[i]->ch_c_iflag); |
Lidza Louina | 0b99d58 | 2013-08-01 17:00:20 -0400 | [diff] [blame] | 226 | } |
| 227 | return count; |
| 228 | } |
| 229 | static DEVICE_ATTR(ports_iflag, S_IRUSR, dgnc_ports_iflag_show, NULL); |
| 230 | |
Wim de With | 8ad524f | 2015-05-20 14:27:39 +0200 | [diff] [blame] | 231 | static ssize_t dgnc_ports_cflag_show(struct device *p, |
| 232 | struct device_attribute *attr, char *buf) |
Lidza Louina | 0b99d58 | 2013-08-01 17:00:20 -0400 | [diff] [blame] | 233 | { |
Lidza Louina | 03425f5 | 2013-09-09 15:01:22 -0400 | [diff] [blame] | 234 | struct dgnc_board *bd; |
Lidza Louina | 0b99d58 | 2013-08-01 17:00:20 -0400 | [diff] [blame] | 235 | int count = 0; |
| 236 | int i = 0; |
| 237 | |
| 238 | DGNC_VERIFY_BOARD(p, bd); |
| 239 | |
| 240 | for (i = 0; i < bd->nasync; i++) { |
| 241 | count += snprintf(buf + count, PAGE_SIZE - count, "%d %x\n", |
Wim de With | 8ad524f | 2015-05-20 14:27:39 +0200 | [diff] [blame] | 242 | bd->channels[i]->ch_portnum, |
| 243 | bd->channels[i]->ch_c_cflag); |
Lidza Louina | 0b99d58 | 2013-08-01 17:00:20 -0400 | [diff] [blame] | 244 | } |
| 245 | return count; |
| 246 | } |
| 247 | static DEVICE_ATTR(ports_cflag, S_IRUSR, dgnc_ports_cflag_show, NULL); |
| 248 | |
Wim de With | 8ad524f | 2015-05-20 14:27:39 +0200 | [diff] [blame] | 249 | static ssize_t dgnc_ports_oflag_show(struct device *p, |
| 250 | struct device_attribute *attr, char *buf) |
Lidza Louina | 0b99d58 | 2013-08-01 17:00:20 -0400 | [diff] [blame] | 251 | { |
Lidza Louina | 03425f5 | 2013-09-09 15:01:22 -0400 | [diff] [blame] | 252 | struct dgnc_board *bd; |
Lidza Louina | 0b99d58 | 2013-08-01 17:00:20 -0400 | [diff] [blame] | 253 | int count = 0; |
| 254 | int i = 0; |
| 255 | |
| 256 | DGNC_VERIFY_BOARD(p, bd); |
| 257 | |
| 258 | for (i = 0; i < bd->nasync; i++) { |
| 259 | count += snprintf(buf + count, PAGE_SIZE - count, "%d %x\n", |
Wim de With | 8ad524f | 2015-05-20 14:27:39 +0200 | [diff] [blame] | 260 | bd->channels[i]->ch_portnum, |
| 261 | bd->channels[i]->ch_c_oflag); |
Lidza Louina | 0b99d58 | 2013-08-01 17:00:20 -0400 | [diff] [blame] | 262 | } |
| 263 | return count; |
| 264 | } |
| 265 | static DEVICE_ATTR(ports_oflag, S_IRUSR, dgnc_ports_oflag_show, NULL); |
| 266 | |
Wim de With | 8ad524f | 2015-05-20 14:27:39 +0200 | [diff] [blame] | 267 | static ssize_t dgnc_ports_lflag_show(struct device *p, |
| 268 | struct device_attribute *attr, char *buf) |
Lidza Louina | 0b99d58 | 2013-08-01 17:00:20 -0400 | [diff] [blame] | 269 | { |
Lidza Louina | 03425f5 | 2013-09-09 15:01:22 -0400 | [diff] [blame] | 270 | struct dgnc_board *bd; |
Lidza Louina | 0b99d58 | 2013-08-01 17:00:20 -0400 | [diff] [blame] | 271 | int count = 0; |
| 272 | int i = 0; |
| 273 | |
| 274 | DGNC_VERIFY_BOARD(p, bd); |
| 275 | |
| 276 | for (i = 0; i < bd->nasync; i++) { |
| 277 | count += snprintf(buf + count, PAGE_SIZE - count, "%d %x\n", |
Wim de With | 8ad524f | 2015-05-20 14:27:39 +0200 | [diff] [blame] | 278 | bd->channels[i]->ch_portnum, |
| 279 | bd->channels[i]->ch_c_lflag); |
Lidza Louina | 0b99d58 | 2013-08-01 17:00:20 -0400 | [diff] [blame] | 280 | } |
| 281 | return count; |
| 282 | } |
| 283 | static DEVICE_ATTR(ports_lflag, S_IRUSR, dgnc_ports_lflag_show, NULL); |
| 284 | |
Wim de With | 8ad524f | 2015-05-20 14:27:39 +0200 | [diff] [blame] | 285 | static ssize_t dgnc_ports_digi_flag_show(struct device *p, |
| 286 | struct device_attribute *attr, |
| 287 | char *buf) |
Lidza Louina | 0b99d58 | 2013-08-01 17:00:20 -0400 | [diff] [blame] | 288 | { |
Lidza Louina | 03425f5 | 2013-09-09 15:01:22 -0400 | [diff] [blame] | 289 | struct dgnc_board *bd; |
Lidza Louina | 0b99d58 | 2013-08-01 17:00:20 -0400 | [diff] [blame] | 290 | int count = 0; |
| 291 | int i = 0; |
| 292 | |
| 293 | DGNC_VERIFY_BOARD(p, bd); |
| 294 | |
| 295 | for (i = 0; i < bd->nasync; i++) { |
| 296 | count += snprintf(buf + count, PAGE_SIZE - count, "%d %x\n", |
Wim de With | 8ad524f | 2015-05-20 14:27:39 +0200 | [diff] [blame] | 297 | bd->channels[i]->ch_portnum, |
| 298 | bd->channels[i]->ch_digi.digi_flags); |
Lidza Louina | 0b99d58 | 2013-08-01 17:00:20 -0400 | [diff] [blame] | 299 | } |
| 300 | return count; |
| 301 | } |
| 302 | static DEVICE_ATTR(ports_digi_flag, S_IRUSR, dgnc_ports_digi_flag_show, NULL); |
| 303 | |
Wim de With | 8ad524f | 2015-05-20 14:27:39 +0200 | [diff] [blame] | 304 | static ssize_t dgnc_ports_rxcount_show(struct device *p, |
| 305 | struct device_attribute *attr, char *buf) |
Lidza Louina | 0b99d58 | 2013-08-01 17:00:20 -0400 | [diff] [blame] | 306 | { |
Lidza Louina | 03425f5 | 2013-09-09 15:01:22 -0400 | [diff] [blame] | 307 | struct dgnc_board *bd; |
Lidza Louina | 0b99d58 | 2013-08-01 17:00:20 -0400 | [diff] [blame] | 308 | int count = 0; |
| 309 | int i = 0; |
| 310 | |
| 311 | DGNC_VERIFY_BOARD(p, bd); |
| 312 | |
| 313 | for (i = 0; i < bd->nasync; i++) { |
| 314 | count += snprintf(buf + count, PAGE_SIZE - count, "%d %ld\n", |
Wim de With | 8ad524f | 2015-05-20 14:27:39 +0200 | [diff] [blame] | 315 | bd->channels[i]->ch_portnum, |
| 316 | bd->channels[i]->ch_rxcount); |
Lidza Louina | 0b99d58 | 2013-08-01 17:00:20 -0400 | [diff] [blame] | 317 | } |
| 318 | return count; |
| 319 | } |
| 320 | static DEVICE_ATTR(ports_rxcount, S_IRUSR, dgnc_ports_rxcount_show, NULL); |
| 321 | |
Wim de With | 8ad524f | 2015-05-20 14:27:39 +0200 | [diff] [blame] | 322 | static ssize_t dgnc_ports_txcount_show(struct device *p, |
| 323 | struct device_attribute *attr, char *buf) |
Lidza Louina | 0b99d58 | 2013-08-01 17:00:20 -0400 | [diff] [blame] | 324 | { |
Lidza Louina | 03425f5 | 2013-09-09 15:01:22 -0400 | [diff] [blame] | 325 | struct dgnc_board *bd; |
Lidza Louina | 0b99d58 | 2013-08-01 17:00:20 -0400 | [diff] [blame] | 326 | int count = 0; |
| 327 | int i = 0; |
| 328 | |
| 329 | DGNC_VERIFY_BOARD(p, bd); |
| 330 | |
| 331 | for (i = 0; i < bd->nasync; i++) { |
| 332 | count += snprintf(buf + count, PAGE_SIZE - count, "%d %ld\n", |
Wim de With | 8ad524f | 2015-05-20 14:27:39 +0200 | [diff] [blame] | 333 | bd->channels[i]->ch_portnum, |
| 334 | bd->channels[i]->ch_txcount); |
Lidza Louina | 0b99d58 | 2013-08-01 17:00:20 -0400 | [diff] [blame] | 335 | } |
| 336 | return count; |
| 337 | } |
| 338 | static DEVICE_ATTR(ports_txcount, S_IRUSR, dgnc_ports_txcount_show, NULL); |
| 339 | |
Lidza Louina | 0b99d58 | 2013-08-01 17:00:20 -0400 | [diff] [blame] | 340 | /* this function creates the sys files that will export each signal status |
| 341 | * to sysfs each value will be put in a separate filename |
| 342 | */ |
Lidza Louina | 03425f5 | 2013-09-09 15:01:22 -0400 | [diff] [blame] | 343 | void dgnc_create_ports_sysfiles(struct dgnc_board *bd) |
Lidza Louina | 0b99d58 | 2013-08-01 17:00:20 -0400 | [diff] [blame] | 344 | { |
| 345 | int rc = 0; |
| 346 | |
| 347 | dev_set_drvdata(&bd->pdev->dev, bd); |
Sudip Mukherjee | 7df227c | 2015-10-04 19:50:15 +0530 | [diff] [blame] | 348 | rc |= device_create_file(&bd->pdev->dev, &dev_attr_ports_state); |
| 349 | rc |= device_create_file(&bd->pdev->dev, &dev_attr_ports_baud); |
| 350 | rc |= device_create_file(&bd->pdev->dev, &dev_attr_ports_msignals); |
| 351 | rc |= device_create_file(&bd->pdev->dev, &dev_attr_ports_iflag); |
| 352 | rc |= device_create_file(&bd->pdev->dev, &dev_attr_ports_cflag); |
| 353 | rc |= device_create_file(&bd->pdev->dev, &dev_attr_ports_oflag); |
| 354 | rc |= device_create_file(&bd->pdev->dev, &dev_attr_ports_lflag); |
| 355 | rc |= device_create_file(&bd->pdev->dev, &dev_attr_ports_digi_flag); |
| 356 | rc |= device_create_file(&bd->pdev->dev, &dev_attr_ports_rxcount); |
| 357 | rc |= device_create_file(&bd->pdev->dev, &dev_attr_ports_txcount); |
| 358 | rc |= device_create_file(&bd->pdev->dev, &dev_attr_vpd); |
| 359 | rc |= device_create_file(&bd->pdev->dev, &dev_attr_serial_number); |
Gulsah Kose | 77b55d8 | 2014-09-21 22:56:15 +0300 | [diff] [blame] | 360 | if (rc) |
Cristina Opriceana | c28645e | 2015-02-27 14:10:36 +0200 | [diff] [blame] | 361 | dev_err(&bd->pdev->dev, "dgnc: sysfs device_create_file failed!\n"); |
Lidza Louina | 0b99d58 | 2013-08-01 17:00:20 -0400 | [diff] [blame] | 362 | } |
| 363 | |
Lidza Louina | 0b99d58 | 2013-08-01 17:00:20 -0400 | [diff] [blame] | 364 | /* removes all the sys files created for that port */ |
Lidza Louina | 03425f5 | 2013-09-09 15:01:22 -0400 | [diff] [blame] | 365 | void dgnc_remove_ports_sysfiles(struct dgnc_board *bd) |
Lidza Louina | 0b99d58 | 2013-08-01 17:00:20 -0400 | [diff] [blame] | 366 | { |
Sudip Mukherjee | 7df227c | 2015-10-04 19:50:15 +0530 | [diff] [blame] | 367 | device_remove_file(&bd->pdev->dev, &dev_attr_ports_state); |
| 368 | device_remove_file(&bd->pdev->dev, &dev_attr_ports_baud); |
| 369 | device_remove_file(&bd->pdev->dev, &dev_attr_ports_msignals); |
| 370 | device_remove_file(&bd->pdev->dev, &dev_attr_ports_iflag); |
| 371 | device_remove_file(&bd->pdev->dev, &dev_attr_ports_cflag); |
| 372 | device_remove_file(&bd->pdev->dev, &dev_attr_ports_oflag); |
| 373 | device_remove_file(&bd->pdev->dev, &dev_attr_ports_lflag); |
| 374 | device_remove_file(&bd->pdev->dev, &dev_attr_ports_digi_flag); |
| 375 | device_remove_file(&bd->pdev->dev, &dev_attr_ports_rxcount); |
| 376 | device_remove_file(&bd->pdev->dev, &dev_attr_ports_txcount); |
| 377 | device_remove_file(&bd->pdev->dev, &dev_attr_vpd); |
| 378 | device_remove_file(&bd->pdev->dev, &dev_attr_serial_number); |
Lidza Louina | 0b99d58 | 2013-08-01 17:00:20 -0400 | [diff] [blame] | 379 | } |
| 380 | |
Wim de With | 8ad524f | 2015-05-20 14:27:39 +0200 | [diff] [blame] | 381 | static ssize_t dgnc_tty_state_show(struct device *d, |
| 382 | struct device_attribute *attr, char *buf) |
Lidza Louina | 0b99d58 | 2013-08-01 17:00:20 -0400 | [diff] [blame] | 383 | { |
Lidza Louina | 03425f5 | 2013-09-09 15:01:22 -0400 | [diff] [blame] | 384 | struct dgnc_board *bd; |
Lidza Louina | 0b99d58 | 2013-08-01 17:00:20 -0400 | [diff] [blame] | 385 | struct channel_t *ch; |
| 386 | struct un_t *un; |
| 387 | |
| 388 | if (!d) |
Lidza Louina | 8f90ef8 | 2013-09-09 15:01:23 -0400 | [diff] [blame] | 389 | return 0; |
Jingoo Han | 0e4f66b | 2013-09-26 08:35:49 +0900 | [diff] [blame] | 390 | un = dev_get_drvdata(d); |
Lidza Louina | 0b99d58 | 2013-08-01 17:00:20 -0400 | [diff] [blame] | 391 | if (!un || un->magic != DGNC_UNIT_MAGIC) |
Lidza Louina | 8f90ef8 | 2013-09-09 15:01:23 -0400 | [diff] [blame] | 392 | return 0; |
Lidza Louina | 0b99d58 | 2013-08-01 17:00:20 -0400 | [diff] [blame] | 393 | ch = un->un_ch; |
| 394 | if (!ch || ch->magic != DGNC_CHANNEL_MAGIC) |
Lidza Louina | 8f90ef8 | 2013-09-09 15:01:23 -0400 | [diff] [blame] | 395 | return 0; |
Lidza Louina | 0b99d58 | 2013-08-01 17:00:20 -0400 | [diff] [blame] | 396 | bd = ch->ch_bd; |
| 397 | if (!bd || bd->magic != DGNC_BOARD_MAGIC) |
Lidza Louina | 8f90ef8 | 2013-09-09 15:01:23 -0400 | [diff] [blame] | 398 | return 0; |
Lidza Louina | 0b99d58 | 2013-08-01 17:00:20 -0400 | [diff] [blame] | 399 | if (bd->state != BOARD_READY) |
Lidza Louina | 8f90ef8 | 2013-09-09 15:01:23 -0400 | [diff] [blame] | 400 | return 0; |
Lidza Louina | 0b99d58 | 2013-08-01 17:00:20 -0400 | [diff] [blame] | 401 | |
Wim de With | 8ad524f | 2015-05-20 14:27:39 +0200 | [diff] [blame] | 402 | return snprintf(buf, PAGE_SIZE, "%s", |
| 403 | un->un_open_count ? "Open" : "Closed"); |
Lidza Louina | 0b99d58 | 2013-08-01 17:00:20 -0400 | [diff] [blame] | 404 | } |
| 405 | static DEVICE_ATTR(state, S_IRUSR, dgnc_tty_state_show, NULL); |
| 406 | |
Wim de With | 8ad524f | 2015-05-20 14:27:39 +0200 | [diff] [blame] | 407 | static ssize_t dgnc_tty_baud_show(struct device *d, |
| 408 | struct device_attribute *attr, char *buf) |
Lidza Louina | 0b99d58 | 2013-08-01 17:00:20 -0400 | [diff] [blame] | 409 | { |
Lidza Louina | 03425f5 | 2013-09-09 15:01:22 -0400 | [diff] [blame] | 410 | struct dgnc_board *bd; |
Lidza Louina | 0b99d58 | 2013-08-01 17:00:20 -0400 | [diff] [blame] | 411 | struct channel_t *ch; |
| 412 | struct un_t *un; |
| 413 | |
| 414 | if (!d) |
Lidza Louina | 8f90ef8 | 2013-09-09 15:01:23 -0400 | [diff] [blame] | 415 | return 0; |
Jingoo Han | 0e4f66b | 2013-09-26 08:35:49 +0900 | [diff] [blame] | 416 | un = dev_get_drvdata(d); |
Lidza Louina | 0b99d58 | 2013-08-01 17:00:20 -0400 | [diff] [blame] | 417 | if (!un || un->magic != DGNC_UNIT_MAGIC) |
Lidza Louina | 8f90ef8 | 2013-09-09 15:01:23 -0400 | [diff] [blame] | 418 | return 0; |
Lidza Louina | 0b99d58 | 2013-08-01 17:00:20 -0400 | [diff] [blame] | 419 | ch = un->un_ch; |
| 420 | if (!ch || ch->magic != DGNC_CHANNEL_MAGIC) |
Lidza Louina | 8f90ef8 | 2013-09-09 15:01:23 -0400 | [diff] [blame] | 421 | return 0; |
Lidza Louina | 0b99d58 | 2013-08-01 17:00:20 -0400 | [diff] [blame] | 422 | bd = ch->ch_bd; |
| 423 | if (!bd || bd->magic != DGNC_BOARD_MAGIC) |
Lidza Louina | 8f90ef8 | 2013-09-09 15:01:23 -0400 | [diff] [blame] | 424 | return 0; |
Lidza Louina | 0b99d58 | 2013-08-01 17:00:20 -0400 | [diff] [blame] | 425 | if (bd->state != BOARD_READY) |
Lidza Louina | 8f90ef8 | 2013-09-09 15:01:23 -0400 | [diff] [blame] | 426 | return 0; |
Lidza Louina | 0b99d58 | 2013-08-01 17:00:20 -0400 | [diff] [blame] | 427 | |
| 428 | return snprintf(buf, PAGE_SIZE, "%d\n", ch->ch_old_baud); |
| 429 | } |
| 430 | static DEVICE_ATTR(baud, S_IRUSR, dgnc_tty_baud_show, NULL); |
| 431 | |
Wim de With | 8ad524f | 2015-05-20 14:27:39 +0200 | [diff] [blame] | 432 | static ssize_t dgnc_tty_msignals_show(struct device *d, |
| 433 | struct device_attribute *attr, char *buf) |
Lidza Louina | 0b99d58 | 2013-08-01 17:00:20 -0400 | [diff] [blame] | 434 | { |
Lidza Louina | 03425f5 | 2013-09-09 15:01:22 -0400 | [diff] [blame] | 435 | struct dgnc_board *bd; |
Lidza Louina | 0b99d58 | 2013-08-01 17:00:20 -0400 | [diff] [blame] | 436 | struct channel_t *ch; |
| 437 | struct un_t *un; |
| 438 | |
| 439 | if (!d) |
Lidza Louina | 8f90ef8 | 2013-09-09 15:01:23 -0400 | [diff] [blame] | 440 | return 0; |
Jingoo Han | 0e4f66b | 2013-09-26 08:35:49 +0900 | [diff] [blame] | 441 | un = dev_get_drvdata(d); |
Lidza Louina | 0b99d58 | 2013-08-01 17:00:20 -0400 | [diff] [blame] | 442 | if (!un || un->magic != DGNC_UNIT_MAGIC) |
Lidza Louina | 8f90ef8 | 2013-09-09 15:01:23 -0400 | [diff] [blame] | 443 | return 0; |
Lidza Louina | 0b99d58 | 2013-08-01 17:00:20 -0400 | [diff] [blame] | 444 | ch = un->un_ch; |
| 445 | if (!ch || ch->magic != DGNC_CHANNEL_MAGIC) |
Lidza Louina | 8f90ef8 | 2013-09-09 15:01:23 -0400 | [diff] [blame] | 446 | return 0; |
Lidza Louina | 0b99d58 | 2013-08-01 17:00:20 -0400 | [diff] [blame] | 447 | bd = ch->ch_bd; |
| 448 | if (!bd || bd->magic != DGNC_BOARD_MAGIC) |
Lidza Louina | 8f90ef8 | 2013-09-09 15:01:23 -0400 | [diff] [blame] | 449 | return 0; |
Lidza Louina | 0b99d58 | 2013-08-01 17:00:20 -0400 | [diff] [blame] | 450 | if (bd->state != BOARD_READY) |
Lidza Louina | 8f90ef8 | 2013-09-09 15:01:23 -0400 | [diff] [blame] | 451 | return 0; |
Lidza Louina | 0b99d58 | 2013-08-01 17:00:20 -0400 | [diff] [blame] | 452 | |
| 453 | if (ch->ch_open_count) { |
| 454 | return snprintf(buf, PAGE_SIZE, "%s %s %s %s %s %s\n", |
| 455 | (ch->ch_mostat & UART_MCR_RTS) ? "RTS" : "", |
| 456 | (ch->ch_mistat & UART_MSR_CTS) ? "CTS" : "", |
| 457 | (ch->ch_mostat & UART_MCR_DTR) ? "DTR" : "", |
| 458 | (ch->ch_mistat & UART_MSR_DSR) ? "DSR" : "", |
| 459 | (ch->ch_mistat & UART_MSR_DCD) ? "DCD" : "", |
| 460 | (ch->ch_mistat & UART_MSR_RI) ? "RI" : ""); |
| 461 | } |
| 462 | return 0; |
| 463 | } |
| 464 | static DEVICE_ATTR(msignals, S_IRUSR, dgnc_tty_msignals_show, NULL); |
| 465 | |
Wim de With | 8ad524f | 2015-05-20 14:27:39 +0200 | [diff] [blame] | 466 | static ssize_t dgnc_tty_iflag_show(struct device *d, |
| 467 | struct device_attribute *attr, char *buf) |
Lidza Louina | 0b99d58 | 2013-08-01 17:00:20 -0400 | [diff] [blame] | 468 | { |
Lidza Louina | 03425f5 | 2013-09-09 15:01:22 -0400 | [diff] [blame] | 469 | struct dgnc_board *bd; |
Lidza Louina | 0b99d58 | 2013-08-01 17:00:20 -0400 | [diff] [blame] | 470 | struct channel_t *ch; |
| 471 | struct un_t *un; |
| 472 | |
| 473 | if (!d) |
Lidza Louina | 8f90ef8 | 2013-09-09 15:01:23 -0400 | [diff] [blame] | 474 | return 0; |
Jingoo Han | 0e4f66b | 2013-09-26 08:35:49 +0900 | [diff] [blame] | 475 | un = dev_get_drvdata(d); |
Lidza Louina | 0b99d58 | 2013-08-01 17:00:20 -0400 | [diff] [blame] | 476 | if (!un || un->magic != DGNC_UNIT_MAGIC) |
Lidza Louina | 8f90ef8 | 2013-09-09 15:01:23 -0400 | [diff] [blame] | 477 | return 0; |
Lidza Louina | 0b99d58 | 2013-08-01 17:00:20 -0400 | [diff] [blame] | 478 | ch = un->un_ch; |
| 479 | if (!ch || ch->magic != DGNC_CHANNEL_MAGIC) |
Lidza Louina | 8f90ef8 | 2013-09-09 15:01:23 -0400 | [diff] [blame] | 480 | return 0; |
Lidza Louina | 0b99d58 | 2013-08-01 17:00:20 -0400 | [diff] [blame] | 481 | bd = ch->ch_bd; |
| 482 | if (!bd || bd->magic != DGNC_BOARD_MAGIC) |
Lidza Louina | 8f90ef8 | 2013-09-09 15:01:23 -0400 | [diff] [blame] | 483 | return 0; |
Lidza Louina | 0b99d58 | 2013-08-01 17:00:20 -0400 | [diff] [blame] | 484 | if (bd->state != BOARD_READY) |
Lidza Louina | 8f90ef8 | 2013-09-09 15:01:23 -0400 | [diff] [blame] | 485 | return 0; |
Lidza Louina | 0b99d58 | 2013-08-01 17:00:20 -0400 | [diff] [blame] | 486 | |
| 487 | return snprintf(buf, PAGE_SIZE, "%x\n", ch->ch_c_iflag); |
| 488 | } |
| 489 | static DEVICE_ATTR(iflag, S_IRUSR, dgnc_tty_iflag_show, NULL); |
| 490 | |
Wim de With | 8ad524f | 2015-05-20 14:27:39 +0200 | [diff] [blame] | 491 | static ssize_t dgnc_tty_cflag_show(struct device *d, |
| 492 | struct device_attribute *attr, char *buf) |
Lidza Louina | 0b99d58 | 2013-08-01 17:00:20 -0400 | [diff] [blame] | 493 | { |
Lidza Louina | 03425f5 | 2013-09-09 15:01:22 -0400 | [diff] [blame] | 494 | struct dgnc_board *bd; |
Lidza Louina | 0b99d58 | 2013-08-01 17:00:20 -0400 | [diff] [blame] | 495 | struct channel_t *ch; |
| 496 | struct un_t *un; |
| 497 | |
| 498 | if (!d) |
Lidza Louina | 8f90ef8 | 2013-09-09 15:01:23 -0400 | [diff] [blame] | 499 | return 0; |
Jingoo Han | 0e4f66b | 2013-09-26 08:35:49 +0900 | [diff] [blame] | 500 | un = dev_get_drvdata(d); |
Lidza Louina | 0b99d58 | 2013-08-01 17:00:20 -0400 | [diff] [blame] | 501 | if (!un || un->magic != DGNC_UNIT_MAGIC) |
Lidza Louina | 8f90ef8 | 2013-09-09 15:01:23 -0400 | [diff] [blame] | 502 | return 0; |
Lidza Louina | 0b99d58 | 2013-08-01 17:00:20 -0400 | [diff] [blame] | 503 | ch = un->un_ch; |
| 504 | if (!ch || ch->magic != DGNC_CHANNEL_MAGIC) |
Lidza Louina | 8f90ef8 | 2013-09-09 15:01:23 -0400 | [diff] [blame] | 505 | return 0; |
Lidza Louina | 0b99d58 | 2013-08-01 17:00:20 -0400 | [diff] [blame] | 506 | bd = ch->ch_bd; |
| 507 | if (!bd || bd->magic != DGNC_BOARD_MAGIC) |
Lidza Louina | 8f90ef8 | 2013-09-09 15:01:23 -0400 | [diff] [blame] | 508 | return 0; |
Lidza Louina | 0b99d58 | 2013-08-01 17:00:20 -0400 | [diff] [blame] | 509 | if (bd->state != BOARD_READY) |
Lidza Louina | 8f90ef8 | 2013-09-09 15:01:23 -0400 | [diff] [blame] | 510 | return 0; |
Lidza Louina | 0b99d58 | 2013-08-01 17:00:20 -0400 | [diff] [blame] | 511 | |
| 512 | return snprintf(buf, PAGE_SIZE, "%x\n", ch->ch_c_cflag); |
| 513 | } |
| 514 | static DEVICE_ATTR(cflag, S_IRUSR, dgnc_tty_cflag_show, NULL); |
| 515 | |
Wim de With | 8ad524f | 2015-05-20 14:27:39 +0200 | [diff] [blame] | 516 | static ssize_t dgnc_tty_oflag_show(struct device *d, |
| 517 | struct device_attribute *attr, char *buf) |
Lidza Louina | 0b99d58 | 2013-08-01 17:00:20 -0400 | [diff] [blame] | 518 | { |
Lidza Louina | 03425f5 | 2013-09-09 15:01:22 -0400 | [diff] [blame] | 519 | struct dgnc_board *bd; |
Lidza Louina | 0b99d58 | 2013-08-01 17:00:20 -0400 | [diff] [blame] | 520 | struct channel_t *ch; |
| 521 | struct un_t *un; |
| 522 | |
| 523 | if (!d) |
Lidza Louina | 8f90ef8 | 2013-09-09 15:01:23 -0400 | [diff] [blame] | 524 | return 0; |
Jingoo Han | 0e4f66b | 2013-09-26 08:35:49 +0900 | [diff] [blame] | 525 | un = dev_get_drvdata(d); |
Lidza Louina | 0b99d58 | 2013-08-01 17:00:20 -0400 | [diff] [blame] | 526 | if (!un || un->magic != DGNC_UNIT_MAGIC) |
Lidza Louina | 8f90ef8 | 2013-09-09 15:01:23 -0400 | [diff] [blame] | 527 | return 0; |
Lidza Louina | 0b99d58 | 2013-08-01 17:00:20 -0400 | [diff] [blame] | 528 | ch = un->un_ch; |
| 529 | if (!ch || ch->magic != DGNC_CHANNEL_MAGIC) |
Lidza Louina | 8f90ef8 | 2013-09-09 15:01:23 -0400 | [diff] [blame] | 530 | return 0; |
Lidza Louina | 0b99d58 | 2013-08-01 17:00:20 -0400 | [diff] [blame] | 531 | bd = ch->ch_bd; |
| 532 | if (!bd || bd->magic != DGNC_BOARD_MAGIC) |
Lidza Louina | 8f90ef8 | 2013-09-09 15:01:23 -0400 | [diff] [blame] | 533 | return 0; |
Lidza Louina | 0b99d58 | 2013-08-01 17:00:20 -0400 | [diff] [blame] | 534 | if (bd->state != BOARD_READY) |
Lidza Louina | 8f90ef8 | 2013-09-09 15:01:23 -0400 | [diff] [blame] | 535 | return 0; |
Lidza Louina | 0b99d58 | 2013-08-01 17:00:20 -0400 | [diff] [blame] | 536 | |
| 537 | return snprintf(buf, PAGE_SIZE, "%x\n", ch->ch_c_oflag); |
| 538 | } |
| 539 | static DEVICE_ATTR(oflag, S_IRUSR, dgnc_tty_oflag_show, NULL); |
| 540 | |
Wim de With | 8ad524f | 2015-05-20 14:27:39 +0200 | [diff] [blame] | 541 | static ssize_t dgnc_tty_lflag_show(struct device *d, |
| 542 | struct device_attribute *attr, char *buf) |
Lidza Louina | 0b99d58 | 2013-08-01 17:00:20 -0400 | [diff] [blame] | 543 | { |
Lidza Louina | 03425f5 | 2013-09-09 15:01:22 -0400 | [diff] [blame] | 544 | struct dgnc_board *bd; |
Lidza Louina | 0b99d58 | 2013-08-01 17:00:20 -0400 | [diff] [blame] | 545 | struct channel_t *ch; |
| 546 | struct un_t *un; |
| 547 | |
| 548 | if (!d) |
Lidza Louina | 8f90ef8 | 2013-09-09 15:01:23 -0400 | [diff] [blame] | 549 | return 0; |
Jingoo Han | 0e4f66b | 2013-09-26 08:35:49 +0900 | [diff] [blame] | 550 | un = dev_get_drvdata(d); |
Lidza Louina | 0b99d58 | 2013-08-01 17:00:20 -0400 | [diff] [blame] | 551 | if (!un || un->magic != DGNC_UNIT_MAGIC) |
Lidza Louina | 8f90ef8 | 2013-09-09 15:01:23 -0400 | [diff] [blame] | 552 | return 0; |
Lidza Louina | 0b99d58 | 2013-08-01 17:00:20 -0400 | [diff] [blame] | 553 | ch = un->un_ch; |
| 554 | if (!ch || ch->magic != DGNC_CHANNEL_MAGIC) |
Lidza Louina | 8f90ef8 | 2013-09-09 15:01:23 -0400 | [diff] [blame] | 555 | return 0; |
Lidza Louina | 0b99d58 | 2013-08-01 17:00:20 -0400 | [diff] [blame] | 556 | bd = ch->ch_bd; |
| 557 | if (!bd || bd->magic != DGNC_BOARD_MAGIC) |
Lidza Louina | 8f90ef8 | 2013-09-09 15:01:23 -0400 | [diff] [blame] | 558 | return 0; |
Lidza Louina | 0b99d58 | 2013-08-01 17:00:20 -0400 | [diff] [blame] | 559 | if (bd->state != BOARD_READY) |
Lidza Louina | 8f90ef8 | 2013-09-09 15:01:23 -0400 | [diff] [blame] | 560 | return 0; |
Lidza Louina | 0b99d58 | 2013-08-01 17:00:20 -0400 | [diff] [blame] | 561 | |
| 562 | return snprintf(buf, PAGE_SIZE, "%x\n", ch->ch_c_lflag); |
| 563 | } |
| 564 | static DEVICE_ATTR(lflag, S_IRUSR, dgnc_tty_lflag_show, NULL); |
| 565 | |
Wim de With | 8ad524f | 2015-05-20 14:27:39 +0200 | [diff] [blame] | 566 | static ssize_t dgnc_tty_digi_flag_show(struct device *d, |
| 567 | struct device_attribute *attr, char *buf) |
Lidza Louina | 0b99d58 | 2013-08-01 17:00:20 -0400 | [diff] [blame] | 568 | { |
Lidza Louina | 03425f5 | 2013-09-09 15:01:22 -0400 | [diff] [blame] | 569 | struct dgnc_board *bd; |
Lidza Louina | 0b99d58 | 2013-08-01 17:00:20 -0400 | [diff] [blame] | 570 | struct channel_t *ch; |
| 571 | struct un_t *un; |
| 572 | |
| 573 | if (!d) |
Lidza Louina | 8f90ef8 | 2013-09-09 15:01:23 -0400 | [diff] [blame] | 574 | return 0; |
Jingoo Han | 0e4f66b | 2013-09-26 08:35:49 +0900 | [diff] [blame] | 575 | un = dev_get_drvdata(d); |
Lidza Louina | 0b99d58 | 2013-08-01 17:00:20 -0400 | [diff] [blame] | 576 | if (!un || un->magic != DGNC_UNIT_MAGIC) |
Lidza Louina | 8f90ef8 | 2013-09-09 15:01:23 -0400 | [diff] [blame] | 577 | return 0; |
Lidza Louina | 0b99d58 | 2013-08-01 17:00:20 -0400 | [diff] [blame] | 578 | ch = un->un_ch; |
| 579 | if (!ch || ch->magic != DGNC_CHANNEL_MAGIC) |
Lidza Louina | 8f90ef8 | 2013-09-09 15:01:23 -0400 | [diff] [blame] | 580 | return 0; |
Lidza Louina | 0b99d58 | 2013-08-01 17:00:20 -0400 | [diff] [blame] | 581 | bd = ch->ch_bd; |
| 582 | if (!bd || bd->magic != DGNC_BOARD_MAGIC) |
Lidza Louina | 8f90ef8 | 2013-09-09 15:01:23 -0400 | [diff] [blame] | 583 | return 0; |
Lidza Louina | 0b99d58 | 2013-08-01 17:00:20 -0400 | [diff] [blame] | 584 | if (bd->state != BOARD_READY) |
Lidza Louina | 8f90ef8 | 2013-09-09 15:01:23 -0400 | [diff] [blame] | 585 | return 0; |
Lidza Louina | 0b99d58 | 2013-08-01 17:00:20 -0400 | [diff] [blame] | 586 | |
| 587 | return snprintf(buf, PAGE_SIZE, "%x\n", ch->ch_digi.digi_flags); |
| 588 | } |
| 589 | static DEVICE_ATTR(digi_flag, S_IRUSR, dgnc_tty_digi_flag_show, NULL); |
| 590 | |
Wim de With | 8ad524f | 2015-05-20 14:27:39 +0200 | [diff] [blame] | 591 | static ssize_t dgnc_tty_rxcount_show(struct device *d, |
| 592 | struct device_attribute *attr, char *buf) |
Lidza Louina | 0b99d58 | 2013-08-01 17:00:20 -0400 | [diff] [blame] | 593 | { |
Lidza Louina | 03425f5 | 2013-09-09 15:01:22 -0400 | [diff] [blame] | 594 | struct dgnc_board *bd; |
Lidza Louina | 0b99d58 | 2013-08-01 17:00:20 -0400 | [diff] [blame] | 595 | struct channel_t *ch; |
| 596 | struct un_t *un; |
| 597 | |
| 598 | if (!d) |
Lidza Louina | 8f90ef8 | 2013-09-09 15:01:23 -0400 | [diff] [blame] | 599 | return 0; |
Jingoo Han | 0e4f66b | 2013-09-26 08:35:49 +0900 | [diff] [blame] | 600 | un = dev_get_drvdata(d); |
Lidza Louina | 0b99d58 | 2013-08-01 17:00:20 -0400 | [diff] [blame] | 601 | if (!un || un->magic != DGNC_UNIT_MAGIC) |
Lidza Louina | 8f90ef8 | 2013-09-09 15:01:23 -0400 | [diff] [blame] | 602 | return 0; |
Lidza Louina | 0b99d58 | 2013-08-01 17:00:20 -0400 | [diff] [blame] | 603 | ch = un->un_ch; |
| 604 | if (!ch || ch->magic != DGNC_CHANNEL_MAGIC) |
Lidza Louina | 8f90ef8 | 2013-09-09 15:01:23 -0400 | [diff] [blame] | 605 | return 0; |
Lidza Louina | 0b99d58 | 2013-08-01 17:00:20 -0400 | [diff] [blame] | 606 | bd = ch->ch_bd; |
| 607 | if (!bd || bd->magic != DGNC_BOARD_MAGIC) |
Lidza Louina | 8f90ef8 | 2013-09-09 15:01:23 -0400 | [diff] [blame] | 608 | return 0; |
Lidza Louina | 0b99d58 | 2013-08-01 17:00:20 -0400 | [diff] [blame] | 609 | if (bd->state != BOARD_READY) |
Lidza Louina | 8f90ef8 | 2013-09-09 15:01:23 -0400 | [diff] [blame] | 610 | return 0; |
Lidza Louina | 0b99d58 | 2013-08-01 17:00:20 -0400 | [diff] [blame] | 611 | |
| 612 | return snprintf(buf, PAGE_SIZE, "%ld\n", ch->ch_rxcount); |
| 613 | } |
| 614 | static DEVICE_ATTR(rxcount, S_IRUSR, dgnc_tty_rxcount_show, NULL); |
| 615 | |
Wim de With | 8ad524f | 2015-05-20 14:27:39 +0200 | [diff] [blame] | 616 | static ssize_t dgnc_tty_txcount_show(struct device *d, |
| 617 | struct device_attribute *attr, char *buf) |
Lidza Louina | 0b99d58 | 2013-08-01 17:00:20 -0400 | [diff] [blame] | 618 | { |
Lidza Louina | 03425f5 | 2013-09-09 15:01:22 -0400 | [diff] [blame] | 619 | struct dgnc_board *bd; |
Lidza Louina | 0b99d58 | 2013-08-01 17:00:20 -0400 | [diff] [blame] | 620 | struct channel_t *ch; |
| 621 | struct un_t *un; |
| 622 | |
| 623 | if (!d) |
Lidza Louina | 8f90ef8 | 2013-09-09 15:01:23 -0400 | [diff] [blame] | 624 | return 0; |
Jingoo Han | 0e4f66b | 2013-09-26 08:35:49 +0900 | [diff] [blame] | 625 | un = dev_get_drvdata(d); |
Lidza Louina | 0b99d58 | 2013-08-01 17:00:20 -0400 | [diff] [blame] | 626 | if (!un || un->magic != DGNC_UNIT_MAGIC) |
Lidza Louina | 8f90ef8 | 2013-09-09 15:01:23 -0400 | [diff] [blame] | 627 | return 0; |
Lidza Louina | 0b99d58 | 2013-08-01 17:00:20 -0400 | [diff] [blame] | 628 | ch = un->un_ch; |
| 629 | if (!ch || ch->magic != DGNC_CHANNEL_MAGIC) |
Lidza Louina | 8f90ef8 | 2013-09-09 15:01:23 -0400 | [diff] [blame] | 630 | return 0; |
Lidza Louina | 0b99d58 | 2013-08-01 17:00:20 -0400 | [diff] [blame] | 631 | bd = ch->ch_bd; |
| 632 | if (!bd || bd->magic != DGNC_BOARD_MAGIC) |
Lidza Louina | 8f90ef8 | 2013-09-09 15:01:23 -0400 | [diff] [blame] | 633 | return 0; |
Lidza Louina | 0b99d58 | 2013-08-01 17:00:20 -0400 | [diff] [blame] | 634 | if (bd->state != BOARD_READY) |
Lidza Louina | 8f90ef8 | 2013-09-09 15:01:23 -0400 | [diff] [blame] | 635 | return 0; |
Lidza Louina | 0b99d58 | 2013-08-01 17:00:20 -0400 | [diff] [blame] | 636 | |
| 637 | return snprintf(buf, PAGE_SIZE, "%ld\n", ch->ch_txcount); |
| 638 | } |
| 639 | static DEVICE_ATTR(txcount, S_IRUSR, dgnc_tty_txcount_show, NULL); |
| 640 | |
Wim de With | 8ad524f | 2015-05-20 14:27:39 +0200 | [diff] [blame] | 641 | static ssize_t dgnc_tty_name_show(struct device *d, |
| 642 | struct device_attribute *attr, char *buf) |
Lidza Louina | 0b99d58 | 2013-08-01 17:00:20 -0400 | [diff] [blame] | 643 | { |
Lidza Louina | 03425f5 | 2013-09-09 15:01:22 -0400 | [diff] [blame] | 644 | struct dgnc_board *bd; |
Lidza Louina | 0b99d58 | 2013-08-01 17:00:20 -0400 | [diff] [blame] | 645 | struct channel_t *ch; |
| 646 | struct un_t *un; |
| 647 | |
| 648 | if (!d) |
Lidza Louina | 8f90ef8 | 2013-09-09 15:01:23 -0400 | [diff] [blame] | 649 | return 0; |
Jingoo Han | 0e4f66b | 2013-09-26 08:35:49 +0900 | [diff] [blame] | 650 | un = dev_get_drvdata(d); |
Lidza Louina | 0b99d58 | 2013-08-01 17:00:20 -0400 | [diff] [blame] | 651 | if (!un || un->magic != DGNC_UNIT_MAGIC) |
Lidza Louina | 8f90ef8 | 2013-09-09 15:01:23 -0400 | [diff] [blame] | 652 | return 0; |
Lidza Louina | 0b99d58 | 2013-08-01 17:00:20 -0400 | [diff] [blame] | 653 | ch = un->un_ch; |
| 654 | if (!ch || ch->magic != DGNC_CHANNEL_MAGIC) |
Lidza Louina | 8f90ef8 | 2013-09-09 15:01:23 -0400 | [diff] [blame] | 655 | return 0; |
Lidza Louina | 0b99d58 | 2013-08-01 17:00:20 -0400 | [diff] [blame] | 656 | bd = ch->ch_bd; |
| 657 | if (!bd || bd->magic != DGNC_BOARD_MAGIC) |
Lidza Louina | 8f90ef8 | 2013-09-09 15:01:23 -0400 | [diff] [blame] | 658 | return 0; |
Lidza Louina | 0b99d58 | 2013-08-01 17:00:20 -0400 | [diff] [blame] | 659 | if (bd->state != BOARD_READY) |
Lidza Louina | 8f90ef8 | 2013-09-09 15:01:23 -0400 | [diff] [blame] | 660 | return 0; |
Lidza Louina | 0b99d58 | 2013-08-01 17:00:20 -0400 | [diff] [blame] | 661 | |
| 662 | return snprintf(buf, PAGE_SIZE, "%sn%d%c\n", |
| 663 | (un->un_type == DGNC_PRINT) ? "pr" : "tty", |
| 664 | bd->boardnum + 1, 'a' + ch->ch_portnum); |
| 665 | } |
| 666 | static DEVICE_ATTR(custom_name, S_IRUSR, dgnc_tty_name_show, NULL); |
| 667 | |
Lidza Louina | 0b99d58 | 2013-08-01 17:00:20 -0400 | [diff] [blame] | 668 | static struct attribute *dgnc_sysfs_tty_entries[] = { |
| 669 | &dev_attr_state.attr, |
| 670 | &dev_attr_baud.attr, |
| 671 | &dev_attr_msignals.attr, |
| 672 | &dev_attr_iflag.attr, |
| 673 | &dev_attr_cflag.attr, |
Lidza Louina | 7a97deb | 2013-08-21 11:08:08 -0400 | [diff] [blame] | 674 | &dev_attr_oflag.attr, |
Lidza Louina | 0b99d58 | 2013-08-01 17:00:20 -0400 | [diff] [blame] | 675 | &dev_attr_lflag.attr, |
| 676 | &dev_attr_digi_flag.attr, |
| 677 | &dev_attr_rxcount.attr, |
| 678 | &dev_attr_txcount.attr, |
| 679 | &dev_attr_custom_name.attr, |
| 680 | NULL |
| 681 | }; |
| 682 | |
Lidza Louina | 0b99d58 | 2013-08-01 17:00:20 -0400 | [diff] [blame] | 683 | static struct attribute_group dgnc_tty_attribute_group = { |
Lidza Louina | 0a60eb3 | 2013-08-21 13:30:10 -0400 | [diff] [blame] | 684 | .name = NULL, |
| 685 | .attrs = dgnc_sysfs_tty_entries, |
Lidza Louina | 0b99d58 | 2013-08-01 17:00:20 -0400 | [diff] [blame] | 686 | }; |
| 687 | |
Lidza Louina | 0b99d58 | 2013-08-01 17:00:20 -0400 | [diff] [blame] | 688 | void dgnc_create_tty_sysfs(struct un_t *un, struct device *c) |
| 689 | { |
| 690 | int ret; |
| 691 | |
| 692 | ret = sysfs_create_group(&c->kobj, &dgnc_tty_attribute_group); |
| 693 | if (ret) { |
Martin Kepplinger | 0f33ae1 | 2014-04-29 11:43:08 +0200 | [diff] [blame] | 694 | dev_err(c, "dgnc: failed to create sysfs tty device attributes.\n"); |
Lidza Louina | 0b99d58 | 2013-08-01 17:00:20 -0400 | [diff] [blame] | 695 | sysfs_remove_group(&c->kobj, &dgnc_tty_attribute_group); |
| 696 | return; |
| 697 | } |
| 698 | |
| 699 | dev_set_drvdata(c, un); |
Lidza Louina | 0b99d58 | 2013-08-01 17:00:20 -0400 | [diff] [blame] | 700 | } |
| 701 | |
Lidza Louina | 0b99d58 | 2013-08-01 17:00:20 -0400 | [diff] [blame] | 702 | void dgnc_remove_tty_sysfs(struct device *c) |
| 703 | { |
| 704 | sysfs_remove_group(&c->kobj, &dgnc_tty_attribute_group); |
| 705 | } |
| 706 | |