bcm63138_nand.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /*
  2. * Copyright © 2015 Broadcom Corporation
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License version 2 as
  6. * published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. */
  13. #include <linux/device.h>
  14. #include <linux/io.h>
  15. #include <linux/ioport.h>
  16. #include <linux/module.h>
  17. #include <linux/of.h>
  18. #include <linux/of_address.h>
  19. #include <linux/platform_device.h>
  20. #include <linux/slab.h>
  21. #include "brcmnand.h"
  22. struct bcm63138_nand_soc {
  23. struct brcmnand_soc soc;
  24. void __iomem *base;
  25. };
  26. #define BCM63138_NAND_INT_STATUS 0x00
  27. #define BCM63138_NAND_INT_EN 0x04
  28. enum {
  29. BCM63138_CTLRDY = BIT(4),
  30. };
  31. static bool bcm63138_nand_intc_ack(struct brcmnand_soc *soc)
  32. {
  33. struct bcm63138_nand_soc *priv =
  34. container_of(soc, struct bcm63138_nand_soc, soc);
  35. void __iomem *mmio = priv->base + BCM63138_NAND_INT_STATUS;
  36. u32 val = brcmnand_readl(mmio);
  37. if (val & BCM63138_CTLRDY) {
  38. brcmnand_writel(val & ~BCM63138_CTLRDY, mmio);
  39. return true;
  40. }
  41. return false;
  42. }
  43. static void bcm63138_nand_intc_set(struct brcmnand_soc *soc, bool en)
  44. {
  45. struct bcm63138_nand_soc *priv =
  46. container_of(soc, struct bcm63138_nand_soc, soc);
  47. void __iomem *mmio = priv->base + BCM63138_NAND_INT_EN;
  48. u32 val = brcmnand_readl(mmio);
  49. if (en)
  50. val |= BCM63138_CTLRDY;
  51. else
  52. val &= ~BCM63138_CTLRDY;
  53. brcmnand_writel(val, mmio);
  54. }
  55. static int bcm63138_nand_probe(struct platform_device *pdev)
  56. {
  57. struct device *dev = &pdev->dev;
  58. struct bcm63138_nand_soc *priv;
  59. struct brcmnand_soc *soc;
  60. struct resource *res;
  61. priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
  62. if (!priv)
  63. return -ENOMEM;
  64. soc = &priv->soc;
  65. res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "nand-int-base");
  66. priv->base = devm_ioremap_resource(dev, res);
  67. if (IS_ERR(priv->base))
  68. return PTR_ERR(priv->base);
  69. soc->ctlrdy_ack = bcm63138_nand_intc_ack;
  70. soc->ctlrdy_set_enabled = bcm63138_nand_intc_set;
  71. return brcmnand_probe(pdev, soc);
  72. }
  73. static const struct of_device_id bcm63138_nand_of_match[] = {
  74. { .compatible = "brcm,nand-bcm63138" },
  75. {},
  76. };
  77. MODULE_DEVICE_TABLE(of, bcm63138_nand_of_match);
  78. static struct platform_driver bcm63138_nand_driver = {
  79. .probe = bcm63138_nand_probe,
  80. .remove = brcmnand_remove,
  81. .driver = {
  82. .name = "bcm63138_nand",
  83. .pm = &brcmnand_pm_ops,
  84. .of_match_table = bcm63138_nand_of_match,
  85. }
  86. };
  87. module_platform_driver(bcm63138_nand_driver);
  88. MODULE_LICENSE("GPL v2");
  89. MODULE_AUTHOR("Brian Norris");
  90. MODULE_DESCRIPTION("NAND driver for BCM63138");