staging: dgap: removes mgmt.h
[linux-2.6.git] / drivers / staging / dgap / dgap_sysfs.c
bloba35c8ed69eff008e41dbf2b063de935801d23c6c
1 /*
2 * Copyright 2004 Digi International (www.digi.com)
3 * Scott H Kilau <Scott_Kilau at digi dot com>
4 *
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.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY, EXPRESS OR IMPLIED; without even the
12 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
13 * PURPOSE. See the GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 * NOTE TO LINUX KERNEL HACKERS: DO NOT REFORMAT THIS CODE!
22 * This is shared code between Digi's CVS archive and the
23 * Linux Kernel sources.
24 * Changing the source just for reformatting needlessly breaks
25 * our CVS diff history.
27 * Send any bug fixes/changes to: Eng.Linux at digi dot com.
28 * Thank you.
32 * $Id: dgap_sysfs.c,v 1.1 2009/10/23 14:01:57 markh Exp $
36 #include <linux/kernel.h>
37 #include <linux/version.h>
38 #include <linux/module.h>
39 #include <linux/ctype.h>
40 #include <linux/string.h>
41 #include <linux/serial_reg.h>
42 #include <linux/device.h>
43 #include <linux/pci.h>
44 #include <linux/kdev_t.h>
46 #include "dgap_driver.h"
47 #include "dgap_proc.h"
48 #include "dgap_conf.h"
49 #include "dgap_parse.h"
52 static ssize_t dgap_driver_version_show(struct device_driver *ddp, char *buf)
54 return snprintf(buf, PAGE_SIZE, "%s\n", DG_PART);
56 static DRIVER_ATTR(version, S_IRUSR, dgap_driver_version_show, NULL);
59 static ssize_t dgap_driver_boards_show(struct device_driver *ddp, char *buf)
61 return snprintf(buf, PAGE_SIZE, "%d\n", dgap_NumBoards);
63 static DRIVER_ATTR(boards, S_IRUSR, dgap_driver_boards_show, NULL);
66 static ssize_t dgap_driver_maxboards_show(struct device_driver *ddp, char *buf)
68 return snprintf(buf, PAGE_SIZE, "%d\n", MAXBOARDS);
70 static DRIVER_ATTR(maxboards, S_IRUSR, dgap_driver_maxboards_show, NULL);
73 static ssize_t dgap_driver_pollcounter_show(struct device_driver *ddp, char *buf)
75 return snprintf(buf, PAGE_SIZE, "%ld\n", dgap_poll_counter);
77 static DRIVER_ATTR(pollcounter, S_IRUSR, dgap_driver_pollcounter_show, NULL);
80 static ssize_t dgap_driver_state_show(struct device_driver *ddp, char *buf)
82 return snprintf(buf, PAGE_SIZE, "%s\n", dgap_driver_state_text[dgap_driver_state]);
84 static DRIVER_ATTR(state, S_IRUSR, dgap_driver_state_show, NULL);
87 static ssize_t dgap_driver_debug_show(struct device_driver *ddp, char *buf)
89 return snprintf(buf, PAGE_SIZE, "0x%x\n", dgap_debug);
92 static ssize_t dgap_driver_debug_store(struct device_driver *ddp, const char *buf, size_t count)
94 sscanf(buf, "0x%x\n", &dgap_debug);
95 return count;
97 static DRIVER_ATTR(debug, (S_IRUSR | S_IWUSR), dgap_driver_debug_show, dgap_driver_debug_store);
100 static ssize_t dgap_driver_rawreadok_show(struct device_driver *ddp, char *buf)
102 return snprintf(buf, PAGE_SIZE, "0x%x\n", dgap_rawreadok);
105 static ssize_t dgap_driver_rawreadok_store(struct device_driver *ddp, const char *buf, size_t count)
107 sscanf(buf, "0x%x\n", &dgap_rawreadok);
108 return count;
110 static DRIVER_ATTR(rawreadok, (S_IRUSR | S_IWUSR), dgap_driver_rawreadok_show, dgap_driver_rawreadok_store);
113 static ssize_t dgap_driver_pollrate_show(struct device_driver *ddp, char *buf)
115 return snprintf(buf, PAGE_SIZE, "%dms\n", dgap_poll_tick);
118 static ssize_t dgap_driver_pollrate_store(struct device_driver *ddp, const char *buf, size_t count)
120 sscanf(buf, "%d\n", &dgap_poll_tick);
121 return count;
123 static DRIVER_ATTR(pollrate, (S_IRUSR | S_IWUSR), dgap_driver_pollrate_show, dgap_driver_pollrate_store);
126 void dgap_create_driver_sysfiles(struct pci_driver *dgap_driver)
128 int rc = 0;
129 struct device_driver *driverfs = &dgap_driver->driver;
131 rc |= driver_create_file(driverfs, &driver_attr_version);
132 rc |= driver_create_file(driverfs, &driver_attr_boards);
133 rc |= driver_create_file(driverfs, &driver_attr_maxboards);
134 rc |= driver_create_file(driverfs, &driver_attr_debug);
135 rc |= driver_create_file(driverfs, &driver_attr_rawreadok);
136 rc |= driver_create_file(driverfs, &driver_attr_pollrate);
137 rc |= driver_create_file(driverfs, &driver_attr_pollcounter);
138 rc |= driver_create_file(driverfs, &driver_attr_state);
139 if (rc) {
140 printk(KERN_ERR "DGAP: sysfs driver_create_file failed!\n");
145 void dgap_remove_driver_sysfiles(struct pci_driver *dgap_driver)
147 struct device_driver *driverfs = &dgap_driver->driver;
148 driver_remove_file(driverfs, &driver_attr_version);
149 driver_remove_file(driverfs, &driver_attr_boards);
150 driver_remove_file(driverfs, &driver_attr_maxboards);
151 driver_remove_file(driverfs, &driver_attr_debug);
152 driver_remove_file(driverfs, &driver_attr_rawreadok);
153 driver_remove_file(driverfs, &driver_attr_pollrate);
154 driver_remove_file(driverfs, &driver_attr_pollcounter);
155 driver_remove_file(driverfs, &driver_attr_state);
159 #define DGAP_VERIFY_BOARD(p, bd) \
160 if (!p) \
161 return (0); \
163 bd = dev_get_drvdata(p); \
164 if (!bd || bd->magic != DGAP_BOARD_MAGIC) \
165 return (0); \
166 if (bd->state != BOARD_READY) \
167 return (0); \
170 static ssize_t dgap_ports_state_show(struct device *p, struct device_attribute *attr, char *buf)
172 struct board_t *bd;
173 int count = 0;
174 int i = 0;
176 DGAP_VERIFY_BOARD(p, bd);
178 for (i = 0; i < bd->nasync; i++) {
179 count += snprintf(buf + count, PAGE_SIZE - count,
180 "%d %s\n", bd->channels[i]->ch_portnum,
181 bd->channels[i]->ch_open_count ? "Open" : "Closed");
183 return count;
185 static DEVICE_ATTR(ports_state, S_IRUSR, dgap_ports_state_show, NULL);
188 static ssize_t dgap_ports_baud_show(struct device *p, struct device_attribute *attr, char *buf)
190 struct board_t *bd;
191 int count = 0;
192 int i = 0;
194 DGAP_VERIFY_BOARD(p, bd);
196 for (i = 0; i < bd->nasync; i++) {
197 count += snprintf(buf + count, PAGE_SIZE - count,
198 "%d %d\n", bd->channels[i]->ch_portnum, bd->channels[i]->ch_baud_info);
200 return count;
202 static DEVICE_ATTR(ports_baud, S_IRUSR, dgap_ports_baud_show, NULL);
205 static ssize_t dgap_ports_msignals_show(struct device *p, struct device_attribute *attr, char *buf)
207 struct board_t *bd;
208 int count = 0;
209 int i = 0;
211 DGAP_VERIFY_BOARD(p, bd);
213 for (i = 0; i < bd->nasync; i++) {
214 if (bd->channels[i]->ch_open_count) {
215 count += snprintf(buf + count, PAGE_SIZE - count,
216 "%d %s %s %s %s %s %s\n", bd->channels[i]->ch_portnum,
217 (bd->channels[i]->ch_mostat & UART_MCR_RTS) ? "RTS" : "",
218 (bd->channels[i]->ch_mistat & UART_MSR_CTS) ? "CTS" : "",
219 (bd->channels[i]->ch_mostat & UART_MCR_DTR) ? "DTR" : "",
220 (bd->channels[i]->ch_mistat & UART_MSR_DSR) ? "DSR" : "",
221 (bd->channels[i]->ch_mistat & UART_MSR_DCD) ? "DCD" : "",
222 (bd->channels[i]->ch_mistat & UART_MSR_RI) ? "RI" : "");
223 } else {
224 count += snprintf(buf + count, PAGE_SIZE - count,
225 "%d\n", bd->channels[i]->ch_portnum);
228 return count;
230 static DEVICE_ATTR(ports_msignals, S_IRUSR, dgap_ports_msignals_show, NULL);
233 static ssize_t dgap_ports_iflag_show(struct device *p, struct device_attribute *attr, char *buf)
235 struct board_t *bd;
236 int count = 0;
237 int i = 0;
239 DGAP_VERIFY_BOARD(p, bd);
241 for (i = 0; i < bd->nasync; i++) {
242 count += snprintf(buf + count, PAGE_SIZE - count, "%d %x\n",
243 bd->channels[i]->ch_portnum, bd->channels[i]->ch_c_iflag);
245 return count;
247 static DEVICE_ATTR(ports_iflag, S_IRUSR, dgap_ports_iflag_show, NULL);
250 static ssize_t dgap_ports_cflag_show(struct device *p, struct device_attribute *attr, char *buf)
252 struct board_t *bd;
253 int count = 0;
254 int i = 0;
256 DGAP_VERIFY_BOARD(p, bd);
258 for (i = 0; i < bd->nasync; i++) {
259 count += snprintf(buf + count, PAGE_SIZE - count, "%d %x\n",
260 bd->channels[i]->ch_portnum, bd->channels[i]->ch_c_cflag);
262 return count;
264 static DEVICE_ATTR(ports_cflag, S_IRUSR, dgap_ports_cflag_show, NULL);
267 static ssize_t dgap_ports_oflag_show(struct device *p, struct device_attribute *attr, char *buf)
269 struct board_t *bd;
270 int count = 0;
271 int i = 0;
273 DGAP_VERIFY_BOARD(p, bd);
275 for (i = 0; i < bd->nasync; i++) {
276 count += snprintf(buf + count, PAGE_SIZE - count, "%d %x\n",
277 bd->channels[i]->ch_portnum, bd->channels[i]->ch_c_oflag);
279 return count;
281 static DEVICE_ATTR(ports_oflag, S_IRUSR, dgap_ports_oflag_show, NULL);
284 static ssize_t dgap_ports_lflag_show(struct device *p, struct device_attribute *attr, char *buf)
286 struct board_t *bd;
287 int count = 0;
288 int i = 0;
290 DGAP_VERIFY_BOARD(p, bd);
292 for (i = 0; i < bd->nasync; i++) {
293 count += snprintf(buf + count, PAGE_SIZE - count, "%d %x\n",
294 bd->channels[i]->ch_portnum, bd->channels[i]->ch_c_lflag);
296 return count;
298 static DEVICE_ATTR(ports_lflag, S_IRUSR, dgap_ports_lflag_show, NULL);
301 static ssize_t dgap_ports_digi_flag_show(struct device *p, struct device_attribute *attr, char *buf)
303 struct board_t *bd;
304 int count = 0;
305 int i = 0;
307 DGAP_VERIFY_BOARD(p, bd);
309 for (i = 0; i < bd->nasync; i++) {
310 count += snprintf(buf + count, PAGE_SIZE - count, "%d %x\n",
311 bd->channels[i]->ch_portnum, bd->channels[i]->ch_digi.digi_flags);
313 return count;
315 static DEVICE_ATTR(ports_digi_flag, S_IRUSR, dgap_ports_digi_flag_show, NULL);
318 static ssize_t dgap_ports_rxcount_show(struct device *p, struct device_attribute *attr, char *buf)
320 struct board_t *bd;
321 int count = 0;
322 int i = 0;
324 DGAP_VERIFY_BOARD(p, bd);
326 for (i = 0; i < bd->nasync; i++) {
327 count += snprintf(buf + count, PAGE_SIZE - count, "%d %ld\n",
328 bd->channels[i]->ch_portnum, bd->channels[i]->ch_rxcount);
330 return count;
332 static DEVICE_ATTR(ports_rxcount, S_IRUSR, dgap_ports_rxcount_show, NULL);
335 static ssize_t dgap_ports_txcount_show(struct device *p, struct device_attribute *attr, char *buf)
337 struct board_t *bd;
338 int count = 0;
339 int i = 0;
341 DGAP_VERIFY_BOARD(p, bd);
343 for (i = 0; i < bd->nasync; i++) {
344 count += snprintf(buf + count, PAGE_SIZE - count, "%d %ld\n",
345 bd->channels[i]->ch_portnum, bd->channels[i]->ch_txcount);
347 return count;
349 static DEVICE_ATTR(ports_txcount, S_IRUSR, dgap_ports_txcount_show, NULL);
352 /* this function creates the sys files that will export each signal status
353 * to sysfs each value will be put in a separate filename
355 void dgap_create_ports_sysfiles(struct board_t *bd)
357 int rc = 0;
359 dev_set_drvdata(&bd->pdev->dev, bd);
360 rc |= device_create_file(&(bd->pdev->dev), &dev_attr_ports_state);
361 rc |= device_create_file(&(bd->pdev->dev), &dev_attr_ports_baud);
362 rc |= device_create_file(&(bd->pdev->dev), &dev_attr_ports_msignals);
363 rc |= device_create_file(&(bd->pdev->dev), &dev_attr_ports_iflag);
364 rc |= device_create_file(&(bd->pdev->dev), &dev_attr_ports_cflag);
365 rc |= device_create_file(&(bd->pdev->dev), &dev_attr_ports_oflag);
366 rc |= device_create_file(&(bd->pdev->dev), &dev_attr_ports_lflag);
367 rc |= device_create_file(&(bd->pdev->dev), &dev_attr_ports_digi_flag);
368 rc |= device_create_file(&(bd->pdev->dev), &dev_attr_ports_rxcount);
369 rc |= device_create_file(&(bd->pdev->dev), &dev_attr_ports_txcount);
370 if (rc) {
371 printk(KERN_ERR "DGAP: sysfs device_create_file failed!\n");
376 /* removes all the sys files created for that port */
377 void dgap_remove_ports_sysfiles(struct board_t *bd)
379 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_state);
380 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_baud);
381 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_msignals);
382 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_iflag);
383 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_cflag);
384 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_oflag);
385 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_lflag);
386 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_digi_flag);
387 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_rxcount);
388 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_txcount);
392 static ssize_t dgap_tty_state_show(struct device *d, struct device_attribute *attr, char *buf)
394 struct board_t *bd;
395 struct channel_t *ch;
396 struct un_t *un;
398 if (!d)
399 return (0);
400 un = (struct un_t *) dev_get_drvdata(d);
401 if (!un || un->magic != DGAP_UNIT_MAGIC)
402 return (0);
403 ch = un->un_ch;
404 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
405 return (0);
406 bd = ch->ch_bd;
407 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
408 return (0);
409 if (bd->state != BOARD_READY)
410 return (0);
412 return snprintf(buf, PAGE_SIZE, "%s", un->un_open_count ? "Open" : "Closed");
414 static DEVICE_ATTR(state, S_IRUSR, dgap_tty_state_show, NULL);
417 static ssize_t dgap_tty_baud_show(struct device *d, struct device_attribute *attr, char *buf)
419 struct board_t *bd;
420 struct channel_t *ch;
421 struct un_t *un;
423 if (!d)
424 return (0);
425 un = (struct un_t *) dev_get_drvdata(d);
426 if (!un || un->magic != DGAP_UNIT_MAGIC)
427 return (0);
428 ch = un->un_ch;
429 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
430 return (0);
431 bd = ch->ch_bd;
432 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
433 return (0);
434 if (bd->state != BOARD_READY)
435 return (0);
437 return snprintf(buf, PAGE_SIZE, "%d\n", ch->ch_baud_info);
439 static DEVICE_ATTR(baud, S_IRUSR, dgap_tty_baud_show, NULL);
442 static ssize_t dgap_tty_msignals_show(struct device *d, struct device_attribute *attr, char *buf)
444 struct board_t *bd;
445 struct channel_t *ch;
446 struct un_t *un;
448 if (!d)
449 return (0);
450 un = (struct un_t *) dev_get_drvdata(d);
451 if (!un || un->magic != DGAP_UNIT_MAGIC)
452 return (0);
453 ch = un->un_ch;
454 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
455 return (0);
456 bd = ch->ch_bd;
457 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
458 return (0);
459 if (bd->state != BOARD_READY)
460 return (0);
462 if (ch->ch_open_count) {
463 return snprintf(buf, PAGE_SIZE, "%s %s %s %s %s %s\n",
464 (ch->ch_mostat & UART_MCR_RTS) ? "RTS" : "",
465 (ch->ch_mistat & UART_MSR_CTS) ? "CTS" : "",
466 (ch->ch_mostat & UART_MCR_DTR) ? "DTR" : "",
467 (ch->ch_mistat & UART_MSR_DSR) ? "DSR" : "",
468 (ch->ch_mistat & UART_MSR_DCD) ? "DCD" : "",
469 (ch->ch_mistat & UART_MSR_RI) ? "RI" : "");
471 return 0;
473 static DEVICE_ATTR(msignals, S_IRUSR, dgap_tty_msignals_show, NULL);
476 static ssize_t dgap_tty_iflag_show(struct device *d, struct device_attribute *attr, char *buf)
478 struct board_t *bd;
479 struct channel_t *ch;
480 struct un_t *un;
482 if (!d)
483 return (0);
484 un = (struct un_t *) dev_get_drvdata(d);
485 if (!un || un->magic != DGAP_UNIT_MAGIC)
486 return (0);
487 ch = un->un_ch;
488 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
489 return (0);
490 bd = ch->ch_bd;
491 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
492 return (0);
493 if (bd->state != BOARD_READY)
494 return (0);
496 return snprintf(buf, PAGE_SIZE, "%x\n", ch->ch_c_iflag);
498 static DEVICE_ATTR(iflag, S_IRUSR, dgap_tty_iflag_show, NULL);
501 static ssize_t dgap_tty_cflag_show(struct device *d, struct device_attribute *attr, char *buf)
503 struct board_t *bd;
504 struct channel_t *ch;
505 struct un_t *un;
507 if (!d)
508 return (0);
509 un = (struct un_t *) dev_get_drvdata(d);
510 if (!un || un->magic != DGAP_UNIT_MAGIC)
511 return (0);
512 ch = un->un_ch;
513 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
514 return (0);
515 bd = ch->ch_bd;
516 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
517 return (0);
518 if (bd->state != BOARD_READY)
519 return (0);
521 return snprintf(buf, PAGE_SIZE, "%x\n", ch->ch_c_cflag);
523 static DEVICE_ATTR(cflag, S_IRUSR, dgap_tty_cflag_show, NULL);
526 static ssize_t dgap_tty_oflag_show(struct device *d, struct device_attribute *attr, char *buf)
528 struct board_t *bd;
529 struct channel_t *ch;
530 struct un_t *un;
532 if (!d)
533 return (0);
534 un = (struct un_t *) dev_get_drvdata(d);
535 if (!un || un->magic != DGAP_UNIT_MAGIC)
536 return (0);
537 ch = un->un_ch;
538 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
539 return (0);
540 bd = ch->ch_bd;
541 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
542 return (0);
543 if (bd->state != BOARD_READY)
544 return (0);
546 return snprintf(buf, PAGE_SIZE, "%x\n", ch->ch_c_oflag);
548 static DEVICE_ATTR(oflag, S_IRUSR, dgap_tty_oflag_show, NULL);
551 static ssize_t dgap_tty_lflag_show(struct device *d, struct device_attribute *attr, char *buf)
553 struct board_t *bd;
554 struct channel_t *ch;
555 struct un_t *un;
557 if (!d)
558 return (0);
559 un = (struct un_t *) dev_get_drvdata(d);
560 if (!un || un->magic != DGAP_UNIT_MAGIC)
561 return (0);
562 ch = un->un_ch;
563 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
564 return (0);
565 bd = ch->ch_bd;
566 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
567 return (0);
568 if (bd->state != BOARD_READY)
569 return (0);
571 return snprintf(buf, PAGE_SIZE, "%x\n", ch->ch_c_lflag);
573 static DEVICE_ATTR(lflag, S_IRUSR, dgap_tty_lflag_show, NULL);
576 static ssize_t dgap_tty_digi_flag_show(struct device *d, struct device_attribute *attr, char *buf)
578 struct board_t *bd;
579 struct channel_t *ch;
580 struct un_t *un;
582 if (!d)
583 return (0);
584 un = (struct un_t *) dev_get_drvdata(d);
585 if (!un || un->magic != DGAP_UNIT_MAGIC)
586 return (0);
587 ch = un->un_ch;
588 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
589 return (0);
590 bd = ch->ch_bd;
591 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
592 return (0);
593 if (bd->state != BOARD_READY)
594 return (0);
596 return snprintf(buf, PAGE_SIZE, "%x\n", ch->ch_digi.digi_flags);
598 static DEVICE_ATTR(digi_flag, S_IRUSR, dgap_tty_digi_flag_show, NULL);
601 static ssize_t dgap_tty_rxcount_show(struct device *d, struct device_attribute *attr, char *buf)
603 struct board_t *bd;
604 struct channel_t *ch;
605 struct un_t *un;
607 if (!d)
608 return (0);
609 un = (struct un_t *) dev_get_drvdata(d);
610 if (!un || un->magic != DGAP_UNIT_MAGIC)
611 return (0);
612 ch = un->un_ch;
613 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
614 return (0);
615 bd = ch->ch_bd;
616 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
617 return (0);
618 if (bd->state != BOARD_READY)
619 return (0);
621 return snprintf(buf, PAGE_SIZE, "%ld\n", ch->ch_rxcount);
623 static DEVICE_ATTR(rxcount, S_IRUSR, dgap_tty_rxcount_show, NULL);
626 static ssize_t dgap_tty_txcount_show(struct device *d, struct device_attribute *attr, char *buf)
628 struct board_t *bd;
629 struct channel_t *ch;
630 struct un_t *un;
632 if (!d)
633 return (0);
634 un = (struct un_t *) dev_get_drvdata(d);
635 if (!un || un->magic != DGAP_UNIT_MAGIC)
636 return (0);
637 ch = un->un_ch;
638 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
639 return (0);
640 bd = ch->ch_bd;
641 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
642 return (0);
643 if (bd->state != BOARD_READY)
644 return (0);
646 return snprintf(buf, PAGE_SIZE, "%ld\n", ch->ch_txcount);
648 static DEVICE_ATTR(txcount, S_IRUSR, dgap_tty_txcount_show, NULL);
651 static ssize_t dgap_tty_name_show(struct device *d, struct device_attribute *attr, char *buf)
653 struct board_t *bd;
654 struct channel_t *ch;
655 struct un_t *un;
656 int cn;
657 int bn;
658 struct cnode *cptr = NULL;
659 int found = FALSE;
660 int ncount = 0;
661 int starto = 0;
662 int i = 0;
664 if (!d)
665 return (0);
666 un = (struct un_t *) dev_get_drvdata(d);
667 if (!un || un->magic != DGAP_UNIT_MAGIC)
668 return (0);
669 ch = un->un_ch;
670 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
671 return (0);
672 bd = ch->ch_bd;
673 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
674 return (0);
675 if (bd->state != BOARD_READY)
676 return (0);
678 bn = bd->boardnum;
679 cn = ch->ch_portnum;
681 for (cptr = bd->bd_config; cptr; cptr = cptr->next) {
683 if ((cptr->type == BNODE) &&
684 ((cptr->u.board.type == APORT2_920P) || (cptr->u.board.type == APORT4_920P) ||
685 (cptr->u.board.type == APORT8_920P) || (cptr->u.board.type == PAPORT4) ||
686 (cptr->u.board.type == PAPORT8))) {
688 found = TRUE;
689 if (cptr->u.board.v_start)
690 starto = cptr->u.board.start;
691 else
692 starto = 1;
695 if (cptr->type == TNODE && found == TRUE) {
696 char *ptr1;
697 if (strstr(cptr->u.ttyname, "tty")) {
698 ptr1 = cptr->u.ttyname;
699 ptr1 += 3;
701 else {
702 ptr1 = cptr->u.ttyname;
705 for (i = 0; i < dgap_config_get_number_of_ports(bd); i++) {
706 if (cn == i) {
707 return snprintf(buf, PAGE_SIZE, "%s%s%02d\n",
708 (un->un_type == DGAP_PRINT) ? "pr" : "tty",
709 ptr1, i + starto);
714 if (cptr->type == CNODE) {
716 for (i = 0; i < cptr->u.conc.nport; i++) {
717 if (cn == (i + ncount)) {
719 return snprintf(buf, PAGE_SIZE, "%s%s%02d\n",
720 (un->un_type == DGAP_PRINT) ? "pr" : "tty",
721 cptr->u.conc.id,
722 i + (cptr->u.conc.v_start ? cptr->u.conc.start : 1));
726 ncount += cptr->u.conc.nport;
729 if (cptr->type == MNODE) {
731 for (i = 0; i < cptr->u.module.nport; i++) {
732 if (cn == (i + ncount)) {
733 return snprintf(buf, PAGE_SIZE, "%s%s%02d\n",
734 (un->un_type == DGAP_PRINT) ? "pr" : "tty",
735 cptr->u.module.id,
736 i + (cptr->u.module.v_start ? cptr->u.module.start : 1));
740 ncount += cptr->u.module.nport;
745 return snprintf(buf, PAGE_SIZE, "%s_dgap_%d_%d\n",
746 (un->un_type == DGAP_PRINT) ? "pr" : "tty", bn, cn);
749 static DEVICE_ATTR(custom_name, S_IRUSR, dgap_tty_name_show, NULL);
752 static struct attribute *dgap_sysfs_tty_entries[] = {
753 &dev_attr_state.attr,
754 &dev_attr_baud.attr,
755 &dev_attr_msignals.attr,
756 &dev_attr_iflag.attr,
757 &dev_attr_cflag.attr,
758 &dev_attr_oflag.attr,
759 &dev_attr_lflag.attr,
760 &dev_attr_digi_flag.attr,
761 &dev_attr_rxcount.attr,
762 &dev_attr_txcount.attr,
763 &dev_attr_custom_name.attr,
764 NULL
768 static struct attribute_group dgap_tty_attribute_group = {
769 .name = NULL,
770 .attrs = dgap_sysfs_tty_entries,
776 void dgap_create_tty_sysfs(struct un_t *un, struct device *c)
778 int ret;
780 ret = sysfs_create_group(&c->kobj, &dgap_tty_attribute_group);
781 if (ret) {
782 printk(KERN_ERR "dgap: failed to create sysfs tty device attributes.\n");
783 sysfs_remove_group(&c->kobj, &dgap_tty_attribute_group);
784 return;
787 dev_set_drvdata(c, un);
792 void dgap_remove_tty_sysfs(struct device *c)
794 sysfs_remove_group(&c->kobj, &dgap_tty_attribute_group);