60d247b72b9ba93c91f78ad1e4f45ca294b8b7ca
[deliverable/linux.git] / drivers / staging / dgnc / dgnc_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
33 #include <linux/kernel.h>
34 #include <linux/module.h>
35 #include <linux/ctype.h>
36 #include <linux/string.h>
37 #include <linux/serial_reg.h>
38 #include <linux/device.h>
39 #include <linux/pci.h>
40 #include <linux/kdev_t.h>
41
42 #include "dgnc_driver.h"
43 #include "dgnc_mgmt.h"
44
45
46 static ssize_t dgnc_driver_version_show(struct device_driver *ddp, char *buf)
47 {
48 return snprintf(buf, PAGE_SIZE, "%s\n", DG_PART);
49 }
50 static DRIVER_ATTR(version, S_IRUSR, dgnc_driver_version_show, NULL);
51
52
53 static ssize_t dgnc_driver_boards_show(struct device_driver *ddp, char *buf)
54 {
55 return snprintf(buf, PAGE_SIZE, "%d\n", dgnc_NumBoards);
56 }
57 static DRIVER_ATTR(boards, S_IRUSR, dgnc_driver_boards_show, NULL);
58
59
60 static ssize_t dgnc_driver_maxboards_show(struct device_driver *ddp, char *buf)
61 {
62 return snprintf(buf, PAGE_SIZE, "%d\n", MAXBOARDS);
63 }
64 static DRIVER_ATTR(maxboards, S_IRUSR, dgnc_driver_maxboards_show, NULL);
65
66 static ssize_t dgnc_driver_debug_show(struct device_driver *ddp, char *buf)
67 {
68 return snprintf(buf, PAGE_SIZE, "0x%x\n", dgnc_debug);
69 }
70
71 static ssize_t dgnc_driver_debug_store(struct device_driver *ddp, const char *buf, size_t count)
72 {
73 sscanf(buf, "0x%x\n", &dgnc_debug);
74 return count;
75 }
76 static DRIVER_ATTR(debug, (S_IRUSR | S_IWUSR), dgnc_driver_debug_show, dgnc_driver_debug_store);
77
78
79 static ssize_t dgnc_driver_rawreadok_show(struct device_driver *ddp, char *buf)
80 {
81 return snprintf(buf, PAGE_SIZE, "0x%x\n", dgnc_rawreadok);
82 }
83
84 static ssize_t dgnc_driver_rawreadok_store(struct device_driver *ddp, const char *buf, size_t count)
85 {
86 sscanf(buf, "0x%x\n", &dgnc_rawreadok);
87 return count;
88 }
89 static DRIVER_ATTR(rawreadok, (S_IRUSR | S_IWUSR), dgnc_driver_rawreadok_show, dgnc_driver_rawreadok_store);
90
91
92 static ssize_t dgnc_driver_pollrate_show(struct device_driver *ddp, char *buf)
93 {
94 return snprintf(buf, PAGE_SIZE, "%dms\n", dgnc_poll_tick);
95 }
96
97 static ssize_t dgnc_driver_pollrate_store(struct device_driver *ddp, const char *buf, size_t count)
98 {
99 sscanf(buf, "%d\n", &dgnc_poll_tick);
100 return count;
101 }
102 static DRIVER_ATTR(pollrate, (S_IRUSR | S_IWUSR), dgnc_driver_pollrate_show, dgnc_driver_pollrate_store);
103
104
105 void dgnc_create_driver_sysfiles(struct pci_driver *dgnc_driver)
106 {
107 int rc = 0;
108 struct device_driver *driverfs = &dgnc_driver->driver;
109
110 rc |= driver_create_file(driverfs, &driver_attr_version);
111 rc |= driver_create_file(driverfs, &driver_attr_boards);
112 rc |= driver_create_file(driverfs, &driver_attr_maxboards);
113 rc |= driver_create_file(driverfs, &driver_attr_debug);
114 rc |= driver_create_file(driverfs, &driver_attr_rawreadok);
115 rc |= driver_create_file(driverfs, &driver_attr_pollrate);
116 if (rc) {
117 printk(KERN_ERR "DGNC: sysfs driver_create_file failed!\n");
118 }
119 }
120
121
122 void dgnc_remove_driver_sysfiles(struct pci_driver *dgnc_driver)
123 {
124 struct device_driver *driverfs = &dgnc_driver->driver;
125 driver_remove_file(driverfs, &driver_attr_version);
126 driver_remove_file(driverfs, &driver_attr_boards);
127 driver_remove_file(driverfs, &driver_attr_maxboards);
128 driver_remove_file(driverfs, &driver_attr_debug);
129 driver_remove_file(driverfs, &driver_attr_rawreadok);
130 driver_remove_file(driverfs, &driver_attr_pollrate);
131 }
132
133
134 #define DGNC_VERIFY_BOARD(p, bd) \
135 do { \
136 if (!p) \
137 return 0; \
138 \
139 bd = dev_get_drvdata(p); \
140 if (!bd || bd->magic != DGNC_BOARD_MAGIC) \
141 return 0; \
142 if (bd->state != BOARD_READY) \
143 return 0; \
144 } while (0)
145
146
147
148 static ssize_t dgnc_vpd_show(struct device *p, struct device_attribute *attr, char *buf)
149 {
150 struct dgnc_board *bd;
151 int count = 0;
152 int i = 0;
153
154 DGNC_VERIFY_BOARD(p, bd);
155
156 count += sprintf(buf + count, "\n 0 1 2 3 4 5 6 7 8 9 A B C D E F");
157 for (i = 0; i < 0x40 * 2; i++) {
158 if (!(i % 16))
159 count += sprintf(buf + count, "\n%04X ", i * 2);
160 count += sprintf(buf + count, "%02X ", bd->vpd[i]);
161 }
162 count += sprintf(buf + count, "\n");
163
164 return count;
165 }
166 static DEVICE_ATTR(vpd, S_IRUSR, dgnc_vpd_show, NULL);
167
168 static ssize_t dgnc_serial_number_show(struct device *p, struct device_attribute *attr, char *buf)
169 {
170 struct dgnc_board *bd;
171 int count = 0;
172
173 DGNC_VERIFY_BOARD(p, bd);
174
175 if (bd->serial_num[0] == '\0')
176 count += sprintf(buf + count, "<UNKNOWN>\n");
177 else
178 count += sprintf(buf + count, "%s\n", bd->serial_num);
179
180 return count;
181 }
182 static DEVICE_ATTR(serial_number, S_IRUSR, dgnc_serial_number_show, NULL);
183
184
185 static ssize_t dgnc_ports_state_show(struct device *p, struct device_attribute *attr, char *buf)
186 {
187 struct dgnc_board *bd;
188 int count = 0;
189 int i = 0;
190
191 DGNC_VERIFY_BOARD(p, bd);
192
193 for (i = 0; i < bd->nasync; i++) {
194 count += snprintf(buf + count, PAGE_SIZE - count,
195 "%d %s\n", bd->channels[i]->ch_portnum,
196 bd->channels[i]->ch_open_count ? "Open" : "Closed");
197 }
198 return count;
199 }
200 static DEVICE_ATTR(ports_state, S_IRUSR, dgnc_ports_state_show, NULL);
201
202
203 static ssize_t dgnc_ports_baud_show(struct device *p, struct device_attribute *attr, char *buf)
204 {
205 struct dgnc_board *bd;
206 int count = 0;
207 int i = 0;
208
209 DGNC_VERIFY_BOARD(p, bd);
210
211 for (i = 0; i < bd->nasync; i++) {
212 count += snprintf(buf + count, PAGE_SIZE - count,
213 "%d %d\n", bd->channels[i]->ch_portnum, bd->channels[i]->ch_old_baud);
214 }
215 return count;
216 }
217 static DEVICE_ATTR(ports_baud, S_IRUSR, dgnc_ports_baud_show, NULL);
218
219
220 static ssize_t dgnc_ports_msignals_show(struct device *p, struct device_attribute *attr, char *buf)
221 {
222 struct dgnc_board *bd;
223 int count = 0;
224 int i = 0;
225
226 DGNC_VERIFY_BOARD(p, bd);
227
228 for (i = 0; i < bd->nasync; i++) {
229 if (bd->channels[i]->ch_open_count) {
230 count += snprintf(buf + count, PAGE_SIZE - count,
231 "%d %s %s %s %s %s %s\n", bd->channels[i]->ch_portnum,
232 (bd->channels[i]->ch_mostat & UART_MCR_RTS) ? "RTS" : "",
233 (bd->channels[i]->ch_mistat & UART_MSR_CTS) ? "CTS" : "",
234 (bd->channels[i]->ch_mostat & UART_MCR_DTR) ? "DTR" : "",
235 (bd->channels[i]->ch_mistat & UART_MSR_DSR) ? "DSR" : "",
236 (bd->channels[i]->ch_mistat & UART_MSR_DCD) ? "DCD" : "",
237 (bd->channels[i]->ch_mistat & UART_MSR_RI) ? "RI" : "");
238 } else {
239 count += snprintf(buf + count, PAGE_SIZE - count,
240 "%d\n", bd->channels[i]->ch_portnum);
241 }
242 }
243 return count;
244 }
245 static DEVICE_ATTR(ports_msignals, S_IRUSR, dgnc_ports_msignals_show, NULL);
246
247
248 static ssize_t dgnc_ports_iflag_show(struct device *p, struct device_attribute *attr, char *buf)
249 {
250 struct dgnc_board *bd;
251 int count = 0;
252 int i = 0;
253
254 DGNC_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_iflag);
259 }
260 return count;
261 }
262 static DEVICE_ATTR(ports_iflag, S_IRUSR, dgnc_ports_iflag_show, NULL);
263
264
265 static ssize_t dgnc_ports_cflag_show(struct device *p, struct device_attribute *attr, char *buf)
266 {
267 struct dgnc_board *bd;
268 int count = 0;
269 int i = 0;
270
271 DGNC_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_cflag);
276 }
277 return count;
278 }
279 static DEVICE_ATTR(ports_cflag, S_IRUSR, dgnc_ports_cflag_show, NULL);
280
281
282 static ssize_t dgnc_ports_oflag_show(struct device *p, struct device_attribute *attr, char *buf)
283 {
284 struct dgnc_board *bd;
285 int count = 0;
286 int i = 0;
287
288 DGNC_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_oflag);
293 }
294 return count;
295 }
296 static DEVICE_ATTR(ports_oflag, S_IRUSR, dgnc_ports_oflag_show, NULL);
297
298
299 static ssize_t dgnc_ports_lflag_show(struct device *p, struct device_attribute *attr, char *buf)
300 {
301 struct dgnc_board *bd;
302 int count = 0;
303 int i = 0;
304
305 DGNC_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_c_lflag);
310 }
311 return count;
312 }
313 static DEVICE_ATTR(ports_lflag, S_IRUSR, dgnc_ports_lflag_show, NULL);
314
315
316 static ssize_t dgnc_ports_digi_flag_show(struct device *p, struct device_attribute *attr, char *buf)
317 {
318 struct dgnc_board *bd;
319 int count = 0;
320 int i = 0;
321
322 DGNC_VERIFY_BOARD(p, bd);
323
324 for (i = 0; i < bd->nasync; i++) {
325 count += snprintf(buf + count, PAGE_SIZE - count, "%d %x\n",
326 bd->channels[i]->ch_portnum, bd->channels[i]->ch_digi.digi_flags);
327 }
328 return count;
329 }
330 static DEVICE_ATTR(ports_digi_flag, S_IRUSR, dgnc_ports_digi_flag_show, NULL);
331
332
333 static ssize_t dgnc_ports_rxcount_show(struct device *p, struct device_attribute *attr, char *buf)
334 {
335 struct dgnc_board *bd;
336 int count = 0;
337 int i = 0;
338
339 DGNC_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_rxcount);
344 }
345 return count;
346 }
347 static DEVICE_ATTR(ports_rxcount, S_IRUSR, dgnc_ports_rxcount_show, NULL);
348
349
350 static ssize_t dgnc_ports_txcount_show(struct device *p, struct device_attribute *attr, char *buf)
351 {
352 struct dgnc_board *bd;
353 int count = 0;
354 int i = 0;
355
356 DGNC_VERIFY_BOARD(p, bd);
357
358 for (i = 0; i < bd->nasync; i++) {
359 count += snprintf(buf + count, PAGE_SIZE - count, "%d %ld\n",
360 bd->channels[i]->ch_portnum, bd->channels[i]->ch_txcount);
361 }
362 return count;
363 }
364 static DEVICE_ATTR(ports_txcount, S_IRUSR, dgnc_ports_txcount_show, NULL);
365
366
367 /* this function creates the sys files that will export each signal status
368 * to sysfs each value will be put in a separate filename
369 */
370 void dgnc_create_ports_sysfiles(struct dgnc_board *bd)
371 {
372 int rc = 0;
373
374 dev_set_drvdata(&bd->pdev->dev, bd);
375 rc |= device_create_file(&(bd->pdev->dev), &dev_attr_ports_state);
376 rc |= device_create_file(&(bd->pdev->dev), &dev_attr_ports_baud);
377 rc |= device_create_file(&(bd->pdev->dev), &dev_attr_ports_msignals);
378 rc |= device_create_file(&(bd->pdev->dev), &dev_attr_ports_iflag);
379 rc |= device_create_file(&(bd->pdev->dev), &dev_attr_ports_cflag);
380 rc |= device_create_file(&(bd->pdev->dev), &dev_attr_ports_oflag);
381 rc |= device_create_file(&(bd->pdev->dev), &dev_attr_ports_lflag);
382 rc |= device_create_file(&(bd->pdev->dev), &dev_attr_ports_digi_flag);
383 rc |= device_create_file(&(bd->pdev->dev), &dev_attr_ports_rxcount);
384 rc |= device_create_file(&(bd->pdev->dev), &dev_attr_ports_txcount);
385 rc |= device_create_file(&(bd->pdev->dev), &dev_attr_vpd);
386 rc |= device_create_file(&(bd->pdev->dev), &dev_attr_serial_number);
387 if (rc) {
388 printk(KERN_ERR "DGNC: sysfs device_create_file failed!\n");
389 }
390 }
391
392
393 /* removes all the sys files created for that port */
394 void dgnc_remove_ports_sysfiles(struct dgnc_board *bd)
395 {
396 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_state);
397 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_baud);
398 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_msignals);
399 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_iflag);
400 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_cflag);
401 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_oflag);
402 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_lflag);
403 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_digi_flag);
404 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_rxcount);
405 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_txcount);
406 device_remove_file(&(bd->pdev->dev), &dev_attr_vpd);
407 device_remove_file(&(bd->pdev->dev), &dev_attr_serial_number);
408 }
409
410
411 static ssize_t dgnc_tty_state_show(struct device *d, struct device_attribute *attr, char *buf)
412 {
413 struct dgnc_board *bd;
414 struct channel_t *ch;
415 struct un_t *un;
416
417 if (!d)
418 return 0;
419 un = dev_get_drvdata(d);
420 if (!un || un->magic != DGNC_UNIT_MAGIC)
421 return 0;
422 ch = un->un_ch;
423 if (!ch || ch->magic != DGNC_CHANNEL_MAGIC)
424 return 0;
425 bd = ch->ch_bd;
426 if (!bd || bd->magic != DGNC_BOARD_MAGIC)
427 return 0;
428 if (bd->state != BOARD_READY)
429 return 0;
430
431 return snprintf(buf, PAGE_SIZE, "%s", un->un_open_count ? "Open" : "Closed");
432 }
433 static DEVICE_ATTR(state, S_IRUSR, dgnc_tty_state_show, NULL);
434
435
436 static ssize_t dgnc_tty_baud_show(struct device *d, struct device_attribute *attr, char *buf)
437 {
438 struct dgnc_board *bd;
439 struct channel_t *ch;
440 struct un_t *un;
441
442 if (!d)
443 return 0;
444 un = dev_get_drvdata(d);
445 if (!un || un->magic != DGNC_UNIT_MAGIC)
446 return 0;
447 ch = un->un_ch;
448 if (!ch || ch->magic != DGNC_CHANNEL_MAGIC)
449 return 0;
450 bd = ch->ch_bd;
451 if (!bd || bd->magic != DGNC_BOARD_MAGIC)
452 return 0;
453 if (bd->state != BOARD_READY)
454 return 0;
455
456 return snprintf(buf, PAGE_SIZE, "%d\n", ch->ch_old_baud);
457 }
458 static DEVICE_ATTR(baud, S_IRUSR, dgnc_tty_baud_show, NULL);
459
460
461 static ssize_t dgnc_tty_msignals_show(struct device *d, struct device_attribute *attr, char *buf)
462 {
463 struct dgnc_board *bd;
464 struct channel_t *ch;
465 struct un_t *un;
466
467 if (!d)
468 return 0;
469 un = dev_get_drvdata(d);
470 if (!un || un->magic != DGNC_UNIT_MAGIC)
471 return 0;
472 ch = un->un_ch;
473 if (!ch || ch->magic != DGNC_CHANNEL_MAGIC)
474 return 0;
475 bd = ch->ch_bd;
476 if (!bd || bd->magic != DGNC_BOARD_MAGIC)
477 return 0;
478 if (bd->state != BOARD_READY)
479 return 0;
480
481 if (ch->ch_open_count) {
482 return snprintf(buf, PAGE_SIZE, "%s %s %s %s %s %s\n",
483 (ch->ch_mostat & UART_MCR_RTS) ? "RTS" : "",
484 (ch->ch_mistat & UART_MSR_CTS) ? "CTS" : "",
485 (ch->ch_mostat & UART_MCR_DTR) ? "DTR" : "",
486 (ch->ch_mistat & UART_MSR_DSR) ? "DSR" : "",
487 (ch->ch_mistat & UART_MSR_DCD) ? "DCD" : "",
488 (ch->ch_mistat & UART_MSR_RI) ? "RI" : "");
489 }
490 return 0;
491 }
492 static DEVICE_ATTR(msignals, S_IRUSR, dgnc_tty_msignals_show, NULL);
493
494
495 static ssize_t dgnc_tty_iflag_show(struct device *d, struct device_attribute *attr, char *buf)
496 {
497 struct dgnc_board *bd;
498 struct channel_t *ch;
499 struct un_t *un;
500
501 if (!d)
502 return 0;
503 un = dev_get_drvdata(d);
504 if (!un || un->magic != DGNC_UNIT_MAGIC)
505 return 0;
506 ch = un->un_ch;
507 if (!ch || ch->magic != DGNC_CHANNEL_MAGIC)
508 return 0;
509 bd = ch->ch_bd;
510 if (!bd || bd->magic != DGNC_BOARD_MAGIC)
511 return 0;
512 if (bd->state != BOARD_READY)
513 return 0;
514
515 return snprintf(buf, PAGE_SIZE, "%x\n", ch->ch_c_iflag);
516 }
517 static DEVICE_ATTR(iflag, S_IRUSR, dgnc_tty_iflag_show, NULL);
518
519
520 static ssize_t dgnc_tty_cflag_show(struct device *d, struct device_attribute *attr, char *buf)
521 {
522 struct dgnc_board *bd;
523 struct channel_t *ch;
524 struct un_t *un;
525
526 if (!d)
527 return 0;
528 un = dev_get_drvdata(d);
529 if (!un || un->magic != DGNC_UNIT_MAGIC)
530 return 0;
531 ch = un->un_ch;
532 if (!ch || ch->magic != DGNC_CHANNEL_MAGIC)
533 return 0;
534 bd = ch->ch_bd;
535 if (!bd || bd->magic != DGNC_BOARD_MAGIC)
536 return 0;
537 if (bd->state != BOARD_READY)
538 return 0;
539
540 return snprintf(buf, PAGE_SIZE, "%x\n", ch->ch_c_cflag);
541 }
542 static DEVICE_ATTR(cflag, S_IRUSR, dgnc_tty_cflag_show, NULL);
543
544
545 static ssize_t dgnc_tty_oflag_show(struct device *d, struct device_attribute *attr, char *buf)
546 {
547 struct dgnc_board *bd;
548 struct channel_t *ch;
549 struct un_t *un;
550
551 if (!d)
552 return 0;
553 un = dev_get_drvdata(d);
554 if (!un || un->magic != DGNC_UNIT_MAGIC)
555 return 0;
556 ch = un->un_ch;
557 if (!ch || ch->magic != DGNC_CHANNEL_MAGIC)
558 return 0;
559 bd = ch->ch_bd;
560 if (!bd || bd->magic != DGNC_BOARD_MAGIC)
561 return 0;
562 if (bd->state != BOARD_READY)
563 return 0;
564
565 return snprintf(buf, PAGE_SIZE, "%x\n", ch->ch_c_oflag);
566 }
567 static DEVICE_ATTR(oflag, S_IRUSR, dgnc_tty_oflag_show, NULL);
568
569
570 static ssize_t dgnc_tty_lflag_show(struct device *d, struct device_attribute *attr, char *buf)
571 {
572 struct dgnc_board *bd;
573 struct channel_t *ch;
574 struct un_t *un;
575
576 if (!d)
577 return 0;
578 un = dev_get_drvdata(d);
579 if (!un || un->magic != DGNC_UNIT_MAGIC)
580 return 0;
581 ch = un->un_ch;
582 if (!ch || ch->magic != DGNC_CHANNEL_MAGIC)
583 return 0;
584 bd = ch->ch_bd;
585 if (!bd || bd->magic != DGNC_BOARD_MAGIC)
586 return 0;
587 if (bd->state != BOARD_READY)
588 return 0;
589
590 return snprintf(buf, PAGE_SIZE, "%x\n", ch->ch_c_lflag);
591 }
592 static DEVICE_ATTR(lflag, S_IRUSR, dgnc_tty_lflag_show, NULL);
593
594
595 static ssize_t dgnc_tty_digi_flag_show(struct device *d, struct device_attribute *attr, char *buf)
596 {
597 struct dgnc_board *bd;
598 struct channel_t *ch;
599 struct un_t *un;
600
601 if (!d)
602 return 0;
603 un = dev_get_drvdata(d);
604 if (!un || un->magic != DGNC_UNIT_MAGIC)
605 return 0;
606 ch = un->un_ch;
607 if (!ch || ch->magic != DGNC_CHANNEL_MAGIC)
608 return 0;
609 bd = ch->ch_bd;
610 if (!bd || bd->magic != DGNC_BOARD_MAGIC)
611 return 0;
612 if (bd->state != BOARD_READY)
613 return 0;
614
615 return snprintf(buf, PAGE_SIZE, "%x\n", ch->ch_digi.digi_flags);
616 }
617 static DEVICE_ATTR(digi_flag, S_IRUSR, dgnc_tty_digi_flag_show, NULL);
618
619
620 static ssize_t dgnc_tty_rxcount_show(struct device *d, struct device_attribute *attr, char *buf)
621 {
622 struct dgnc_board *bd;
623 struct channel_t *ch;
624 struct un_t *un;
625
626 if (!d)
627 return 0;
628 un = dev_get_drvdata(d);
629 if (!un || un->magic != DGNC_UNIT_MAGIC)
630 return 0;
631 ch = un->un_ch;
632 if (!ch || ch->magic != DGNC_CHANNEL_MAGIC)
633 return 0;
634 bd = ch->ch_bd;
635 if (!bd || bd->magic != DGNC_BOARD_MAGIC)
636 return 0;
637 if (bd->state != BOARD_READY)
638 return 0;
639
640 return snprintf(buf, PAGE_SIZE, "%ld\n", ch->ch_rxcount);
641 }
642 static DEVICE_ATTR(rxcount, S_IRUSR, dgnc_tty_rxcount_show, NULL);
643
644
645 static ssize_t dgnc_tty_txcount_show(struct device *d, struct device_attribute *attr, char *buf)
646 {
647 struct dgnc_board *bd;
648 struct channel_t *ch;
649 struct un_t *un;
650
651 if (!d)
652 return 0;
653 un = dev_get_drvdata(d);
654 if (!un || un->magic != DGNC_UNIT_MAGIC)
655 return 0;
656 ch = un->un_ch;
657 if (!ch || ch->magic != DGNC_CHANNEL_MAGIC)
658 return 0;
659 bd = ch->ch_bd;
660 if (!bd || bd->magic != DGNC_BOARD_MAGIC)
661 return 0;
662 if (bd->state != BOARD_READY)
663 return 0;
664
665 return snprintf(buf, PAGE_SIZE, "%ld\n", ch->ch_txcount);
666 }
667 static DEVICE_ATTR(txcount, S_IRUSR, dgnc_tty_txcount_show, NULL);
668
669
670 static ssize_t dgnc_tty_name_show(struct device *d, struct device_attribute *attr, char *buf)
671 {
672 struct dgnc_board *bd;
673 struct channel_t *ch;
674 struct un_t *un;
675
676 if (!d)
677 return 0;
678 un = dev_get_drvdata(d);
679 if (!un || un->magic != DGNC_UNIT_MAGIC)
680 return 0;
681 ch = un->un_ch;
682 if (!ch || ch->magic != DGNC_CHANNEL_MAGIC)
683 return 0;
684 bd = ch->ch_bd;
685 if (!bd || bd->magic != DGNC_BOARD_MAGIC)
686 return 0;
687 if (bd->state != BOARD_READY)
688 return 0;
689
690 return snprintf(buf, PAGE_SIZE, "%sn%d%c\n",
691 (un->un_type == DGNC_PRINT) ? "pr" : "tty",
692 bd->boardnum + 1, 'a' + ch->ch_portnum);
693 }
694 static DEVICE_ATTR(custom_name, S_IRUSR, dgnc_tty_name_show, NULL);
695
696
697 static struct attribute *dgnc_sysfs_tty_entries[] = {
698 &dev_attr_state.attr,
699 &dev_attr_baud.attr,
700 &dev_attr_msignals.attr,
701 &dev_attr_iflag.attr,
702 &dev_attr_cflag.attr,
703 &dev_attr_oflag.attr,
704 &dev_attr_lflag.attr,
705 &dev_attr_digi_flag.attr,
706 &dev_attr_rxcount.attr,
707 &dev_attr_txcount.attr,
708 &dev_attr_custom_name.attr,
709 NULL
710 };
711
712
713 static struct attribute_group dgnc_tty_attribute_group = {
714 .name = NULL,
715 .attrs = dgnc_sysfs_tty_entries,
716 };
717
718
719 void dgnc_create_tty_sysfs(struct un_t *un, struct device *c)
720 {
721 int ret;
722
723 ret = sysfs_create_group(&c->kobj, &dgnc_tty_attribute_group);
724 if (ret) {
725 dev_err(c, "dgnc: failed to create sysfs tty device attributes.\n");
726 sysfs_remove_group(&c->kobj, &dgnc_tty_attribute_group);
727 return;
728 }
729
730 dev_set_drvdata(c, un);
731
732 }
733
734
735 void dgnc_remove_tty_sysfs(struct device *c)
736 {
737 sysfs_remove_group(&c->kobj, &dgnc_tty_attribute_group);
738 }
739
This page took 0.044467 seconds and 4 git commands to generate.