]>
git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blob - drivers/staging/dgnc/dgnc_mgmt.c
2 * Copyright 2003 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.
16 /************************************************************************
18 * This file implements the mgmt functionality for the
19 * Neo and ClassicBoard based product lines.
21 ************************************************************************
23 #include <linux/kernel.h>
24 #include <linux/ctype.h>
25 #include <linux/sched.h> /* For jiffies, task states */
26 #include <linux/interrupt.h> /* For tasklet and interrupt structs/defines */
27 #include <linux/serial_reg.h>
28 #include <linux/termios.h>
29 #include <linux/uaccess.h> /* For copy_from_user/copy_to_user */
31 #include "dgnc_driver.h"
33 #include "dgnc_mgmt.h"
35 /* Our "in use" variables, to enforce 1 open only */
36 static int dgnc_mgmt_in_use
[MAXMGMTDEVICES
];
41 * Open the mgmt/downld/dpa device
43 int dgnc_mgmt_open(struct inode
*inode
, struct file
*file
)
46 unsigned int minor
= iminor(inode
);
48 spin_lock_irqsave(&dgnc_global_lock
, flags
);
51 if (minor
< MAXMGMTDEVICES
) {
52 /* Only allow 1 open at a time on mgmt device */
53 if (dgnc_mgmt_in_use
[minor
]) {
54 spin_unlock_irqrestore(&dgnc_global_lock
, flags
);
57 dgnc_mgmt_in_use
[minor
]++;
59 spin_unlock_irqrestore(&dgnc_global_lock
, flags
);
63 spin_unlock_irqrestore(&dgnc_global_lock
, flags
);
71 * Open the mgmt/dpa device
73 int dgnc_mgmt_close(struct inode
*inode
, struct file
*file
)
76 unsigned int minor
= iminor(inode
);
78 spin_lock_irqsave(&dgnc_global_lock
, flags
);
81 if (minor
< MAXMGMTDEVICES
) {
82 if (dgnc_mgmt_in_use
[minor
])
83 dgnc_mgmt_in_use
[minor
] = 0;
85 spin_unlock_irqrestore(&dgnc_global_lock
, flags
);
93 * ioctl the mgmt/dpa device
96 long dgnc_mgmt_ioctl(struct file
*file
, unsigned int cmd
, unsigned long arg
)
99 void __user
*uarg
= (void __user
*)arg
;
105 * This returns the total number of boards
106 * in the system, as well as driver version
107 * and has space for a reserved entry
109 struct digi_dinfo ddi
;
111 spin_lock_irqsave(&dgnc_global_lock
, flags
);
113 memset(&ddi
, 0, sizeof(ddi
));
114 ddi
.dinfo_nboards
= dgnc_NumBoards
;
115 sprintf(ddi
.dinfo_version
, "%s", DG_PART
);
117 spin_unlock_irqrestore(&dgnc_global_lock
, flags
);
119 if (copy_to_user(uarg
, &ddi
, sizeof(ddi
)))
131 if (copy_from_user(&brd
, uarg
, sizeof(int)))
134 if (brd
< 0 || brd
>= dgnc_NumBoards
)
137 memset(&di
, 0, sizeof(di
));
141 spin_lock_irqsave(&dgnc_Board
[brd
]->bd_lock
, flags
);
143 di
.info_bdtype
= dgnc_Board
[brd
]->dpatype
;
144 di
.info_bdstate
= dgnc_Board
[brd
]->dpastatus
;
146 di
.info_physaddr
= (ulong
)dgnc_Board
[brd
]->membase
;
147 di
.info_physsize
= (ulong
)dgnc_Board
[brd
]->membase
148 - dgnc_Board
[brd
]->membase_end
;
149 if (dgnc_Board
[brd
]->state
!= BOARD_FAILED
)
150 di
.info_nports
= dgnc_Board
[brd
]->nasync
;
154 spin_unlock_irqrestore(&dgnc_Board
[brd
]->bd_lock
, flags
);
156 if (copy_to_user(uarg
, &di
, sizeof(di
)))
162 case DIGI_GET_NI_INFO
:
164 struct channel_t
*ch
;
166 unsigned char mstat
= 0;
170 if (copy_from_user(&ni
, uarg
, sizeof(ni
)))
174 channel
= ni
.channel
;
176 /* Verify boundaries on board */
177 if (board
>= dgnc_NumBoards
)
180 /* Verify boundaries on channel */
181 if (channel
>= dgnc_Board
[board
]->nasync
)
184 ch
= dgnc_Board
[board
]->channels
[channel
];
186 if (!ch
|| ch
->magic
!= DGNC_CHANNEL_MAGIC
)
189 memset(&ni
, 0, sizeof(ni
));
191 ni
.channel
= channel
;
193 spin_lock_irqsave(&ch
->ch_lock
, flags
);
195 mstat
= ch
->ch_mostat
| ch
->ch_mistat
;
197 if (mstat
& UART_MCR_DTR
) {
198 ni
.mstat
|= TIOCM_DTR
;
201 if (mstat
& UART_MCR_RTS
) {
202 ni
.mstat
|= TIOCM_RTS
;
205 if (mstat
& UART_MSR_CTS
) {
206 ni
.mstat
|= TIOCM_CTS
;
209 if (mstat
& UART_MSR_RI
) {
210 ni
.mstat
|= TIOCM_RI
;
213 if (mstat
& UART_MSR_DCD
) {
214 ni
.mstat
|= TIOCM_CD
;
217 if (mstat
& UART_MSR_DSR
)
218 ni
.mstat
|= TIOCM_DSR
;
220 ni
.iflag
= ch
->ch_c_iflag
;
221 ni
.oflag
= ch
->ch_c_oflag
;
222 ni
.cflag
= ch
->ch_c_cflag
;
223 ni
.lflag
= ch
->ch_c_lflag
;
225 if (ch
->ch_digi
.digi_flags
& CTSPACE
||
226 ch
->ch_c_cflag
& CRTSCTS
)
231 if ((ch
->ch_flags
& CH_STOPI
) ||
232 (ch
->ch_flags
& CH_FORCED_STOPI
))
237 if ((ch
->ch_flags
& CH_STOP
) || (ch
->ch_flags
& CH_FORCED_STOP
))
242 ni
.curtx
= ch
->ch_txcount
;
243 ni
.currx
= ch
->ch_rxcount
;
245 ni
.baud
= ch
->ch_old_baud
;
247 spin_unlock_irqrestore(&ch
->ch_lock
, flags
);
249 if (copy_to_user(uarg
, &ni
, sizeof(ni
)))