Correct .gbs.conf settings
[platform/adaptation/renesas_rcar/renesas_kernel.git] / drivers / staging / dgap / dgap_sysfs.c
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.
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
12  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
13  * PURPOSE.  See the GNU General Public License for more details.
14  *
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.
18  *
19  * 
20  *      NOTE TO LINUX KERNEL HACKERS:  DO NOT REFORMAT THIS CODE!
21  *
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.
26  *
27  *      Send any bug fixes/changes to:  Eng.Linux at digi dot com.
28  *      Thank you.
29  *
30  *
31  * 
32  * $Id: dgap_sysfs.c,v 1.1 2009/10/23 14:01:57 markh Exp $   
33  */
34
35
36 #include <linux/kernel.h>
37 #include <linux/module.h>
38 #include <linux/ctype.h>
39 #include <linux/string.h>
40 #include <linux/serial_reg.h>
41 #include <linux/device.h>
42 #include <linux/pci.h>
43 #include <linux/kdev_t.h>
44   
45 #include "dgap_driver.h"
46 #include "dgap_conf.h"
47 #include "dgap_parse.h"
48
49
50 static ssize_t dgap_driver_version_show(struct device_driver *ddp, char *buf)
51 {
52         return snprintf(buf, PAGE_SIZE, "%s\n", DG_PART);
53 }
54 static DRIVER_ATTR(version, S_IRUSR, dgap_driver_version_show, NULL);
55
56
57 static ssize_t dgap_driver_boards_show(struct device_driver *ddp, char *buf)
58 {
59         return snprintf(buf, PAGE_SIZE, "%d\n", dgap_NumBoards);
60 }
61 static DRIVER_ATTR(boards, S_IRUSR, dgap_driver_boards_show, NULL);
62
63
64 static ssize_t dgap_driver_maxboards_show(struct device_driver *ddp, char *buf)
65 {
66         return snprintf(buf, PAGE_SIZE, "%d\n", MAXBOARDS);
67 }
68 static DRIVER_ATTR(maxboards, S_IRUSR, dgap_driver_maxboards_show, NULL);
69
70
71 static ssize_t dgap_driver_pollcounter_show(struct device_driver *ddp, char *buf)
72 {
73         return snprintf(buf, PAGE_SIZE, "%ld\n", dgap_poll_counter);
74 }
75 static DRIVER_ATTR(pollcounter, S_IRUSR, dgap_driver_pollcounter_show, NULL);
76
77
78 static ssize_t dgap_driver_state_show(struct device_driver *ddp, char *buf)
79 {
80         return snprintf(buf, PAGE_SIZE, "%s\n", dgap_driver_state_text[dgap_driver_state]);
81 }
82 static DRIVER_ATTR(state, S_IRUSR, dgap_driver_state_show, NULL);
83
84
85 static ssize_t dgap_driver_debug_show(struct device_driver *ddp, char *buf)
86 {
87         return snprintf(buf, PAGE_SIZE, "0x%x\n", dgap_debug);
88 }
89
90 static ssize_t dgap_driver_debug_store(struct device_driver *ddp, const char *buf, size_t count)
91 {
92         sscanf(buf, "0x%x\n", &dgap_debug);
93         return count;
94 }
95 static DRIVER_ATTR(debug, (S_IRUSR | S_IWUSR), dgap_driver_debug_show, dgap_driver_debug_store);
96
97
98 static ssize_t dgap_driver_rawreadok_show(struct device_driver *ddp, char *buf)
99 {
100         return snprintf(buf, PAGE_SIZE, "0x%x\n", dgap_rawreadok);
101 }
102
103 static ssize_t dgap_driver_rawreadok_store(struct device_driver *ddp, const char *buf, size_t count)
104 {
105         sscanf(buf, "0x%x\n", &dgap_rawreadok);
106         return count;
107 }
108 static DRIVER_ATTR(rawreadok, (S_IRUSR | S_IWUSR), dgap_driver_rawreadok_show, dgap_driver_rawreadok_store);
109
110
111 static ssize_t dgap_driver_pollrate_show(struct device_driver *ddp, char *buf)
112 {
113         return snprintf(buf, PAGE_SIZE, "%dms\n", dgap_poll_tick);
114 }
115
116 static ssize_t dgap_driver_pollrate_store(struct device_driver *ddp, const char *buf, size_t count)
117 {
118         sscanf(buf, "%d\n", &dgap_poll_tick);
119         return count;
120 }
121 static DRIVER_ATTR(pollrate, (S_IRUSR | S_IWUSR), dgap_driver_pollrate_show, dgap_driver_pollrate_store);
122
123
124 void dgap_create_driver_sysfiles(struct pci_driver *dgap_driver)
125 {
126         int rc = 0;
127         struct device_driver *driverfs = &dgap_driver->driver;
128
129         rc |= driver_create_file(driverfs, &driver_attr_version);
130         rc |= driver_create_file(driverfs, &driver_attr_boards);
131         rc |= driver_create_file(driverfs, &driver_attr_maxboards);
132         rc |= driver_create_file(driverfs, &driver_attr_debug);
133         rc |= driver_create_file(driverfs, &driver_attr_rawreadok); 
134         rc |= driver_create_file(driverfs, &driver_attr_pollrate);
135         rc |= driver_create_file(driverfs, &driver_attr_pollcounter);
136         rc |= driver_create_file(driverfs, &driver_attr_state);
137         if (rc) {
138                 printk(KERN_ERR "DGAP: sysfs driver_create_file failed!\n");
139         }
140 }
141
142
143 void dgap_remove_driver_sysfiles(struct pci_driver *dgap_driver)
144 {
145         struct device_driver *driverfs = &dgap_driver->driver;
146         driver_remove_file(driverfs, &driver_attr_version);
147         driver_remove_file(driverfs, &driver_attr_boards);
148         driver_remove_file(driverfs, &driver_attr_maxboards);
149         driver_remove_file(driverfs, &driver_attr_debug);
150         driver_remove_file(driverfs, &driver_attr_rawreadok);
151         driver_remove_file(driverfs, &driver_attr_pollrate);
152         driver_remove_file(driverfs, &driver_attr_pollcounter);
153         driver_remove_file(driverfs, &driver_attr_state);
154 }
155
156
157 #define DGAP_VERIFY_BOARD(p, bd)                        \
158         if (!p)                                         \
159                 return (0);                             \
160                                                         \
161         bd = dev_get_drvdata(p);                        \
162         if (!bd || bd->magic != DGAP_BOARD_MAGIC)       \
163                 return (0);                             \
164         if (bd->state != BOARD_READY)                   \
165                 return (0);                             \
166
167
168 static ssize_t dgap_ports_state_show(struct device *p, struct device_attribute *attr, char *buf)
169 {
170         struct board_t *bd;
171         int count = 0;
172         int i = 0;
173
174         DGAP_VERIFY_BOARD(p, bd);
175
176         for (i = 0; i < bd->nasync; i++) {
177                 count += snprintf(buf + count, PAGE_SIZE - count,
178                         "%d %s\n", bd->channels[i]->ch_portnum,
179                         bd->channels[i]->ch_open_count ? "Open" : "Closed");
180         }
181         return count;
182 }
183 static DEVICE_ATTR(ports_state, S_IRUSR, dgap_ports_state_show, NULL);
184
185
186 static ssize_t dgap_ports_baud_show(struct device *p, struct device_attribute *attr, char *buf)
187 {
188         struct board_t *bd;
189         int count = 0;
190         int i = 0;
191
192         DGAP_VERIFY_BOARD(p, bd);
193
194         for (i = 0; i < bd->nasync; i++) {
195                 count +=  snprintf(buf + count, PAGE_SIZE - count,
196                         "%d %d\n", bd->channels[i]->ch_portnum, bd->channels[i]->ch_baud_info);
197         }
198         return count;
199 }
200 static DEVICE_ATTR(ports_baud, S_IRUSR, dgap_ports_baud_show, NULL);
201
202
203 static ssize_t dgap_ports_msignals_show(struct device *p, struct device_attribute *attr, char *buf)
204 {
205         struct board_t *bd;
206         int count = 0;
207         int i = 0;
208
209         DGAP_VERIFY_BOARD(p, bd);
210
211         for (i = 0; i < bd->nasync; i++) {
212                 if (bd->channels[i]->ch_open_count) {
213                         count += snprintf(buf + count, PAGE_SIZE - count,
214                                 "%d %s %s %s %s %s %s\n", bd->channels[i]->ch_portnum,
215                                 (bd->channels[i]->ch_mostat & UART_MCR_RTS) ? "RTS" : "",
216                                 (bd->channels[i]->ch_mistat & UART_MSR_CTS) ? "CTS" : "",
217                                 (bd->channels[i]->ch_mostat & UART_MCR_DTR) ? "DTR" : "",
218                                 (bd->channels[i]->ch_mistat & UART_MSR_DSR) ? "DSR" : "",
219                                 (bd->channels[i]->ch_mistat & UART_MSR_DCD) ? "DCD" : "",
220                                 (bd->channels[i]->ch_mistat & UART_MSR_RI)  ? "RI"  : "");
221                 } else {
222                         count += snprintf(buf + count, PAGE_SIZE - count,
223                                 "%d\n", bd->channels[i]->ch_portnum);
224                 }
225         }
226         return count;
227 }
228 static DEVICE_ATTR(ports_msignals, S_IRUSR, dgap_ports_msignals_show, NULL);
229
230
231 static ssize_t dgap_ports_iflag_show(struct device *p, struct device_attribute *attr, char *buf)
232 {
233         struct board_t *bd;
234         int count = 0;
235         int i = 0;
236
237         DGAP_VERIFY_BOARD(p, bd);
238
239         for (i = 0; i < bd->nasync; i++) {
240                 count += snprintf(buf + count, PAGE_SIZE - count, "%d %x\n",
241                         bd->channels[i]->ch_portnum, bd->channels[i]->ch_c_iflag);
242         }
243         return count;
244 }
245 static DEVICE_ATTR(ports_iflag, S_IRUSR, dgap_ports_iflag_show, NULL);
246
247
248 static ssize_t dgap_ports_cflag_show(struct device *p, struct device_attribute *attr, char *buf)
249 {
250         struct board_t *bd;
251         int count = 0;
252         int i = 0;
253
254         DGAP_VERIFY_BOARD(p, bd);
255
256         for (i = 0; i < bd->nasync; i++) {
257                 count += snprintf(buf + count, PAGE_SIZE - count, "%d %x\n",
258                         bd->channels[i]->ch_portnum, bd->channels[i]->ch_c_cflag);
259         }
260         return count;
261 }
262 static DEVICE_ATTR(ports_cflag, S_IRUSR, dgap_ports_cflag_show, NULL);
263
264
265 static ssize_t dgap_ports_oflag_show(struct device *p, struct device_attribute *attr, char *buf)
266 {
267         struct board_t *bd;
268         int count = 0;
269         int i = 0;
270
271         DGAP_VERIFY_BOARD(p, bd);
272
273         for (i = 0; i < bd->nasync; i++) {
274                 count += snprintf(buf + count, PAGE_SIZE - count, "%d %x\n",
275                         bd->channels[i]->ch_portnum, bd->channels[i]->ch_c_oflag);
276         }
277         return count;
278 }
279 static DEVICE_ATTR(ports_oflag, S_IRUSR, dgap_ports_oflag_show, NULL);
280
281
282 static ssize_t dgap_ports_lflag_show(struct device *p, struct device_attribute *attr, char *buf)
283 {
284         struct board_t *bd;
285         int count = 0;
286         int i = 0;
287
288         DGAP_VERIFY_BOARD(p, bd);
289
290         for (i = 0; i < bd->nasync; i++) {
291                 count += snprintf(buf + count, PAGE_SIZE - count, "%d %x\n",
292                         bd->channels[i]->ch_portnum, bd->channels[i]->ch_c_lflag);
293         }
294         return count;
295 }
296 static DEVICE_ATTR(ports_lflag, S_IRUSR, dgap_ports_lflag_show, NULL);
297
298
299 static ssize_t dgap_ports_digi_flag_show(struct device *p, struct device_attribute *attr, char *buf)
300 {
301         struct board_t *bd;
302         int count = 0;
303         int i = 0;
304
305         DGAP_VERIFY_BOARD(p, bd);
306
307         for (i = 0; i < bd->nasync; i++) {
308                 count += snprintf(buf + count, PAGE_SIZE - count, "%d %x\n",
309                         bd->channels[i]->ch_portnum, bd->channels[i]->ch_digi.digi_flags);
310         }
311         return count;
312 }
313 static DEVICE_ATTR(ports_digi_flag, S_IRUSR, dgap_ports_digi_flag_show, NULL);
314
315
316 static ssize_t dgap_ports_rxcount_show(struct device *p, struct device_attribute *attr, char *buf)
317 {
318         struct board_t *bd;
319         int count = 0;
320         int i = 0;
321
322         DGAP_VERIFY_BOARD(p, bd);
323
324         for (i = 0; i < bd->nasync; i++) {
325                 count += snprintf(buf + count, PAGE_SIZE - count, "%d %ld\n",
326                         bd->channels[i]->ch_portnum, bd->channels[i]->ch_rxcount);
327         }
328         return count;
329 }
330 static DEVICE_ATTR(ports_rxcount, S_IRUSR, dgap_ports_rxcount_show, NULL);
331
332
333 static ssize_t dgap_ports_txcount_show(struct device *p, struct device_attribute *attr, char *buf)
334 {
335         struct board_t *bd;
336         int count = 0;
337         int i = 0;
338
339         DGAP_VERIFY_BOARD(p, bd);
340
341         for (i = 0; i < bd->nasync; i++) {
342                 count += snprintf(buf + count, PAGE_SIZE - count, "%d %ld\n",
343                         bd->channels[i]->ch_portnum, bd->channels[i]->ch_txcount);
344         }
345         return count;
346 }
347 static DEVICE_ATTR(ports_txcount, S_IRUSR, dgap_ports_txcount_show, NULL);
348
349
350 /* this function creates the sys files that will export each signal status
351  * to sysfs each value will be put in a separate filename
352  */
353 void dgap_create_ports_sysfiles(struct board_t *bd)
354 {
355         int rc = 0;
356
357         dev_set_drvdata(&bd->pdev->dev, bd);
358         rc |= device_create_file(&(bd->pdev->dev), &dev_attr_ports_state);
359         rc |= device_create_file(&(bd->pdev->dev), &dev_attr_ports_baud);
360         rc |= device_create_file(&(bd->pdev->dev), &dev_attr_ports_msignals);
361         rc |= device_create_file(&(bd->pdev->dev), &dev_attr_ports_iflag);
362         rc |= device_create_file(&(bd->pdev->dev), &dev_attr_ports_cflag);
363         rc |= device_create_file(&(bd->pdev->dev), &dev_attr_ports_oflag);
364         rc |= device_create_file(&(bd->pdev->dev), &dev_attr_ports_lflag);
365         rc |= device_create_file(&(bd->pdev->dev), &dev_attr_ports_digi_flag);
366         rc |= device_create_file(&(bd->pdev->dev), &dev_attr_ports_rxcount);
367         rc |= device_create_file(&(bd->pdev->dev), &dev_attr_ports_txcount);
368         if (rc) {
369                 printk(KERN_ERR "DGAP: sysfs device_create_file failed!\n");
370         }
371 }
372
373
374 /* removes all the sys files created for that port */
375 void dgap_remove_ports_sysfiles(struct board_t *bd)
376 {
377         device_remove_file(&(bd->pdev->dev), &dev_attr_ports_state);
378         device_remove_file(&(bd->pdev->dev), &dev_attr_ports_baud);
379         device_remove_file(&(bd->pdev->dev), &dev_attr_ports_msignals);
380         device_remove_file(&(bd->pdev->dev), &dev_attr_ports_iflag);
381         device_remove_file(&(bd->pdev->dev), &dev_attr_ports_cflag);
382         device_remove_file(&(bd->pdev->dev), &dev_attr_ports_oflag);
383         device_remove_file(&(bd->pdev->dev), &dev_attr_ports_lflag);
384         device_remove_file(&(bd->pdev->dev), &dev_attr_ports_digi_flag);
385         device_remove_file(&(bd->pdev->dev), &dev_attr_ports_rxcount);
386         device_remove_file(&(bd->pdev->dev), &dev_attr_ports_txcount);
387 }
388
389
390 static ssize_t dgap_tty_state_show(struct device *d, struct device_attribute *attr, char *buf)
391 {
392         struct board_t *bd;
393         struct channel_t *ch;
394         struct un_t *un;
395
396         if (!d)
397                 return (0);
398         un = dev_get_drvdata(d);
399         if (!un || un->magic != DGAP_UNIT_MAGIC)
400                 return (0);
401         ch = un->un_ch;
402         if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
403                 return (0);
404         bd = ch->ch_bd;
405         if (!bd || bd->magic != DGAP_BOARD_MAGIC)
406                 return (0);
407         if (bd->state != BOARD_READY)
408                 return (0);
409
410         return snprintf(buf, PAGE_SIZE, "%s", un->un_open_count ? "Open" : "Closed");
411 }
412 static DEVICE_ATTR(state, S_IRUSR, dgap_tty_state_show, NULL);
413
414
415 static ssize_t dgap_tty_baud_show(struct device *d, struct device_attribute *attr, char *buf)
416 {
417         struct board_t *bd;
418         struct channel_t *ch;
419         struct un_t *un;
420
421         if (!d)
422                 return (0);
423         un = dev_get_drvdata(d);
424         if (!un || un->magic != DGAP_UNIT_MAGIC)
425                 return (0);
426         ch = un->un_ch;
427         if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
428                 return (0);
429         bd = ch->ch_bd;
430         if (!bd || bd->magic != DGAP_BOARD_MAGIC)
431                 return (0);
432         if (bd->state != BOARD_READY)
433                 return (0);
434
435         return snprintf(buf, PAGE_SIZE, "%d\n", ch->ch_baud_info);
436 }
437 static DEVICE_ATTR(baud, S_IRUSR, dgap_tty_baud_show, NULL);
438
439
440 static ssize_t dgap_tty_msignals_show(struct device *d, struct device_attribute *attr, char *buf)
441 {
442         struct board_t *bd;
443         struct channel_t *ch;
444         struct un_t *un;
445
446         if (!d)
447                 return (0);
448         un = dev_get_drvdata(d);
449         if (!un || un->magic != DGAP_UNIT_MAGIC)
450                 return (0);
451         ch = un->un_ch;
452         if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
453                 return (0);
454         bd = ch->ch_bd;
455         if (!bd || bd->magic != DGAP_BOARD_MAGIC)
456                 return (0);
457         if (bd->state != BOARD_READY)
458                 return (0);
459
460         if (ch->ch_open_count) {
461                 return snprintf(buf, PAGE_SIZE, "%s %s %s %s %s %s\n",
462                         (ch->ch_mostat & UART_MCR_RTS) ? "RTS" : "",
463                         (ch->ch_mistat & UART_MSR_CTS) ? "CTS" : "",
464                         (ch->ch_mostat & UART_MCR_DTR) ? "DTR" : "",
465                         (ch->ch_mistat & UART_MSR_DSR) ? "DSR" : "",
466                         (ch->ch_mistat & UART_MSR_DCD) ? "DCD" : "",
467                         (ch->ch_mistat & UART_MSR_RI)  ? "RI"  : "");
468         }
469         return 0;
470 }
471 static DEVICE_ATTR(msignals, S_IRUSR, dgap_tty_msignals_show, NULL);
472
473
474 static ssize_t dgap_tty_iflag_show(struct device *d, struct device_attribute *attr, char *buf)
475 {
476         struct board_t *bd;
477         struct channel_t *ch;
478         struct un_t *un;
479
480         if (!d)
481                 return (0);
482         un = dev_get_drvdata(d);
483         if (!un || un->magic != DGAP_UNIT_MAGIC)
484                 return (0);
485         ch = un->un_ch;
486         if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
487                 return (0);
488         bd = ch->ch_bd;
489         if (!bd || bd->magic != DGAP_BOARD_MAGIC)
490                 return (0);
491         if (bd->state != BOARD_READY)
492                 return (0);
493
494         return snprintf(buf, PAGE_SIZE, "%x\n", ch->ch_c_iflag);
495 }
496 static DEVICE_ATTR(iflag, S_IRUSR, dgap_tty_iflag_show, NULL);
497
498
499 static ssize_t dgap_tty_cflag_show(struct device *d, struct device_attribute *attr, char *buf)
500 {
501         struct board_t *bd;
502         struct channel_t *ch;
503         struct un_t *un;
504
505         if (!d)
506                 return (0);
507         un = dev_get_drvdata(d);
508         if (!un || un->magic != DGAP_UNIT_MAGIC)
509                 return (0);
510         ch = un->un_ch;
511         if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
512                 return (0);
513         bd = ch->ch_bd;
514         if (!bd || bd->magic != DGAP_BOARD_MAGIC)
515                 return (0);
516         if (bd->state != BOARD_READY)
517                 return (0);
518
519         return snprintf(buf, PAGE_SIZE, "%x\n", ch->ch_c_cflag);
520 }
521 static DEVICE_ATTR(cflag, S_IRUSR, dgap_tty_cflag_show, NULL);
522
523
524 static ssize_t dgap_tty_oflag_show(struct device *d, struct device_attribute *attr, char *buf)
525 {
526         struct board_t *bd;
527         struct channel_t *ch;
528         struct un_t *un;
529
530         if (!d)
531                 return (0);
532         un = dev_get_drvdata(d);
533         if (!un || un->magic != DGAP_UNIT_MAGIC)
534                 return (0);
535         ch = un->un_ch;
536         if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
537                 return (0);
538         bd = ch->ch_bd;
539         if (!bd || bd->magic != DGAP_BOARD_MAGIC)
540                 return (0);
541         if (bd->state != BOARD_READY)
542                 return (0);
543
544         return snprintf(buf, PAGE_SIZE, "%x\n", ch->ch_c_oflag);
545 }
546 static DEVICE_ATTR(oflag, S_IRUSR, dgap_tty_oflag_show, NULL);
547
548
549 static ssize_t dgap_tty_lflag_show(struct device *d, struct device_attribute *attr, char *buf)
550 {
551         struct board_t *bd;
552         struct channel_t *ch;
553         struct un_t *un;
554
555         if (!d)
556                 return (0);
557         un = dev_get_drvdata(d);
558         if (!un || un->magic != DGAP_UNIT_MAGIC)
559                 return (0);
560         ch = un->un_ch;
561         if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
562                 return (0);
563         bd = ch->ch_bd;
564         if (!bd || bd->magic != DGAP_BOARD_MAGIC)
565                 return (0);
566         if (bd->state != BOARD_READY)
567                 return (0);
568
569         return snprintf(buf, PAGE_SIZE, "%x\n", ch->ch_c_lflag);
570 }
571 static DEVICE_ATTR(lflag, S_IRUSR, dgap_tty_lflag_show, NULL);
572
573
574 static ssize_t dgap_tty_digi_flag_show(struct device *d, struct device_attribute *attr, char *buf)
575 {
576         struct board_t *bd;
577         struct channel_t *ch;
578         struct un_t *un;
579
580         if (!d)
581                 return (0);
582         un = dev_get_drvdata(d);
583         if (!un || un->magic != DGAP_UNIT_MAGIC)
584                 return (0);
585         ch = un->un_ch;
586         if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
587                 return (0);
588         bd = ch->ch_bd;
589         if (!bd || bd->magic != DGAP_BOARD_MAGIC)
590                 return (0);
591         if (bd->state != BOARD_READY)
592                 return (0);
593
594         return snprintf(buf, PAGE_SIZE, "%x\n", ch->ch_digi.digi_flags);
595 }
596 static DEVICE_ATTR(digi_flag, S_IRUSR, dgap_tty_digi_flag_show, NULL);
597
598
599 static ssize_t dgap_tty_rxcount_show(struct device *d, struct device_attribute *attr, char *buf)
600 {
601         struct board_t *bd;
602         struct channel_t *ch;
603         struct un_t *un;
604
605         if (!d)
606                 return (0);
607         un = dev_get_drvdata(d);
608         if (!un || un->magic != DGAP_UNIT_MAGIC)
609                 return (0);
610         ch = un->un_ch;
611         if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
612                 return (0);
613         bd = ch->ch_bd;
614         if (!bd || bd->magic != DGAP_BOARD_MAGIC)
615                 return (0);
616         if (bd->state != BOARD_READY)
617                 return (0);
618
619         return snprintf(buf, PAGE_SIZE, "%ld\n", ch->ch_rxcount);
620 }
621 static DEVICE_ATTR(rxcount, S_IRUSR, dgap_tty_rxcount_show, NULL);
622
623
624 static ssize_t dgap_tty_txcount_show(struct device *d, struct device_attribute *attr, char *buf)
625 {
626         struct board_t *bd;
627         struct channel_t *ch;
628         struct un_t *un;
629
630         if (!d)
631                 return (0);
632         un = dev_get_drvdata(d);
633         if (!un || un->magic != DGAP_UNIT_MAGIC)
634                 return (0);
635         ch = un->un_ch;
636         if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
637                 return (0);
638         bd = ch->ch_bd;
639         if (!bd || bd->magic != DGAP_BOARD_MAGIC)
640                 return (0);
641         if (bd->state != BOARD_READY)
642                 return (0);
643
644         return snprintf(buf, PAGE_SIZE, "%ld\n", ch->ch_txcount);
645 }
646 static DEVICE_ATTR(txcount, S_IRUSR, dgap_tty_txcount_show, NULL);
647
648
649 static ssize_t dgap_tty_name_show(struct device *d, struct device_attribute *attr, char *buf)
650 {
651         struct board_t *bd;
652         struct channel_t *ch;
653         struct un_t *un;
654         int     cn;
655         int     bn;
656         struct cnode *cptr = NULL;
657         int found = FALSE;
658         int ncount = 0;
659         int starto = 0;
660         int i = 0;
661
662         if (!d)
663                 return (0);
664         un = dev_get_drvdata(d);
665         if (!un || un->magic != DGAP_UNIT_MAGIC)
666                 return (0);
667         ch = un->un_ch;
668         if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
669                 return (0);
670         bd = ch->ch_bd;
671         if (!bd || bd->magic != DGAP_BOARD_MAGIC)
672                 return (0);
673         if (bd->state != BOARD_READY)
674                 return (0);
675
676         bn = bd->boardnum;
677         cn = ch->ch_portnum;
678
679         for (cptr = bd->bd_config; cptr; cptr = cptr->next) {
680
681                 if ((cptr->type == BNODE) &&
682                     ((cptr->u.board.type == APORT2_920P) || (cptr->u.board.type == APORT4_920P) ||
683                      (cptr->u.board.type == APORT8_920P) || (cptr->u.board.type == PAPORT4) ||
684                      (cptr->u.board.type == PAPORT8))) {
685
686                                 found = TRUE;
687                                 if (cptr->u.board.v_start)
688                                         starto = cptr->u.board.start;
689                                 else
690                                         starto = 1;
691                 }
692
693                 if (cptr->type == TNODE && found == TRUE) {
694                         char *ptr1;
695                         if (strstr(cptr->u.ttyname, "tty")) {
696                                 ptr1 = cptr->u.ttyname;
697                                 ptr1 += 3;
698                         }
699                         else {
700                                 ptr1 = cptr->u.ttyname;
701                         }
702
703                         for (i = 0; i < dgap_config_get_number_of_ports(bd); i++) {
704                                 if (cn == i) {
705                                         return snprintf(buf, PAGE_SIZE, "%s%s%02d\n",
706                                                 (un->un_type == DGAP_PRINT) ? "pr" : "tty",
707                                                 ptr1, i + starto);
708                                 }
709                         }
710                 }
711
712                 if (cptr->type == CNODE) {
713
714                         for (i = 0; i < cptr->u.conc.nport; i++) {
715                                 if (cn == (i + ncount)) {
716
717                                         return snprintf(buf, PAGE_SIZE, "%s%s%02d\n",
718                                                 (un->un_type == DGAP_PRINT) ? "pr" : "tty",
719                                                 cptr->u.conc.id,
720                                                 i + (cptr->u.conc.v_start ? cptr->u.conc.start : 1));
721                                 }
722                         }
723
724                         ncount += cptr->u.conc.nport;
725                 }
726
727                 if (cptr->type == MNODE) {
728
729                         for (i = 0; i < cptr->u.module.nport; i++) {
730                                 if (cn == (i + ncount)) {
731                                         return snprintf(buf, PAGE_SIZE, "%s%s%02d\n",
732                                                 (un->un_type == DGAP_PRINT) ? "pr" : "tty",
733                                                 cptr->u.module.id,
734                                                 i + (cptr->u.module.v_start ? cptr->u.module.start : 1));
735                                 }
736                         }
737
738                         ncount += cptr->u.module.nport;
739
740                 }
741         }
742
743         return snprintf(buf, PAGE_SIZE, "%s_dgap_%d_%d\n",
744                 (un->un_type == DGAP_PRINT) ? "pr" : "tty", bn, cn);
745
746 }
747 static DEVICE_ATTR(custom_name, S_IRUSR, dgap_tty_name_show, NULL);
748
749
750 static struct attribute *dgap_sysfs_tty_entries[] = {
751         &dev_attr_state.attr,
752         &dev_attr_baud.attr,
753         &dev_attr_msignals.attr,
754         &dev_attr_iflag.attr,
755         &dev_attr_cflag.attr,
756         &dev_attr_oflag.attr,
757         &dev_attr_lflag.attr,
758         &dev_attr_digi_flag.attr,
759         &dev_attr_rxcount.attr,
760         &dev_attr_txcount.attr,
761         &dev_attr_custom_name.attr,
762         NULL
763 };
764
765
766 static struct attribute_group dgap_tty_attribute_group = {
767         .name = NULL,
768         .attrs = dgap_sysfs_tty_entries,
769 };
770
771
772
773
774 void dgap_create_tty_sysfs(struct un_t *un, struct device *c)
775 {
776         int ret;
777
778         ret = sysfs_create_group(&c->kobj, &dgap_tty_attribute_group);
779         if (ret) {
780                 printk(KERN_ERR "dgap: failed to create sysfs tty device attributes.\n");
781                 sysfs_remove_group(&c->kobj, &dgap_tty_attribute_group);
782                 return;
783         }
784
785         dev_set_drvdata(c, un);
786
787 }
788
789
790 void dgap_remove_tty_sysfs(struct device *c)
791 {
792         sysfs_remove_group(&c->kobj, &dgap_tty_attribute_group);
793 }