spi-dw-mmio.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /*
  2. * Memory-mapped interface driver for DW SPI Core
  3. *
  4. * Copyright (c) 2010, Octasic semiconductor.
  5. *
  6. * This program is free software; you can redistribute it and/or modify it
  7. * under the terms and conditions of the GNU General Public License,
  8. * version 2, as published by the Free Software Foundation.
  9. */
  10. #include <linux/clk.h>
  11. #include <linux/err.h>
  12. #include <linux/interrupt.h>
  13. #include <linux/platform_device.h>
  14. #include <linux/slab.h>
  15. #include <linux/spi/spi.h>
  16. #include <linux/scatterlist.h>
  17. #include <linux/module.h>
  18. #include "spi-dw.h"
  19. #define DRIVER_NAME "dw_spi_mmio"
  20. struct dw_spi_mmio {
  21. struct dw_spi dws;
  22. struct clk *clk;
  23. };
  24. static int dw_spi_mmio_probe(struct platform_device *pdev)
  25. {
  26. struct dw_spi_mmio *dwsmmio;
  27. struct dw_spi *dws;
  28. struct resource *mem;
  29. int ret;
  30. dwsmmio = devm_kzalloc(&pdev->dev, sizeof(struct dw_spi_mmio),
  31. GFP_KERNEL);
  32. if (!dwsmmio)
  33. return -ENOMEM;
  34. dws = &dwsmmio->dws;
  35. /* Get basic io resource and map it */
  36. mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  37. if (!mem) {
  38. dev_err(&pdev->dev, "no mem resource?\n");
  39. return -EINVAL;
  40. }
  41. dws->regs = devm_ioremap_resource(&pdev->dev, mem);
  42. if (IS_ERR(dws->regs)) {
  43. dev_err(&pdev->dev, "SPI region map failed\n");
  44. return PTR_ERR(dws->regs);
  45. }
  46. dws->irq = platform_get_irq(pdev, 0);
  47. if (dws->irq < 0) {
  48. dev_err(&pdev->dev, "no irq resource?\n");
  49. return dws->irq; /* -ENXIO */
  50. }
  51. dwsmmio->clk = devm_clk_get(&pdev->dev, NULL);
  52. if (IS_ERR(dwsmmio->clk))
  53. return PTR_ERR(dwsmmio->clk);
  54. ret = clk_prepare_enable(dwsmmio->clk);
  55. if (ret)
  56. return ret;
  57. dws->bus_num = pdev->id;
  58. dws->num_cs = 4;
  59. dws->max_freq = clk_get_rate(dwsmmio->clk);
  60. ret = dw_spi_add_host(&pdev->dev, dws);
  61. if (ret)
  62. goto out;
  63. platform_set_drvdata(pdev, dwsmmio);
  64. return 0;
  65. out:
  66. clk_disable_unprepare(dwsmmio->clk);
  67. return ret;
  68. }
  69. static int dw_spi_mmio_remove(struct platform_device *pdev)
  70. {
  71. struct dw_spi_mmio *dwsmmio = platform_get_drvdata(pdev);
  72. clk_disable_unprepare(dwsmmio->clk);
  73. dw_spi_remove_host(&dwsmmio->dws);
  74. return 0;
  75. }
  76. static struct platform_driver dw_spi_mmio_driver = {
  77. .probe = dw_spi_mmio_probe,
  78. .remove = dw_spi_mmio_remove,
  79. .driver = {
  80. .name = DRIVER_NAME,
  81. .owner = THIS_MODULE,
  82. },
  83. };
  84. module_platform_driver(dw_spi_mmio_driver);
  85. MODULE_AUTHOR("Jean-Hugues Deschenes <jean-hugues.deschenes@octasic.com>");
  86. MODULE_DESCRIPTION("Memory-mapped I/O interface driver for DW SPI Core");
  87. MODULE_LICENSE("GPL v2");