2 * Copyright 2004 Digi International (www.digi.com)
3 * Scott H Kilau <Scott_Kilau at digi dot com>
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)
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.
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
);
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
);
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
);
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
)
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
);
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) \
163 bd = dev_get_drvdata(p); \
164 if (!bd || bd->magic != DGAP_BOARD_MAGIC) \
166 if (bd->state != BOARD_READY) \
170 static ssize_t dgap_ports_state_show(struct device *p, struct device_attribute *attr, char *buf)
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");
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
)
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
);
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
)
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" : "");
224 count
+= snprintf(buf
+ count
, PAGE_SIZE
- count
,
225 "%d\n", bd
->channels
[i
]->ch_portnum
);
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
)
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
);
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
)
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
);
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
)
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
);
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
)
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
);
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
)
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
);
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
)
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
);
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
)
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
);
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
)
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
);
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
)
395 struct channel_t
*ch
;
400 un
= (struct un_t
*) dev_get_drvdata(d
);
401 if (!un
|| un
->magic
!= DGAP_UNIT_MAGIC
)
404 if (!ch
|| ch
->magic
!= DGAP_CHANNEL_MAGIC
)
407 if (!bd
|| bd
->magic
!= DGAP_BOARD_MAGIC
)
409 if (bd
->state
!= BOARD_READY
)
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
)
420 struct channel_t
*ch
;
425 un
= (struct un_t
*) dev_get_drvdata(d
);
426 if (!un
|| un
->magic
!= DGAP_UNIT_MAGIC
)
429 if (!ch
|| ch
->magic
!= DGAP_CHANNEL_MAGIC
)
432 if (!bd
|| bd
->magic
!= DGAP_BOARD_MAGIC
)
434 if (bd
->state
!= BOARD_READY
)
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
)
445 struct channel_t
*ch
;
450 un
= (struct un_t
*) dev_get_drvdata(d
);
451 if (!un
|| un
->magic
!= DGAP_UNIT_MAGIC
)
454 if (!ch
|| ch
->magic
!= DGAP_CHANNEL_MAGIC
)
457 if (!bd
|| bd
->magic
!= DGAP_BOARD_MAGIC
)
459 if (bd
->state
!= BOARD_READY
)
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" : "");
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
)
479 struct channel_t
*ch
;
484 un
= (struct un_t
*) dev_get_drvdata(d
);
485 if (!un
|| un
->magic
!= DGAP_UNIT_MAGIC
)
488 if (!ch
|| ch
->magic
!= DGAP_CHANNEL_MAGIC
)
491 if (!bd
|| bd
->magic
!= DGAP_BOARD_MAGIC
)
493 if (bd
->state
!= BOARD_READY
)
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
)
504 struct channel_t
*ch
;
509 un
= (struct un_t
*) dev_get_drvdata(d
);
510 if (!un
|| un
->magic
!= DGAP_UNIT_MAGIC
)
513 if (!ch
|| ch
->magic
!= DGAP_CHANNEL_MAGIC
)
516 if (!bd
|| bd
->magic
!= DGAP_BOARD_MAGIC
)
518 if (bd
->state
!= BOARD_READY
)
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
)
529 struct channel_t
*ch
;
534 un
= (struct un_t
*) dev_get_drvdata(d
);
535 if (!un
|| un
->magic
!= DGAP_UNIT_MAGIC
)
538 if (!ch
|| ch
->magic
!= DGAP_CHANNEL_MAGIC
)
541 if (!bd
|| bd
->magic
!= DGAP_BOARD_MAGIC
)
543 if (bd
->state
!= BOARD_READY
)
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
)
554 struct channel_t
*ch
;
559 un
= (struct un_t
*) dev_get_drvdata(d
);
560 if (!un
|| un
->magic
!= DGAP_UNIT_MAGIC
)
563 if (!ch
|| ch
->magic
!= DGAP_CHANNEL_MAGIC
)
566 if (!bd
|| bd
->magic
!= DGAP_BOARD_MAGIC
)
568 if (bd
->state
!= BOARD_READY
)
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
)
579 struct channel_t
*ch
;
584 un
= (struct un_t
*) dev_get_drvdata(d
);
585 if (!un
|| un
->magic
!= DGAP_UNIT_MAGIC
)
588 if (!ch
|| ch
->magic
!= DGAP_CHANNEL_MAGIC
)
591 if (!bd
|| bd
->magic
!= DGAP_BOARD_MAGIC
)
593 if (bd
->state
!= BOARD_READY
)
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
)
604 struct channel_t
*ch
;
609 un
= (struct un_t
*) dev_get_drvdata(d
);
610 if (!un
|| un
->magic
!= DGAP_UNIT_MAGIC
)
613 if (!ch
|| ch
->magic
!= DGAP_CHANNEL_MAGIC
)
616 if (!bd
|| bd
->magic
!= DGAP_BOARD_MAGIC
)
618 if (bd
->state
!= BOARD_READY
)
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
)
629 struct channel_t
*ch
;
634 un
= (struct un_t
*) dev_get_drvdata(d
);
635 if (!un
|| un
->magic
!= DGAP_UNIT_MAGIC
)
638 if (!ch
|| ch
->magic
!= DGAP_CHANNEL_MAGIC
)
641 if (!bd
|| bd
->magic
!= DGAP_BOARD_MAGIC
)
643 if (bd
->state
!= BOARD_READY
)
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
)
654 struct channel_t
*ch
;
658 struct cnode
*cptr
= NULL
;
666 un
= (struct un_t
*) dev_get_drvdata(d
);
667 if (!un
|| un
->magic
!= DGAP_UNIT_MAGIC
)
670 if (!ch
|| ch
->magic
!= DGAP_CHANNEL_MAGIC
)
673 if (!bd
|| bd
->magic
!= DGAP_BOARD_MAGIC
)
675 if (bd
->state
!= BOARD_READY
)
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
))) {
689 if (cptr
->u
.board
.v_start
)
690 starto
= cptr
->u
.board
.start
;
695 if (cptr
->type
== TNODE
&& found
== TRUE
) {
697 if (strstr(cptr
->u
.ttyname
, "tty")) {
698 ptr1
= cptr
->u
.ttyname
;
702 ptr1
= cptr
->u
.ttyname
;
705 for (i
= 0; i
< dgap_config_get_number_of_ports(bd
); i
++) {
707 return snprintf(buf
, PAGE_SIZE
, "%s%s%02d\n",
708 (un
->un_type
== DGAP_PRINT
) ? "pr" : "tty",
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",
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",
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
,
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
,
768 static struct attribute_group dgap_tty_attribute_group
= {
770 .attrs
= dgap_sysfs_tty_entries
,
776 void dgap_create_tty_sysfs(struct un_t
*un
, struct device
*c
)
780 ret
= sysfs_create_group(&c
->kobj
, &dgap_tty_attribute_group
);
782 printk(KERN_ERR
"dgap: failed to create sysfs tty device attributes.\n");
783 sysfs_remove_group(&c
->kobj
, &dgap_tty_attribute_group
);
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
);