#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: ite_compat.c,v 1.14 2023/03/26 15:12:34 andvar Exp $");
#include "ite.h"
#include "wsdisplay.h"
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/conf.h>
#include <sys/device.h>
#include <sys/ioctl.h>
#include <sys/ttycom.h>
#include <dev/cons.h>
#include <machine/cpu.h>
#include <machine/iteioctl.h>
#include "ioconf.h"
dev_type_open(iteopen);
dev_type_close(iteclose);
dev_type_read(iteread);
dev_type_write(itewrite);
dev_type_ioctl(iteioctl);
dev_type_tty(itetty);
dev_type_poll(itepoll);
dev_type_kqfilter(itekqfilter);
const struct cdevsw ite_cdevsw = {
.d_open = iteopen,
.d_close = iteclose,
.d_read = iteread,
.d_write = itewrite,
.d_ioctl = iteioctl,
.d_stop = nostop,
.d_tty = itetty,
.d_poll = itepoll,
.d_mmap = nommap,
.d_kqfilter = itekqfilter,
.d_discard = nodiscard,
.d_flag = D_TTY
};
#if NWSDISPLAY > 0
extern const struct cdevsw wsdisplay_cdevsw;
#endif
static int ite_initted = 0;
static int ite_bell_freq = 1880;
static int ite_bell_length = 10;
static int ite_bell_volume = 100;
void
iteattach(int n)
{
#if NWSDISPLAY > 0
int maj;
maj = cdevsw_lookup_major(&wsdisplay_cdevsw);
KASSERT(maj != -1);
if (maj != major(cn_tab->cn_dev))
return;
ite_initted = 1;
#endif
}
int
iteopen(dev_t dev, int mode, int devtype, struct lwp *l)
{
return ite_initted ? (0) : (ENXIO);
}
int
iteclose(dev_t dev, int flag, int mode, struct lwp *l)
{
return ite_initted ? (0) : (ENXIO);
}
int
iteread(dev_t dev, struct uio *uio, int flag)
{
return ite_initted ?
(*wsdisplay_cdevsw.d_read)(cn_tab->cn_dev, uio, flag) : (ENXIO);
}
int
itewrite(dev_t dev, struct uio *uio, int flag)
{
return ite_initted ?
(*wsdisplay_cdevsw.d_write)(cn_tab->cn_dev, uio, flag) : (ENXIO);
}
struct tty *
itetty(dev_t dev)
{
return ite_initted ? (*wsdisplay_cdevsw.d_tty)(cn_tab->cn_dev) : (NULL);
}
int
iteioctl(dev_t dev, u_long cmd, void *addr, int flag, struct lwp *l)
{
if (!ite_initted)
return (ENXIO);
switch (cmd) {
case ITEIOC_RINGBELL:
return mac68k_ring_bell(ite_bell_freq,
ite_bell_length, ite_bell_volume);
case ITEIOC_SETBELL:
{
struct bellparams *bp = (void *)addr;
if (bp->freq < 10 || bp->freq > 40000)
return (EINVAL);
if (bp->len < 0 || bp->len > 3600)
return (EINVAL);
if (bp->vol < 0 || bp->vol > 100)
return (EINVAL);
ite_bell_freq = bp->freq;
ite_bell_length = bp->len;
ite_bell_volume = bp->vol;
return (0);
}
case ITEIOC_GETBELL:
{
struct bellparams *bp = (void *)addr;
ite_bell_freq = bp->freq;
ite_bell_length = bp->len;
ite_bell_volume = bp->vol;
return (0);
}
default:
return ((*wsdisplay_cdevsw.d_ioctl)(cn_tab->cn_dev, cmd,
addr, flag, l));
}
return (ENOTTY);
}
int
itepoll(dev_t dev, int events, struct lwp *l)
{
return ite_initted ?
(*wsdisplay_cdevsw.d_poll)(cn_tab->cn_dev, events, l) : (ENXIO);
}
int
itekqfilter(dev_t dev, struct knote *kn)
{
return ite_initted ?
(*wsdisplay_cdevsw.d_kqfilter)(cn_tab->cn_dev, kn) : (ENXIO);
}