bcm6368_nand.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. /*
  2. * Copyright 2015 Simon Arlott
  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. * Derived from bcm63138_nand.c:
  14. * Copyright © 2015 Broadcom Corporation
  15. *
  16. * Derived from bcm963xx_4.12L.06B_consumer/shared/opensource/include/bcm963xx/63268_map_part.h:
  17. * Copyright 2000-2010 Broadcom Corporation
  18. *
  19. * Derived from bcm963xx_4.12L.06B_consumer/shared/opensource/flash/nandflash.c:
  20. * Copyright 2000-2010 Broadcom Corporation
  21. */
  22. #include <linux/device.h>
  23. #include <linux/io.h>
  24. #include <linux/ioport.h>
  25. #include <linux/module.h>
  26. #include <linux/of.h>
  27. #include <linux/of_address.h>
  28. #include <linux/platform_device.h>
  29. #include <linux/slab.h>
  30. #include "brcmnand.h"
  31. struct bcm6368_nand_soc {
  32. struct brcmnand_soc soc;
  33. void __iomem *base;
  34. };
  35. #define BCM6368_NAND_INT 0x00
  36. #define BCM6368_NAND_STATUS_SHIFT 0
  37. #define BCM6368_NAND_STATUS_MASK (0xfff << BCM6368_NAND_STATUS_SHIFT)
  38. #define BCM6368_NAND_ENABLE_SHIFT 16
  39. #define BCM6368_NAND_ENABLE_MASK (0xffff << BCM6368_NAND_ENABLE_SHIFT)
  40. #define BCM6368_NAND_BASE_ADDR0 0x04
  41. #define BCM6368_NAND_BASE_ADDR1 0x0c
  42. enum {
  43. BCM6368_NP_READ = BIT(0),
  44. BCM6368_BLOCK_ERASE = BIT(1),
  45. BCM6368_COPY_BACK = BIT(2),
  46. BCM6368_PAGE_PGM = BIT(3),
  47. BCM6368_CTRL_READY = BIT(4),
  48. BCM6368_DEV_RBPIN = BIT(5),
  49. BCM6368_ECC_ERR_UNC = BIT(6),
  50. BCM6368_ECC_ERR_CORR = BIT(7),
  51. };
  52. static bool bcm6368_nand_intc_ack(struct brcmnand_soc *soc)
  53. {
  54. struct bcm6368_nand_soc *priv =
  55. container_of(soc, struct bcm6368_nand_soc, soc);
  56. void __iomem *mmio = priv->base + BCM6368_NAND_INT;
  57. u32 val = brcmnand_readl(mmio);
  58. if (val & (BCM6368_CTRL_READY << BCM6368_NAND_STATUS_SHIFT)) {
  59. /* Ack interrupt */
  60. val &= ~BCM6368_NAND_STATUS_MASK;
  61. val |= BCM6368_CTRL_READY << BCM6368_NAND_STATUS_SHIFT;
  62. brcmnand_writel(val, mmio);
  63. return true;
  64. }
  65. return false;
  66. }
  67. static void bcm6368_nand_intc_set(struct brcmnand_soc *soc, bool en)
  68. {
  69. struct bcm6368_nand_soc *priv =
  70. container_of(soc, struct bcm6368_nand_soc, soc);
  71. void __iomem *mmio = priv->base + BCM6368_NAND_INT;
  72. u32 val = brcmnand_readl(mmio);
  73. /* Don't ack any interrupts */
  74. val &= ~BCM6368_NAND_STATUS_MASK;
  75. if (en)
  76. val |= BCM6368_CTRL_READY << BCM6368_NAND_ENABLE_SHIFT;
  77. else
  78. val &= ~(BCM6368_CTRL_READY << BCM6368_NAND_ENABLE_SHIFT);
  79. brcmnand_writel(val, mmio);
  80. }
  81. static int bcm6368_nand_probe(struct platform_device *pdev)
  82. {
  83. struct device *dev = &pdev->dev;
  84. struct bcm6368_nand_soc *priv;
  85. struct brcmnand_soc *soc;
  86. struct resource *res;
  87. priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
  88. if (!priv)
  89. return -ENOMEM;
  90. soc = &priv->soc;
  91. res = platform_get_resource_byname(pdev,
  92. IORESOURCE_MEM, "nand-int-base");
  93. priv->base = devm_ioremap_resource(dev, res);
  94. if (IS_ERR(priv->base))
  95. return PTR_ERR(priv->base);
  96. soc->ctlrdy_ack = bcm6368_nand_intc_ack;
  97. soc->ctlrdy_set_enabled = bcm6368_nand_intc_set;
  98. /* Disable and ack all interrupts */
  99. brcmnand_writel(0, priv->base + BCM6368_NAND_INT);
  100. brcmnand_writel(BCM6368_NAND_STATUS_MASK,
  101. priv->base + BCM6368_NAND_INT);
  102. return brcmnand_probe(pdev, soc);
  103. }
  104. static const struct of_device_id bcm6368_nand_of_match[] = {
  105. { .compatible = "brcm,nand-bcm6368" },
  106. {},
  107. };
  108. MODULE_DEVICE_TABLE(of, bcm6368_nand_of_match);
  109. static struct platform_driver bcm6368_nand_driver = {
  110. .probe = bcm6368_nand_probe,
  111. .remove = brcmnand_remove,
  112. .driver = {
  113. .name = "bcm6368_nand",
  114. .pm = &brcmnand_pm_ops,
  115. .of_match_table = bcm6368_nand_of_match,
  116. }
  117. };
  118. module_platform_driver(bcm6368_nand_driver);
  119. MODULE_LICENSE("GPL");
  120. MODULE_AUTHOR("Simon Arlott");
  121. MODULE_DESCRIPTION("NAND driver for BCM6368");