Index: sys/dev/spibus/spigen.c =================================================================== --- sys/dev/spibus/spigen.c +++ sys/dev/spibus/spigen.c @@ -64,6 +64,7 @@ struct spigen_softc { device_t sc_dev; struct cdev *sc_cdev; + struct cdev *sc_adev; /* alias device */ struct mtx sc_mtx; uint32_t sc_command_length_max; /* cannot change while mmapped */ uint32_t sc_data_length_max; /* cannot change while mmapped */ @@ -186,11 +187,39 @@ { struct spigen_softc *sc; const int unit = device_get_unit(dev); + int cs, res; + struct make_dev_args mda; + + spibus_get_cs(dev, &cs); + cs &= ~SPIBUS_CS_HIGH; /* trim 'cs high' bit */ sc = device_get_softc(dev); sc->sc_dev = dev; - sc->sc_cdev = make_dev(&spigen_cdevsw, unit, - UID_ROOT, GID_OPERATOR, 0660, "spigen%d", unit); + + make_dev_args_init(&mda); + mda.mda_flags = 0; /* see make_dev in kern_conf.c */ + mda.mda_devsw = &spigen_cdevsw; + mda.mda_cr = NULL; /* see make_dev in kern_conf.c */ + mda.mda_uid = UID_ROOT; + mda.mda_gid = GID_OPERATOR; + mda.mda_mode = 0660; + mda.mda_unit = unit; + + res = make_dev_s(&mda, &(sc->sc_cdev), "spigen%d", unit); + if (res) { + return res; + } + + res = make_dev_alias_p(0, &(sc->sc_adev), sc->sc_cdev, "spigen%d.%d", + device_get_unit(device_get_parent(dev)), cs); + if (res) { + if (sc->sc_cdev) { /* TODO: should I just rely on 'detach' to do this? */ + destroy_dev(sc->sc_cdev); + sc->sc_cdev = NULL; + } + return res; + } + sc->sc_cdev->si_drv1 = dev; sc->sc_command_length_max = PAGE_SIZE; sc->sc_data_length_max = PAGE_SIZE; @@ -429,8 +458,11 @@ mtx_destroy(&sc->sc_mtx); - if (sc->sc_cdev) - destroy_dev(sc->sc_cdev); + if (sc->sc_adev) + destroy_dev(sc->sc_adev); + + if (sc->sc_cdev) + destroy_dev(sc->sc_cdev); return (0); }