xilinx_spi_pltfm.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /*
  2. * Support for Xilinx SPI platform devices
  3. * Copyright (c) 2009 Intel Corporation
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License version 2 as
  7. * published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  17. */
  18. /* Supports:
  19. * Xilinx SPI devices as platform devices
  20. *
  21. * Inspired by xilinx_spi.c, 2002-2007 (c) MontaVista Software, Inc.
  22. */
  23. #include <linux/module.h>
  24. #include <linux/init.h>
  25. #include <linux/interrupt.h>
  26. #include <linux/io.h>
  27. #include <linux/platform_device.h>
  28. #include <linux/spi/spi.h>
  29. #include <linux/spi/spi_bitbang.h>
  30. #include <linux/spi/xilinx_spi.h>
  31. #include "xilinx_spi.h"
  32. static int __devinit xilinx_spi_probe(struct platform_device *dev)
  33. {
  34. struct xspi_platform_data *pdata;
  35. struct resource *r;
  36. int irq;
  37. struct spi_master *master;
  38. u8 i;
  39. pdata = dev->dev.platform_data;
  40. if (!pdata)
  41. return -ENODEV;
  42. r = platform_get_resource(dev, IORESOURCE_MEM, 0);
  43. if (!r)
  44. return -ENODEV;
  45. irq = platform_get_irq(dev, 0);
  46. if (irq < 0)
  47. return -ENXIO;
  48. master = xilinx_spi_init(&dev->dev, r, irq, dev->id);
  49. if (!master)
  50. return -ENODEV;
  51. for (i = 0; i < pdata->num_devices; i++)
  52. spi_new_device(master, pdata->devices + i);
  53. platform_set_drvdata(dev, master);
  54. return 0;
  55. }
  56. static int __devexit xilinx_spi_remove(struct platform_device *dev)
  57. {
  58. xilinx_spi_deinit(platform_get_drvdata(dev));
  59. platform_set_drvdata(dev, 0);
  60. return 0;
  61. }
  62. /* work with hotplug and coldplug */
  63. MODULE_ALIAS("platform:" XILINX_SPI_NAME);
  64. static struct platform_driver xilinx_spi_driver = {
  65. .probe = xilinx_spi_probe,
  66. .remove = __devexit_p(xilinx_spi_remove),
  67. .driver = {
  68. .name = XILINX_SPI_NAME,
  69. .owner = THIS_MODULE,
  70. },
  71. };
  72. static int __init xilinx_spi_pltfm_init(void)
  73. {
  74. return platform_driver_register(&xilinx_spi_driver);
  75. }
  76. module_init(xilinx_spi_pltfm_init);
  77. static void __exit xilinx_spi_pltfm_exit(void)
  78. {
  79. platform_driver_unregister(&xilinx_spi_driver);
  80. }
  81. module_exit(xilinx_spi_pltfm_exit);
  82. MODULE_AUTHOR("Mocean Laboratories <info@mocean-labs.com>");
  83. MODULE_DESCRIPTION("Xilinx SPI platform driver");
  84. MODULE_LICENSE("GPL v2");