Allocate unit numbers with unr, implement detach function.

This commit is contained in:
Poul-Henning Kamp 2005-09-15 13:07:38 +00:00
parent c5cff17017
commit f6a157fb88
2 changed files with 21 additions and 5 deletions

View file

@ -81,6 +81,7 @@ upd7210_rd(struct upd7210 *u, enum upd7210_rreg reg)
void
upd7210_wr(struct upd7210 *u, enum upd7210_wreg reg, u_int val)
{
bus_space_write_1(
u->reg_tag[reg],
u->reg_handle[reg],
@ -271,21 +272,34 @@ static struct cdevsw gpib_l_cdevsw = {
/* Housekeeping */
static struct unrhdr *units;
void
upd7210attach(struct upd7210 *u)
{
int unit = 0;
struct cdev *dev;
if (units == NULL)
units = new_unrhdr(0, minor2unit(MAXMINOR), NULL);
u->unit = alloc_unr(units);
mtx_init(&u->mutex, "gpib", NULL, MTX_DEF);
u->cdev = make_dev(&gpib_l_cdevsw, unit,
u->cdev = make_dev(&gpib_l_cdevsw, u->unit,
UID_ROOT, GID_WHEEL, 0444,
"gpib%ul", unit);
"gpib%ul", u->unit);
u->cdev->si_drv1 = u;
dev = make_dev(&gpib_ib_cdevsw, unit,
dev = make_dev(&gpib_ib_cdevsw, u->unit,
UID_ROOT, GID_WHEEL, 0444,
"gpib%uib", unit);
"gpib%uib", u->unit);
dev->si_drv1 = u;
dev_depends(u->cdev, dev);
}
void
upd7210detach(struct upd7210 *u)
{
destroy_dev(u->cdev);
mtx_destroy(&u->mutex);
free_unr(units, u->unit);
}

View file

@ -51,6 +51,7 @@ struct upd7210 {
bus_space_tag_t reg_tag[8];
u_int reg_offset[8];
int dmachan;
int unit;
/* private stuff */
struct mtx mutex;
@ -72,6 +73,7 @@ struct upd7210 {
#ifdef UPD7210_HW_DRIVER
void upd7210intr(void *);
void upd7210attach(struct upd7210 *);
void upd7210detach(struct upd7210 *);
#endif
#ifdef UPD7210_SW_DRIVER