pg.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735
  1. /*
  2. pg.c (c) 1998 Grant R. Guenther <grant@torque.net>
  3. Under the terms of the GNU General Public License.
  4. The pg driver provides a simple character device interface for
  5. sending ATAPI commands to a device. With the exception of the
  6. ATAPI reset operation, all operations are performed by a pair
  7. of read and write operations to the appropriate /dev/pgN device.
  8. A write operation delivers a command and any outbound data in
  9. a single buffer. Normally, the write will succeed unless the
  10. device is offline or malfunctioning, or there is already another
  11. command pending. If the write succeeds, it should be followed
  12. immediately by a read operation, to obtain any returned data and
  13. status information. A read will fail if there is no operation
  14. in progress.
  15. As a special case, the device can be reset with a write operation,
  16. and in this case, no following read is expected, or permitted.
  17. There are no ioctl() operations. Any single operation
  18. may transfer at most PG_MAX_DATA bytes. Note that the driver must
  19. copy the data through an internal buffer. In keeping with all
  20. current ATAPI devices, command packets are assumed to be exactly
  21. 12 bytes in length.
  22. To permit future changes to this interface, the headers in the
  23. read and write buffers contain a single character "magic" flag.
  24. Currently this flag must be the character "P".
  25. By default, the driver will autoprobe for a single parallel
  26. port ATAPI device, but if their individual parameters are
  27. specified, the driver can handle up to 4 devices.
  28. To use this device, you must have the following device
  29. special files defined:
  30. /dev/pg0 c 97 0
  31. /dev/pg1 c 97 1
  32. /dev/pg2 c 97 2
  33. /dev/pg3 c 97 3
  34. (You'll need to change the 97 to something else if you use
  35. the 'major' parameter to install the driver on a different
  36. major number.)
  37. The behaviour of the pg driver can be altered by setting
  38. some parameters from the insmod command line. The following
  39. parameters are adjustable:
  40. drive0 These four arguments can be arrays of
  41. drive1 1-6 integers as follows:
  42. drive2
  43. drive3 <prt>,<pro>,<uni>,<mod>,<slv>,<dly>
  44. Where,
  45. <prt> is the base of the parallel port address for
  46. the corresponding drive. (required)
  47. <pro> is the protocol number for the adapter that
  48. supports this drive. These numbers are
  49. logged by 'paride' when the protocol modules
  50. are initialised. (0 if not given)
  51. <uni> for those adapters that support chained
  52. devices, this is the unit selector for the
  53. chain of devices on the given port. It should
  54. be zero for devices that don't support chaining.
  55. (0 if not given)
  56. <mod> this can be -1 to choose the best mode, or one
  57. of the mode numbers supported by the adapter.
  58. (-1 if not given)
  59. <slv> ATAPI devices can be jumpered to master or slave.
  60. Set this to 0 to choose the master drive, 1 to
  61. choose the slave, -1 (the default) to choose the
  62. first drive found.
  63. <dly> some parallel ports require the driver to
  64. go more slowly. -1 sets a default value that
  65. should work with the chosen protocol. Otherwise,
  66. set this to a small integer, the larger it is
  67. the slower the port i/o. In some cases, setting
  68. this to zero will speed up the device. (default -1)
  69. major You may use this parameter to overide the
  70. default major number (97) that this driver
  71. will use. Be sure to change the device
  72. name as well.
  73. name This parameter is a character string that
  74. contains the name the kernel will use for this
  75. device (in /proc output, for instance).
  76. (default "pg").
  77. verbose This parameter controls the amount of logging
  78. that is done by the driver. Set it to 0 for
  79. quiet operation, to 1 to enable progress
  80. messages while the driver probes for devices,
  81. or to 2 for full debug logging. (default 0)
  82. If this driver is built into the kernel, you can use
  83. the following command line parameters, with the same values
  84. as the corresponding module parameters listed above:
  85. pg.drive0
  86. pg.drive1
  87. pg.drive2
  88. pg.drive3
  89. In addition, you can use the parameter pg.disable to disable
  90. the driver entirely.
  91. */
  92. /* Changes:
  93. 1.01 GRG 1998.06.16 Bug fixes
  94. 1.02 GRG 1998.09.24 Added jumbo support
  95. */
  96. #define PG_VERSION "1.02"
  97. #define PG_MAJOR 97
  98. #define PG_NAME "pg"
  99. #define PG_UNITS 4
  100. #ifndef PI_PG
  101. #define PI_PG 4
  102. #endif
  103. #include <linux/types.h>
  104. /* Here are things one can override from the insmod command.
  105. Most are autoprobed by paride unless set here. Verbose is 0
  106. by default.
  107. */
  108. static int verbose;
  109. static int major = PG_MAJOR;
  110. static char *name = PG_NAME;
  111. static int disable = 0;
  112. static int drive0[6] = { 0, 0, 0, -1, -1, -1 };
  113. static int drive1[6] = { 0, 0, 0, -1, -1, -1 };
  114. static int drive2[6] = { 0, 0, 0, -1, -1, -1 };
  115. static int drive3[6] = { 0, 0, 0, -1, -1, -1 };
  116. static int (*drives[4])[6] = {&drive0, &drive1, &drive2, &drive3};
  117. static int pg_drive_count;
  118. enum {D_PRT, D_PRO, D_UNI, D_MOD, D_SLV, D_DLY};
  119. /* end of parameters */
  120. #include <linux/module.h>
  121. #include <linux/init.h>
  122. #include <linux/fs.h>
  123. #include <linux/delay.h>
  124. #include <linux/slab.h>
  125. #include <linux/mtio.h>
  126. #include <linux/pg.h>
  127. #include <linux/device.h>
  128. #include <linux/sched.h> /* current, TASK_* */
  129. #include <linux/mutex.h>
  130. #include <linux/jiffies.h>
  131. #include <asm/uaccess.h>
  132. module_param(verbose, int, 0644);
  133. module_param(major, int, 0);
  134. module_param(name, charp, 0);
  135. module_param_array(drive0, int, NULL, 0);
  136. module_param_array(drive1, int, NULL, 0);
  137. module_param_array(drive2, int, NULL, 0);
  138. module_param_array(drive3, int, NULL, 0);
  139. #include "paride.h"
  140. #define PG_SPIN_DEL 50 /* spin delay in micro-seconds */
  141. #define PG_SPIN 200
  142. #define PG_TMO HZ
  143. #define PG_RESET_TMO 10*HZ
  144. #define STAT_ERR 0x01
  145. #define STAT_INDEX 0x02
  146. #define STAT_ECC 0x04
  147. #define STAT_DRQ 0x08
  148. #define STAT_SEEK 0x10
  149. #define STAT_WRERR 0x20
  150. #define STAT_READY 0x40
  151. #define STAT_BUSY 0x80
  152. #define ATAPI_IDENTIFY 0x12
  153. static DEFINE_MUTEX(pg_mutex);
  154. static int pg_open(struct inode *inode, struct file *file);
  155. static int pg_release(struct inode *inode, struct file *file);
  156. static ssize_t pg_read(struct file *filp, char __user *buf,
  157. size_t count, loff_t * ppos);
  158. static ssize_t pg_write(struct file *filp, const char __user *buf,
  159. size_t count, loff_t * ppos);
  160. static int pg_detect(void);
  161. #define PG_NAMELEN 8
  162. struct pg {
  163. struct pi_adapter pia; /* interface to paride layer */
  164. struct pi_adapter *pi;
  165. int busy; /* write done, read expected */
  166. int start; /* jiffies at command start */
  167. int dlen; /* transfer size requested */
  168. unsigned long timeout; /* timeout requested */
  169. int status; /* last sense key */
  170. int drive; /* drive */
  171. unsigned long access; /* count of active opens ... */
  172. int present; /* device present ? */
  173. char *bufptr;
  174. char name[PG_NAMELEN]; /* pg0, pg1, ... */
  175. };
  176. static struct pg devices[PG_UNITS];
  177. static int pg_identify(struct pg *dev, int log);
  178. static char pg_scratch[512]; /* scratch block buffer */
  179. static struct class *pg_class;
  180. static void *par_drv; /* reference of parport driver */
  181. /* kernel glue structures */
  182. static const struct file_operations pg_fops = {
  183. .owner = THIS_MODULE,
  184. .read = pg_read,
  185. .write = pg_write,
  186. .open = pg_open,
  187. .release = pg_release,
  188. .llseek = noop_llseek,
  189. };
  190. static void pg_init_units(void)
  191. {
  192. int unit;
  193. pg_drive_count = 0;
  194. for (unit = 0; unit < PG_UNITS; unit++) {
  195. int *parm = *drives[unit];
  196. struct pg *dev = &devices[unit];
  197. dev->pi = &dev->pia;
  198. clear_bit(0, &dev->access);
  199. dev->busy = 0;
  200. dev->present = 0;
  201. dev->bufptr = NULL;
  202. dev->drive = parm[D_SLV];
  203. snprintf(dev->name, PG_NAMELEN, "%s%c", name, 'a'+unit);
  204. if (parm[D_PRT])
  205. pg_drive_count++;
  206. }
  207. }
  208. static inline int status_reg(struct pg *dev)
  209. {
  210. return pi_read_regr(dev->pi, 1, 6);
  211. }
  212. static inline int read_reg(struct pg *dev, int reg)
  213. {
  214. return pi_read_regr(dev->pi, 0, reg);
  215. }
  216. static inline void write_reg(struct pg *dev, int reg, int val)
  217. {
  218. pi_write_regr(dev->pi, 0, reg, val);
  219. }
  220. static inline u8 DRIVE(struct pg *dev)
  221. {
  222. return 0xa0+0x10*dev->drive;
  223. }
  224. static void pg_sleep(int cs)
  225. {
  226. schedule_timeout_interruptible(cs);
  227. }
  228. static int pg_wait(struct pg *dev, int go, int stop, unsigned long tmo, char *msg)
  229. {
  230. int j, r, e, s, p, to;
  231. dev->status = 0;
  232. j = 0;
  233. while ((((r = status_reg(dev)) & go) || (stop && (!(r & stop))))
  234. && time_before(jiffies, tmo)) {
  235. if (j++ < PG_SPIN)
  236. udelay(PG_SPIN_DEL);
  237. else
  238. pg_sleep(1);
  239. }
  240. to = time_after_eq(jiffies, tmo);
  241. if ((r & (STAT_ERR & stop)) || to) {
  242. s = read_reg(dev, 7);
  243. e = read_reg(dev, 1);
  244. p = read_reg(dev, 2);
  245. if (verbose > 1)
  246. printk("%s: %s: stat=0x%x err=0x%x phase=%d%s\n",
  247. dev->name, msg, s, e, p, to ? " timeout" : "");
  248. if (to)
  249. e |= 0x100;
  250. dev->status = (e >> 4) & 0xff;
  251. return -1;
  252. }
  253. return 0;
  254. }
  255. static int pg_command(struct pg *dev, char *cmd, int dlen, unsigned long tmo)
  256. {
  257. int k;
  258. pi_connect(dev->pi);
  259. write_reg(dev, 6, DRIVE(dev));
  260. if (pg_wait(dev, STAT_BUSY | STAT_DRQ, 0, tmo, "before command"))
  261. goto fail;
  262. write_reg(dev, 4, dlen % 256);
  263. write_reg(dev, 5, dlen / 256);
  264. write_reg(dev, 7, 0xa0); /* ATAPI packet command */
  265. if (pg_wait(dev, STAT_BUSY, STAT_DRQ, tmo, "command DRQ"))
  266. goto fail;
  267. if (read_reg(dev, 2) != 1) {
  268. printk("%s: command phase error\n", dev->name);
  269. goto fail;
  270. }
  271. pi_write_block(dev->pi, cmd, 12);
  272. if (verbose > 1) {
  273. printk("%s: Command sent, dlen=%d packet= ", dev->name, dlen);
  274. for (k = 0; k < 12; k++)
  275. printk("%02x ", cmd[k] & 0xff);
  276. printk("\n");
  277. }
  278. return 0;
  279. fail:
  280. pi_disconnect(dev->pi);
  281. return -1;
  282. }
  283. static int pg_completion(struct pg *dev, char *buf, unsigned long tmo)
  284. {
  285. int r, d, n, p;
  286. r = pg_wait(dev, STAT_BUSY, STAT_DRQ | STAT_READY | STAT_ERR,
  287. tmo, "completion");
  288. dev->dlen = 0;
  289. while (read_reg(dev, 7) & STAT_DRQ) {
  290. d = (read_reg(dev, 4) + 256 * read_reg(dev, 5));
  291. n = ((d + 3) & 0xfffc);
  292. p = read_reg(dev, 2) & 3;
  293. if (p == 0)
  294. pi_write_block(dev->pi, buf, n);
  295. if (p == 2)
  296. pi_read_block(dev->pi, buf, n);
  297. if (verbose > 1)
  298. printk("%s: %s %d bytes\n", dev->name,
  299. p ? "Read" : "Write", n);
  300. dev->dlen += (1 - p) * d;
  301. buf += d;
  302. r = pg_wait(dev, STAT_BUSY, STAT_DRQ | STAT_READY | STAT_ERR,
  303. tmo, "completion");
  304. }
  305. pi_disconnect(dev->pi);
  306. return r;
  307. }
  308. static int pg_reset(struct pg *dev)
  309. {
  310. int i, k, err;
  311. int expect[5] = { 1, 1, 1, 0x14, 0xeb };
  312. int got[5];
  313. pi_connect(dev->pi);
  314. write_reg(dev, 6, DRIVE(dev));
  315. write_reg(dev, 7, 8);
  316. pg_sleep(20 * HZ / 1000);
  317. k = 0;
  318. while ((k++ < PG_RESET_TMO) && (status_reg(dev) & STAT_BUSY))
  319. pg_sleep(1);
  320. for (i = 0; i < 5; i++)
  321. got[i] = read_reg(dev, i + 1);
  322. err = memcmp(expect, got, sizeof(got)) ? -1 : 0;
  323. if (verbose) {
  324. printk("%s: Reset (%d) signature = ", dev->name, k);
  325. for (i = 0; i < 5; i++)
  326. printk("%3x", got[i]);
  327. if (err)
  328. printk(" (incorrect)");
  329. printk("\n");
  330. }
  331. pi_disconnect(dev->pi);
  332. return err;
  333. }
  334. static void xs(char *buf, char *targ, int len)
  335. {
  336. char l = '\0';
  337. int k;
  338. for (k = 0; k < len; k++) {
  339. char c = *buf++;
  340. if (c != ' ' && c != l)
  341. l = *targ++ = c;
  342. }
  343. if (l == ' ')
  344. targ--;
  345. *targ = '\0';
  346. }
  347. static int pg_identify(struct pg *dev, int log)
  348. {
  349. int s;
  350. char *ms[2] = { "master", "slave" };
  351. char mf[10], id[18];
  352. char id_cmd[12] = { ATAPI_IDENTIFY, 0, 0, 0, 36, 0, 0, 0, 0, 0, 0, 0 };
  353. char buf[36];
  354. s = pg_command(dev, id_cmd, 36, jiffies + PG_TMO);
  355. if (s)
  356. return -1;
  357. s = pg_completion(dev, buf, jiffies + PG_TMO);
  358. if (s)
  359. return -1;
  360. if (log) {
  361. xs(buf + 8, mf, 8);
  362. xs(buf + 16, id, 16);
  363. printk("%s: %s %s, %s\n", dev->name, mf, id, ms[dev->drive]);
  364. }
  365. return 0;
  366. }
  367. /*
  368. * returns 0, with id set if drive is detected
  369. * -1, if drive detection failed
  370. */
  371. static int pg_probe(struct pg *dev)
  372. {
  373. if (dev->drive == -1) {
  374. for (dev->drive = 0; dev->drive <= 1; dev->drive++)
  375. if (!pg_reset(dev))
  376. return pg_identify(dev, 1);
  377. } else {
  378. if (!pg_reset(dev))
  379. return pg_identify(dev, 1);
  380. }
  381. return -1;
  382. }
  383. static int pg_detect(void)
  384. {
  385. struct pg *dev = &devices[0];
  386. int k, unit;
  387. printk("%s: %s version %s, major %d\n", name, name, PG_VERSION, major);
  388. par_drv = pi_register_driver(name);
  389. if (!par_drv) {
  390. pr_err("failed to register %s driver\n", name);
  391. return -1;
  392. }
  393. k = 0;
  394. if (pg_drive_count == 0) {
  395. if (pi_init(dev->pi, 1, -1, -1, -1, -1, -1, pg_scratch,
  396. PI_PG, verbose, dev->name)) {
  397. if (!pg_probe(dev)) {
  398. dev->present = 1;
  399. k++;
  400. } else
  401. pi_release(dev->pi);
  402. }
  403. } else
  404. for (unit = 0; unit < PG_UNITS; unit++, dev++) {
  405. int *parm = *drives[unit];
  406. if (!parm[D_PRT])
  407. continue;
  408. if (pi_init(dev->pi, 0, parm[D_PRT], parm[D_MOD],
  409. parm[D_UNI], parm[D_PRO], parm[D_DLY],
  410. pg_scratch, PI_PG, verbose, dev->name)) {
  411. if (!pg_probe(dev)) {
  412. dev->present = 1;
  413. k++;
  414. } else
  415. pi_release(dev->pi);
  416. }
  417. }
  418. if (k)
  419. return 0;
  420. pi_unregister_driver(par_drv);
  421. printk("%s: No ATAPI device detected\n", name);
  422. return -1;
  423. }
  424. static int pg_open(struct inode *inode, struct file *file)
  425. {
  426. int unit = iminor(inode) & 0x7f;
  427. struct pg *dev = &devices[unit];
  428. int ret = 0;
  429. mutex_lock(&pg_mutex);
  430. if ((unit >= PG_UNITS) || (!dev->present)) {
  431. ret = -ENODEV;
  432. goto out;
  433. }
  434. if (test_and_set_bit(0, &dev->access)) {
  435. ret = -EBUSY;
  436. goto out;
  437. }
  438. if (dev->busy) {
  439. pg_reset(dev);
  440. dev->busy = 0;
  441. }
  442. pg_identify(dev, (verbose > 1));
  443. dev->bufptr = kmalloc(PG_MAX_DATA, GFP_KERNEL);
  444. if (dev->bufptr == NULL) {
  445. clear_bit(0, &dev->access);
  446. printk("%s: buffer allocation failed\n", dev->name);
  447. ret = -ENOMEM;
  448. goto out;
  449. }
  450. file->private_data = dev;
  451. out:
  452. mutex_unlock(&pg_mutex);
  453. return ret;
  454. }
  455. static int pg_release(struct inode *inode, struct file *file)
  456. {
  457. struct pg *dev = file->private_data;
  458. kfree(dev->bufptr);
  459. dev->bufptr = NULL;
  460. clear_bit(0, &dev->access);
  461. return 0;
  462. }
  463. static ssize_t pg_write(struct file *filp, const char __user *buf, size_t count, loff_t *ppos)
  464. {
  465. struct pg *dev = filp->private_data;
  466. struct pg_write_hdr hdr;
  467. int hs = sizeof (hdr);
  468. if (dev->busy)
  469. return -EBUSY;
  470. if (count < hs)
  471. return -EINVAL;
  472. if (copy_from_user(&hdr, buf, hs))
  473. return -EFAULT;
  474. if (hdr.magic != PG_MAGIC)
  475. return -EINVAL;
  476. if (hdr.dlen < 0 || hdr.dlen > PG_MAX_DATA)
  477. return -EINVAL;
  478. if ((count - hs) > PG_MAX_DATA)
  479. return -EINVAL;
  480. if (hdr.func == PG_RESET) {
  481. if (count != hs)
  482. return -EINVAL;
  483. if (pg_reset(dev))
  484. return -EIO;
  485. return count;
  486. }
  487. if (hdr.func != PG_COMMAND)
  488. return -EINVAL;
  489. dev->start = jiffies;
  490. dev->timeout = hdr.timeout * HZ + HZ / 2 + jiffies;
  491. if (pg_command(dev, hdr.packet, hdr.dlen, jiffies + PG_TMO)) {
  492. if (dev->status & 0x10)
  493. return -ETIME;
  494. return -EIO;
  495. }
  496. dev->busy = 1;
  497. if (copy_from_user(dev->bufptr, buf + hs, count - hs))
  498. return -EFAULT;
  499. return count;
  500. }
  501. static ssize_t pg_read(struct file *filp, char __user *buf, size_t count, loff_t *ppos)
  502. {
  503. struct pg *dev = filp->private_data;
  504. struct pg_read_hdr hdr;
  505. int hs = sizeof (hdr);
  506. int copy;
  507. if (!dev->busy)
  508. return -EINVAL;
  509. if (count < hs)
  510. return -EINVAL;
  511. dev->busy = 0;
  512. if (pg_completion(dev, dev->bufptr, dev->timeout))
  513. if (dev->status & 0x10)
  514. return -ETIME;
  515. memset(&hdr, 0, sizeof(hdr));
  516. hdr.magic = PG_MAGIC;
  517. hdr.dlen = dev->dlen;
  518. copy = 0;
  519. if (hdr.dlen < 0) {
  520. hdr.dlen = -1 * hdr.dlen;
  521. copy = hdr.dlen;
  522. if (copy > (count - hs))
  523. copy = count - hs;
  524. }
  525. hdr.duration = (jiffies - dev->start + HZ / 2) / HZ;
  526. hdr.scsi = dev->status & 0x0f;
  527. if (copy_to_user(buf, &hdr, hs))
  528. return -EFAULT;
  529. if (copy > 0)
  530. if (copy_to_user(buf + hs, dev->bufptr, copy))
  531. return -EFAULT;
  532. return copy + hs;
  533. }
  534. static int __init pg_init(void)
  535. {
  536. int unit;
  537. int err;
  538. if (disable){
  539. err = -EINVAL;
  540. goto out;
  541. }
  542. pg_init_units();
  543. if (pg_detect()) {
  544. err = -ENODEV;
  545. goto out;
  546. }
  547. err = register_chrdev(major, name, &pg_fops);
  548. if (err < 0) {
  549. printk("pg_init: unable to get major number %d\n", major);
  550. for (unit = 0; unit < PG_UNITS; unit++) {
  551. struct pg *dev = &devices[unit];
  552. if (dev->present)
  553. pi_release(dev->pi);
  554. }
  555. goto out;
  556. }
  557. major = err; /* In case the user specified `major=0' (dynamic) */
  558. pg_class = class_create(THIS_MODULE, "pg");
  559. if (IS_ERR(pg_class)) {
  560. err = PTR_ERR(pg_class);
  561. goto out_chrdev;
  562. }
  563. for (unit = 0; unit < PG_UNITS; unit++) {
  564. struct pg *dev = &devices[unit];
  565. if (dev->present)
  566. device_create(pg_class, NULL, MKDEV(major, unit), NULL,
  567. "pg%u", unit);
  568. }
  569. err = 0;
  570. goto out;
  571. out_chrdev:
  572. unregister_chrdev(major, "pg");
  573. out:
  574. return err;
  575. }
  576. static void __exit pg_exit(void)
  577. {
  578. int unit;
  579. for (unit = 0; unit < PG_UNITS; unit++) {
  580. struct pg *dev = &devices[unit];
  581. if (dev->present)
  582. device_destroy(pg_class, MKDEV(major, unit));
  583. }
  584. class_destroy(pg_class);
  585. unregister_chrdev(major, name);
  586. for (unit = 0; unit < PG_UNITS; unit++) {
  587. struct pg *dev = &devices[unit];
  588. if (dev->present)
  589. pi_release(dev->pi);
  590. }
  591. }
  592. MODULE_LICENSE("GPL");
  593. module_init(pg_init)
  594. module_exit(pg_exit)