in turn based on the FreeBSD driver, ported to NetBSD and somewhat modified by me. Thanks to Matt Thomas for testing.