spi-iproc-qspi.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright 2016 Broadcom Limited
  4. */
  5. #include <linux/device.h>
  6. #include <linux/io.h>
  7. #include <linux/ioport.h>
  8. #include <linux/module.h>
  9. #include <linux/of.h>
  10. #include <linux/of_address.h>
  11. #include <linux/platform_device.h>
  12. #include <linux/slab.h>
  13. #include "spi-bcm-qspi.h"
  14. #define INTR_BASE_BIT_SHIFT 0x02
  15. #define INTR_COUNT 0x07
  16. struct bcm_iproc_intc {
  17. struct bcm_qspi_soc_intc soc_intc;
  18. struct platform_device *pdev;
  19. void __iomem *int_reg;
  20. void __iomem *int_status_reg;
  21. spinlock_t soclock;
  22. bool big_endian;
  23. };
  24. static u32 bcm_iproc_qspi_get_l2_int_status(struct bcm_qspi_soc_intc *soc_intc)
  25. {
  26. struct bcm_iproc_intc *priv =
  27. container_of(soc_intc, struct bcm_iproc_intc, soc_intc);
  28. void __iomem *mmio = priv->int_status_reg;
  29. int i;
  30. u32 val = 0, sts = 0;
  31. for (i = 0; i < INTR_COUNT; i++) {
  32. if (bcm_qspi_readl(priv->big_endian, mmio + (i * 4)))
  33. val |= 1UL << i;
  34. }
  35. if (val & INTR_MSPI_DONE_MASK)
  36. sts |= MSPI_DONE;
  37. if (val & BSPI_LR_INTERRUPTS_ALL)
  38. sts |= BSPI_DONE;
  39. if (val & BSPI_LR_INTERRUPTS_ERROR)
  40. sts |= BSPI_ERR;
  41. return sts;
  42. }
  43. static void bcm_iproc_qspi_int_ack(struct bcm_qspi_soc_intc *soc_intc, int type)
  44. {
  45. struct bcm_iproc_intc *priv =
  46. container_of(soc_intc, struct bcm_iproc_intc, soc_intc);
  47. void __iomem *mmio = priv->int_status_reg;
  48. u32 mask = get_qspi_mask(type);
  49. int i;
  50. for (i = 0; i < INTR_COUNT; i++) {
  51. if (mask & (1UL << i))
  52. bcm_qspi_writel(priv->big_endian, 1, mmio + (i * 4));
  53. }
  54. }
  55. static void bcm_iproc_qspi_int_set(struct bcm_qspi_soc_intc *soc_intc, int type,
  56. bool en)
  57. {
  58. struct bcm_iproc_intc *priv =
  59. container_of(soc_intc, struct bcm_iproc_intc, soc_intc);
  60. void __iomem *mmio = priv->int_reg;
  61. u32 mask = get_qspi_mask(type);
  62. u32 val;
  63. unsigned long flags;
  64. spin_lock_irqsave(&priv->soclock, flags);
  65. val = bcm_qspi_readl(priv->big_endian, mmio);
  66. if (en)
  67. val = val | (mask << INTR_BASE_BIT_SHIFT);
  68. else
  69. val = val & ~(mask << INTR_BASE_BIT_SHIFT);
  70. bcm_qspi_writel(priv->big_endian, val, mmio);
  71. spin_unlock_irqrestore(&priv->soclock, flags);
  72. }
  73. static int bcm_iproc_probe(struct platform_device *pdev)
  74. {
  75. struct device *dev = &pdev->dev;
  76. struct bcm_iproc_intc *priv;
  77. struct bcm_qspi_soc_intc *soc_intc;
  78. struct resource *res;
  79. priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
  80. if (!priv)
  81. return -ENOMEM;
  82. soc_intc = &priv->soc_intc;
  83. priv->pdev = pdev;
  84. spin_lock_init(&priv->soclock);
  85. res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "intr_regs");
  86. priv->int_reg = devm_ioremap_resource(dev, res);
  87. if (IS_ERR(priv->int_reg))
  88. return PTR_ERR(priv->int_reg);
  89. res = platform_get_resource_byname(pdev, IORESOURCE_MEM,
  90. "intr_status_reg");
  91. priv->int_status_reg = devm_ioremap_resource(dev, res);
  92. if (IS_ERR(priv->int_status_reg))
  93. return PTR_ERR(priv->int_status_reg);
  94. priv->big_endian = of_device_is_big_endian(dev->of_node);
  95. bcm_iproc_qspi_int_ack(soc_intc, MSPI_BSPI_DONE);
  96. bcm_iproc_qspi_int_set(soc_intc, MSPI_BSPI_DONE, false);
  97. soc_intc->bcm_qspi_int_ack = bcm_iproc_qspi_int_ack;
  98. soc_intc->bcm_qspi_int_set = bcm_iproc_qspi_int_set;
  99. soc_intc->bcm_qspi_get_int_status = bcm_iproc_qspi_get_l2_int_status;
  100. return bcm_qspi_probe(pdev, soc_intc);
  101. }
  102. static int bcm_iproc_remove(struct platform_device *pdev)
  103. {
  104. return bcm_qspi_remove(pdev);
  105. }
  106. static const struct of_device_id bcm_iproc_of_match[] = {
  107. { .compatible = "brcm,spi-nsp-qspi" },
  108. { .compatible = "brcm,spi-ns2-qspi" },
  109. {},
  110. };
  111. MODULE_DEVICE_TABLE(of, bcm_iproc_of_match);
  112. static struct platform_driver bcm_iproc_driver = {
  113. .probe = bcm_iproc_probe,
  114. .remove = bcm_iproc_remove,
  115. .driver = {
  116. .name = "bcm_iproc",
  117. .pm = &bcm_qspi_pm_ops,
  118. .of_match_table = bcm_iproc_of_match,
  119. }
  120. };
  121. module_platform_driver(bcm_iproc_driver);
  122. MODULE_LICENSE("GPL v2");
  123. MODULE_AUTHOR("Kamal Dasu");
  124. MODULE_DESCRIPTION("SPI flash driver for Broadcom iProc SoCs");