spidev.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685
  1. /*
  2. * spidev.c -- simple synchronous userspace interface to SPI devices
  3. *
  4. * Copyright (C) 2006 SWAPP
  5. * Andrea Paterniani <a.paterniani@swapp-eng.it>
  6. * Copyright (C) 2007 David Brownell (simplification, cleanup)
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  21. */
  22. #include <linux/init.h>
  23. #include <linux/module.h>
  24. #include <linux/ioctl.h>
  25. #include <linux/fs.h>
  26. #include <linux/device.h>
  27. #include <linux/err.h>
  28. #include <linux/list.h>
  29. #include <linux/errno.h>
  30. #include <linux/mutex.h>
  31. #include <linux/slab.h>
  32. #include <linux/smp_lock.h>
  33. #include <linux/spi/spi.h>
  34. #include <linux/spi/spidev.h>
  35. #include <asm/uaccess.h>
  36. /*
  37. * This supports acccess to SPI devices using normal userspace I/O calls.
  38. * Note that while traditional UNIX/POSIX I/O semantics are half duplex,
  39. * and often mask message boundaries, full SPI support requires full duplex
  40. * transfers. There are several kinds of of internal message boundaries to
  41. * handle chipselect management and other protocol options.
  42. *
  43. * SPI has a character major number assigned. We allocate minor numbers
  44. * dynamically using a bitmask. You must use hotplug tools, such as udev
  45. * (or mdev with busybox) to create and destroy the /dev/spidevB.C device
  46. * nodes, since there is no fixed association of minor numbers with any
  47. * particular SPI bus or device.
  48. */
  49. #define SPIDEV_MAJOR 153 /* assigned */
  50. #define N_SPI_MINORS 32 /* ... up to 256 */
  51. static unsigned long minors[N_SPI_MINORS / BITS_PER_LONG];
  52. /* Bit masks for spi_device.mode management. Note that incorrect
  53. * settings for CS_HIGH and 3WIRE can cause *lots* of trouble for other
  54. * devices on a shared bus: CS_HIGH, because this device will be
  55. * active when it shouldn't be; 3WIRE, because when active it won't
  56. * behave as it should.
  57. *
  58. * REVISIT should changing those two modes be privileged?
  59. */
  60. #define SPI_MODE_MASK (SPI_CPHA | SPI_CPOL | SPI_CS_HIGH \
  61. | SPI_LSB_FIRST | SPI_3WIRE | SPI_LOOP)
  62. struct spidev_data {
  63. dev_t devt;
  64. spinlock_t spi_lock;
  65. struct spi_device *spi;
  66. struct list_head device_entry;
  67. /* buffer is NULL unless this device is open (users > 0) */
  68. struct mutex buf_lock;
  69. unsigned users;
  70. u8 *buffer;
  71. };
  72. static LIST_HEAD(device_list);
  73. static DEFINE_MUTEX(device_list_lock);
  74. static unsigned bufsiz = 4096;
  75. module_param(bufsiz, uint, S_IRUGO);
  76. MODULE_PARM_DESC(bufsiz, "data bytes in biggest supported SPI message");
  77. /*-------------------------------------------------------------------------*/
  78. /*
  79. * We can't use the standard synchronous wrappers for file I/O; we
  80. * need to protect against async removal of the underlying spi_device.
  81. */
  82. static void spidev_complete(void *arg)
  83. {
  84. complete(arg);
  85. }
  86. static ssize_t
  87. spidev_sync(struct spidev_data *spidev, struct spi_message *message)
  88. {
  89. DECLARE_COMPLETION_ONSTACK(done);
  90. int status;
  91. message->complete = spidev_complete;
  92. message->context = &done;
  93. spin_lock_irq(&spidev->spi_lock);
  94. if (spidev->spi == NULL)
  95. status = -ESHUTDOWN;
  96. else
  97. status = spi_async(spidev->spi, message);
  98. spin_unlock_irq(&spidev->spi_lock);
  99. if (status == 0) {
  100. wait_for_completion(&done);
  101. status = message->status;
  102. if (status == 0)
  103. status = message->actual_length;
  104. }
  105. return status;
  106. }
  107. static inline ssize_t
  108. spidev_sync_write(struct spidev_data *spidev, size_t len)
  109. {
  110. struct spi_transfer t = {
  111. .tx_buf = spidev->buffer,
  112. .len = len,
  113. };
  114. struct spi_message m;
  115. spi_message_init(&m);
  116. spi_message_add_tail(&t, &m);
  117. return spidev_sync(spidev, &m);
  118. }
  119. static inline ssize_t
  120. spidev_sync_read(struct spidev_data *spidev, size_t len)
  121. {
  122. struct spi_transfer t = {
  123. .rx_buf = spidev->buffer,
  124. .len = len,
  125. };
  126. struct spi_message m;
  127. spi_message_init(&m);
  128. spi_message_add_tail(&t, &m);
  129. return spidev_sync(spidev, &m);
  130. }
  131. /*-------------------------------------------------------------------------*/
  132. /* Read-only message with current device setup */
  133. static ssize_t
  134. spidev_read(struct file *filp, char __user *buf, size_t count, loff_t *f_pos)
  135. {
  136. struct spidev_data *spidev;
  137. ssize_t status = 0;
  138. /* chipselect only toggles at start or end of operation */
  139. if (count > bufsiz)
  140. return -EMSGSIZE;
  141. spidev = filp->private_data;
  142. mutex_lock(&spidev->buf_lock);
  143. status = spidev_sync_read(spidev, count);
  144. if (status > 0) {
  145. unsigned long missing;
  146. missing = copy_to_user(buf, spidev->buffer, status);
  147. if (missing == status)
  148. status = -EFAULT;
  149. else
  150. status = status - missing;
  151. }
  152. mutex_unlock(&spidev->buf_lock);
  153. return status;
  154. }
  155. /* Write-only message with current device setup */
  156. static ssize_t
  157. spidev_write(struct file *filp, const char __user *buf,
  158. size_t count, loff_t *f_pos)
  159. {
  160. struct spidev_data *spidev;
  161. ssize_t status = 0;
  162. unsigned long missing;
  163. /* chipselect only toggles at start or end of operation */
  164. if (count > bufsiz)
  165. return -EMSGSIZE;
  166. spidev = filp->private_data;
  167. mutex_lock(&spidev->buf_lock);
  168. missing = copy_from_user(spidev->buffer, buf, count);
  169. if (missing == 0) {
  170. status = spidev_sync_write(spidev, count);
  171. } else
  172. status = -EFAULT;
  173. mutex_unlock(&spidev->buf_lock);
  174. return status;
  175. }
  176. static int spidev_message(struct spidev_data *spidev,
  177. struct spi_ioc_transfer *u_xfers, unsigned n_xfers)
  178. {
  179. struct spi_message msg;
  180. struct spi_transfer *k_xfers;
  181. struct spi_transfer *k_tmp;
  182. struct spi_ioc_transfer *u_tmp;
  183. unsigned n, total;
  184. u8 *buf;
  185. int status = -EFAULT;
  186. spi_message_init(&msg);
  187. k_xfers = kcalloc(n_xfers, sizeof(*k_tmp), GFP_KERNEL);
  188. if (k_xfers == NULL)
  189. return -ENOMEM;
  190. /* Construct spi_message, copying any tx data to bounce buffer.
  191. * We walk the array of user-provided transfers, using each one
  192. * to initialize a kernel version of the same transfer.
  193. */
  194. buf = spidev->buffer;
  195. total = 0;
  196. for (n = n_xfers, k_tmp = k_xfers, u_tmp = u_xfers;
  197. n;
  198. n--, k_tmp++, u_tmp++) {
  199. k_tmp->len = u_tmp->len;
  200. total += k_tmp->len;
  201. if (total > bufsiz) {
  202. status = -EMSGSIZE;
  203. goto done;
  204. }
  205. if (u_tmp->rx_buf) {
  206. k_tmp->rx_buf = buf;
  207. if (!access_ok(VERIFY_WRITE, (u8 __user *)
  208. (uintptr_t) u_tmp->rx_buf,
  209. u_tmp->len))
  210. goto done;
  211. }
  212. if (u_tmp->tx_buf) {
  213. k_tmp->tx_buf = buf;
  214. if (copy_from_user(buf, (const u8 __user *)
  215. (uintptr_t) u_tmp->tx_buf,
  216. u_tmp->len))
  217. goto done;
  218. }
  219. buf += k_tmp->len;
  220. k_tmp->cs_change = !!u_tmp->cs_change;
  221. k_tmp->bits_per_word = u_tmp->bits_per_word;
  222. k_tmp->delay_usecs = u_tmp->delay_usecs;
  223. k_tmp->speed_hz = u_tmp->speed_hz;
  224. #ifdef VERBOSE
  225. dev_dbg(&spi->dev,
  226. " xfer len %zd %s%s%s%dbits %u usec %uHz\n",
  227. u_tmp->len,
  228. u_tmp->rx_buf ? "rx " : "",
  229. u_tmp->tx_buf ? "tx " : "",
  230. u_tmp->cs_change ? "cs " : "",
  231. u_tmp->bits_per_word ? : spi->bits_per_word,
  232. u_tmp->delay_usecs,
  233. u_tmp->speed_hz ? : spi->max_speed_hz);
  234. #endif
  235. spi_message_add_tail(k_tmp, &msg);
  236. }
  237. status = spidev_sync(spidev, &msg);
  238. if (status < 0)
  239. goto done;
  240. /* copy any rx data out of bounce buffer */
  241. buf = spidev->buffer;
  242. for (n = n_xfers, u_tmp = u_xfers; n; n--, u_tmp++) {
  243. if (u_tmp->rx_buf) {
  244. if (__copy_to_user((u8 __user *)
  245. (uintptr_t) u_tmp->rx_buf, buf,
  246. u_tmp->len)) {
  247. status = -EFAULT;
  248. goto done;
  249. }
  250. }
  251. buf += u_tmp->len;
  252. }
  253. status = total;
  254. done:
  255. kfree(k_xfers);
  256. return status;
  257. }
  258. static long
  259. spidev_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
  260. {
  261. int err = 0;
  262. int retval = 0;
  263. struct spidev_data *spidev;
  264. struct spi_device *spi;
  265. u32 tmp;
  266. unsigned n_ioc;
  267. struct spi_ioc_transfer *ioc;
  268. /* Check type and command number */
  269. if (_IOC_TYPE(cmd) != SPI_IOC_MAGIC)
  270. return -ENOTTY;
  271. /* Check access direction once here; don't repeat below.
  272. * IOC_DIR is from the user perspective, while access_ok is
  273. * from the kernel perspective; so they look reversed.
  274. */
  275. if (_IOC_DIR(cmd) & _IOC_READ)
  276. err = !access_ok(VERIFY_WRITE,
  277. (void __user *)arg, _IOC_SIZE(cmd));
  278. if (err == 0 && _IOC_DIR(cmd) & _IOC_WRITE)
  279. err = !access_ok(VERIFY_READ,
  280. (void __user *)arg, _IOC_SIZE(cmd));
  281. if (err)
  282. return -EFAULT;
  283. /* guard against device removal before, or while,
  284. * we issue this ioctl.
  285. */
  286. spidev = filp->private_data;
  287. spin_lock_irq(&spidev->spi_lock);
  288. spi = spi_dev_get(spidev->spi);
  289. spin_unlock_irq(&spidev->spi_lock);
  290. if (spi == NULL)
  291. return -ESHUTDOWN;
  292. /* use the buffer lock here for triple duty:
  293. * - prevent I/O (from us) so calling spi_setup() is safe;
  294. * - prevent concurrent SPI_IOC_WR_* from morphing
  295. * data fields while SPI_IOC_RD_* reads them;
  296. * - SPI_IOC_MESSAGE needs the buffer locked "normally".
  297. */
  298. mutex_lock(&spidev->buf_lock);
  299. switch (cmd) {
  300. /* read requests */
  301. case SPI_IOC_RD_MODE:
  302. retval = __put_user(spi->mode & SPI_MODE_MASK,
  303. (__u8 __user *)arg);
  304. break;
  305. case SPI_IOC_RD_LSB_FIRST:
  306. retval = __put_user((spi->mode & SPI_LSB_FIRST) ? 1 : 0,
  307. (__u8 __user *)arg);
  308. break;
  309. case SPI_IOC_RD_BITS_PER_WORD:
  310. retval = __put_user(spi->bits_per_word, (__u8 __user *)arg);
  311. break;
  312. case SPI_IOC_RD_MAX_SPEED_HZ:
  313. retval = __put_user(spi->max_speed_hz, (__u32 __user *)arg);
  314. break;
  315. /* write requests */
  316. case SPI_IOC_WR_MODE:
  317. retval = __get_user(tmp, (u8 __user *)arg);
  318. if (retval == 0) {
  319. u8 save = spi->mode;
  320. if (tmp & ~SPI_MODE_MASK) {
  321. retval = -EINVAL;
  322. break;
  323. }
  324. tmp |= spi->mode & ~SPI_MODE_MASK;
  325. spi->mode = (u8)tmp;
  326. retval = spi_setup(spi);
  327. if (retval < 0)
  328. spi->mode = save;
  329. else
  330. dev_dbg(&spi->dev, "spi mode %02x\n", tmp);
  331. }
  332. break;
  333. case SPI_IOC_WR_LSB_FIRST:
  334. retval = __get_user(tmp, (__u8 __user *)arg);
  335. if (retval == 0) {
  336. u8 save = spi->mode;
  337. if (tmp)
  338. spi->mode |= SPI_LSB_FIRST;
  339. else
  340. spi->mode &= ~SPI_LSB_FIRST;
  341. retval = spi_setup(spi);
  342. if (retval < 0)
  343. spi->mode = save;
  344. else
  345. dev_dbg(&spi->dev, "%csb first\n",
  346. tmp ? 'l' : 'm');
  347. }
  348. break;
  349. case SPI_IOC_WR_BITS_PER_WORD:
  350. retval = __get_user(tmp, (__u8 __user *)arg);
  351. if (retval == 0) {
  352. u8 save = spi->bits_per_word;
  353. spi->bits_per_word = tmp;
  354. retval = spi_setup(spi);
  355. if (retval < 0)
  356. spi->bits_per_word = save;
  357. else
  358. dev_dbg(&spi->dev, "%d bits per word\n", tmp);
  359. }
  360. break;
  361. case SPI_IOC_WR_MAX_SPEED_HZ:
  362. retval = __get_user(tmp, (__u32 __user *)arg);
  363. if (retval == 0) {
  364. u32 save = spi->max_speed_hz;
  365. spi->max_speed_hz = tmp;
  366. retval = spi_setup(spi);
  367. if (retval < 0)
  368. spi->max_speed_hz = save;
  369. else
  370. dev_dbg(&spi->dev, "%d Hz (max)\n", tmp);
  371. }
  372. break;
  373. default:
  374. /* segmented and/or full-duplex I/O request */
  375. if (_IOC_NR(cmd) != _IOC_NR(SPI_IOC_MESSAGE(0))
  376. || _IOC_DIR(cmd) != _IOC_WRITE) {
  377. retval = -ENOTTY;
  378. break;
  379. }
  380. tmp = _IOC_SIZE(cmd);
  381. if ((tmp % sizeof(struct spi_ioc_transfer)) != 0) {
  382. retval = -EINVAL;
  383. break;
  384. }
  385. n_ioc = tmp / sizeof(struct spi_ioc_transfer);
  386. if (n_ioc == 0)
  387. break;
  388. /* copy into scratch area */
  389. ioc = kmalloc(tmp, GFP_KERNEL);
  390. if (!ioc) {
  391. retval = -ENOMEM;
  392. break;
  393. }
  394. if (__copy_from_user(ioc, (void __user *)arg, tmp)) {
  395. kfree(ioc);
  396. retval = -EFAULT;
  397. break;
  398. }
  399. /* translate to spi_message, execute */
  400. retval = spidev_message(spidev, ioc, n_ioc);
  401. kfree(ioc);
  402. break;
  403. }
  404. mutex_unlock(&spidev->buf_lock);
  405. spi_dev_put(spi);
  406. return retval;
  407. }
  408. static int spidev_open(struct inode *inode, struct file *filp)
  409. {
  410. struct spidev_data *spidev;
  411. int status = -ENXIO;
  412. lock_kernel();
  413. mutex_lock(&device_list_lock);
  414. list_for_each_entry(spidev, &device_list, device_entry) {
  415. if (spidev->devt == inode->i_rdev) {
  416. status = 0;
  417. break;
  418. }
  419. }
  420. if (status == 0) {
  421. if (!spidev->buffer) {
  422. spidev->buffer = kmalloc(bufsiz, GFP_KERNEL);
  423. if (!spidev->buffer) {
  424. dev_dbg(&spidev->spi->dev, "open/ENOMEM\n");
  425. status = -ENOMEM;
  426. }
  427. }
  428. if (status == 0) {
  429. spidev->users++;
  430. filp->private_data = spidev;
  431. nonseekable_open(inode, filp);
  432. }
  433. } else
  434. pr_debug("spidev: nothing for minor %d\n", iminor(inode));
  435. mutex_unlock(&device_list_lock);
  436. unlock_kernel();
  437. return status;
  438. }
  439. static int spidev_release(struct inode *inode, struct file *filp)
  440. {
  441. struct spidev_data *spidev;
  442. int status = 0;
  443. mutex_lock(&device_list_lock);
  444. spidev = filp->private_data;
  445. filp->private_data = NULL;
  446. /* last close? */
  447. spidev->users--;
  448. if (!spidev->users) {
  449. int dofree;
  450. kfree(spidev->buffer);
  451. spidev->buffer = NULL;
  452. /* ... after we unbound from the underlying device? */
  453. spin_lock_irq(&spidev->spi_lock);
  454. dofree = (spidev->spi == NULL);
  455. spin_unlock_irq(&spidev->spi_lock);
  456. if (dofree)
  457. kfree(spidev);
  458. }
  459. mutex_unlock(&device_list_lock);
  460. return status;
  461. }
  462. static struct file_operations spidev_fops = {
  463. .owner = THIS_MODULE,
  464. /* REVISIT switch to aio primitives, so that userspace
  465. * gets more complete API coverage. It'll simplify things
  466. * too, except for the locking.
  467. */
  468. .write = spidev_write,
  469. .read = spidev_read,
  470. .unlocked_ioctl = spidev_ioctl,
  471. .open = spidev_open,
  472. .release = spidev_release,
  473. };
  474. /*-------------------------------------------------------------------------*/
  475. /* The main reason to have this class is to make mdev/udev create the
  476. * /dev/spidevB.C character device nodes exposing our userspace API.
  477. * It also simplifies memory management.
  478. */
  479. static struct class *spidev_class;
  480. /*-------------------------------------------------------------------------*/
  481. static int spidev_probe(struct spi_device *spi)
  482. {
  483. struct spidev_data *spidev;
  484. int status;
  485. unsigned long minor;
  486. /* Allocate driver data */
  487. spidev = kzalloc(sizeof(*spidev), GFP_KERNEL);
  488. if (!spidev)
  489. return -ENOMEM;
  490. /* Initialize the driver data */
  491. spidev->spi = spi;
  492. spin_lock_init(&spidev->spi_lock);
  493. mutex_init(&spidev->buf_lock);
  494. INIT_LIST_HEAD(&spidev->device_entry);
  495. /* If we can allocate a minor number, hook up this device.
  496. * Reusing minors is fine so long as udev or mdev is working.
  497. */
  498. mutex_lock(&device_list_lock);
  499. minor = find_first_zero_bit(minors, N_SPI_MINORS);
  500. if (minor < N_SPI_MINORS) {
  501. struct device *dev;
  502. spidev->devt = MKDEV(SPIDEV_MAJOR, minor);
  503. dev = device_create(spidev_class, &spi->dev, spidev->devt,
  504. spidev, "spidev%d.%d",
  505. spi->master->bus_num, spi->chip_select);
  506. status = IS_ERR(dev) ? PTR_ERR(dev) : 0;
  507. } else {
  508. dev_dbg(&spi->dev, "no minor number available!\n");
  509. status = -ENODEV;
  510. }
  511. if (status == 0) {
  512. set_bit(minor, minors);
  513. list_add(&spidev->device_entry, &device_list);
  514. }
  515. mutex_unlock(&device_list_lock);
  516. if (status == 0)
  517. spi_set_drvdata(spi, spidev);
  518. else
  519. kfree(spidev);
  520. return status;
  521. }
  522. static int spidev_remove(struct spi_device *spi)
  523. {
  524. struct spidev_data *spidev = spi_get_drvdata(spi);
  525. /* make sure ops on existing fds can abort cleanly */
  526. spin_lock_irq(&spidev->spi_lock);
  527. spidev->spi = NULL;
  528. spi_set_drvdata(spi, NULL);
  529. spin_unlock_irq(&spidev->spi_lock);
  530. /* prevent new opens */
  531. mutex_lock(&device_list_lock);
  532. list_del(&spidev->device_entry);
  533. device_destroy(spidev_class, spidev->devt);
  534. clear_bit(MINOR(spidev->devt), minors);
  535. if (spidev->users == 0)
  536. kfree(spidev);
  537. mutex_unlock(&device_list_lock);
  538. return 0;
  539. }
  540. static struct spi_driver spidev_spi = {
  541. .driver = {
  542. .name = "spidev",
  543. .owner = THIS_MODULE,
  544. },
  545. .probe = spidev_probe,
  546. .remove = __devexit_p(spidev_remove),
  547. /* NOTE: suspend/resume methods are not necessary here.
  548. * We don't do anything except pass the requests to/from
  549. * the underlying controller. The refrigerator handles
  550. * most issues; the controller driver handles the rest.
  551. */
  552. };
  553. /*-------------------------------------------------------------------------*/
  554. static int __init spidev_init(void)
  555. {
  556. int status;
  557. /* Claim our 256 reserved device numbers. Then register a class
  558. * that will key udev/mdev to add/remove /dev nodes. Last, register
  559. * the driver which manages those device numbers.
  560. */
  561. BUILD_BUG_ON(N_SPI_MINORS > 256);
  562. status = register_chrdev(SPIDEV_MAJOR, "spi", &spidev_fops);
  563. if (status < 0)
  564. return status;
  565. spidev_class = class_create(THIS_MODULE, "spidev");
  566. if (IS_ERR(spidev_class)) {
  567. unregister_chrdev(SPIDEV_MAJOR, spidev_spi.driver.name);
  568. return PTR_ERR(spidev_class);
  569. }
  570. status = spi_register_driver(&spidev_spi);
  571. if (status < 0) {
  572. class_destroy(spidev_class);
  573. unregister_chrdev(SPIDEV_MAJOR, spidev_spi.driver.name);
  574. }
  575. return status;
  576. }
  577. module_init(spidev_init);
  578. static void __exit spidev_exit(void)
  579. {
  580. spi_unregister_driver(&spidev_spi);
  581. class_destroy(spidev_class);
  582. unregister_chrdev(SPIDEV_MAJOR, spidev_spi.driver.name);
  583. }
  584. module_exit(spidev_exit);
  585. MODULE_AUTHOR("Andrea Paterniani, <a.paterniani@swapp-eng.it>");
  586. MODULE_DESCRIPTION("User mode SPI device interface");
  587. MODULE_LICENSE("GPL");