1
0

dev-nfc.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. /*
  2. * Atheros AR934X SoCs built-in NAND flash controller support
  3. *
  4. * Copyright (C) 2011-2012 Gabor Juhos <juhosg@openwrt.org>
  5. *
  6. * This program is free software; you can redistribute it and/or modify it
  7. * under the terms of the GNU General Public License version 2 as published
  8. * by the Free Software Foundation.
  9. */
  10. #include <linux/kernel.h>
  11. #include <linux/delay.h>
  12. #include <linux/init.h>
  13. #include <linux/irq.h>
  14. #include <linux/dma-mapping.h>
  15. #include <linux/etherdevice.h>
  16. #include <linux/platform_device.h>
  17. #include <linux/platform/ar934x_nfc.h>
  18. #include <asm/mach-ath79/ath79.h>
  19. #include <asm/mach-ath79/ar71xx_regs.h>
  20. #include "dev-nfc.h"
  21. static struct resource ath79_nfc_resources[2];
  22. static u64 ar934x_nfc_dmamask = DMA_BIT_MASK(32);
  23. static struct ar934x_nfc_platform_data ath79_nfc_data;
  24. static struct platform_device ath79_nfc_device = {
  25. .name = AR934X_NFC_DRIVER_NAME,
  26. .id = -1,
  27. .resource = ath79_nfc_resources,
  28. .num_resources = ARRAY_SIZE(ath79_nfc_resources),
  29. .dev = {
  30. .dma_mask = &ar934x_nfc_dmamask,
  31. .coherent_dma_mask = DMA_BIT_MASK(32),
  32. .platform_data = &ath79_nfc_data,
  33. },
  34. };
  35. static void __init ath79_nfc_init_resource(struct resource res[2],
  36. unsigned long base,
  37. unsigned long size,
  38. int irq)
  39. {
  40. memset(res, 0, sizeof(struct resource) * 2);
  41. res[0].flags = IORESOURCE_MEM;
  42. res[0].start = base;
  43. res[0].end = base + size - 1;
  44. res[1].flags = IORESOURCE_IRQ;
  45. res[1].start = irq;
  46. res[1].end = irq;
  47. }
  48. static void ar934x_nfc_hw_reset(bool active)
  49. {
  50. if (active) {
  51. ath79_device_reset_set(AR934X_RESET_NANDF);
  52. udelay(100);
  53. ath79_device_reset_set(AR934X_RESET_ETH_SWITCH_ANALOG);
  54. udelay(250);
  55. } else {
  56. ath79_device_reset_clear(AR934X_RESET_ETH_SWITCH_ANALOG);
  57. udelay(250);
  58. ath79_device_reset_clear(AR934X_RESET_NANDF);
  59. udelay(100);
  60. }
  61. }
  62. static void ar934x_nfc_setup(void)
  63. {
  64. ath79_nfc_data.hw_reset = ar934x_nfc_hw_reset;
  65. ath79_nfc_init_resource(ath79_nfc_resources,
  66. AR934X_NFC_BASE, AR934X_NFC_SIZE,
  67. ATH79_MISC_IRQ(21));
  68. platform_device_register(&ath79_nfc_device);
  69. }
  70. static void qca955x_nfc_hw_reset(bool active)
  71. {
  72. if (active) {
  73. ath79_device_reset_set(QCA955X_RESET_NANDF);
  74. udelay(250);
  75. } else {
  76. ath79_device_reset_clear(QCA955X_RESET_NANDF);
  77. udelay(100);
  78. }
  79. }
  80. static void qca955x_nfc_setup(void)
  81. {
  82. ath79_nfc_data.hw_reset = qca955x_nfc_hw_reset;
  83. ath79_nfc_init_resource(ath79_nfc_resources,
  84. QCA955X_NFC_BASE, QCA955X_NFC_SIZE,
  85. ATH79_MISC_IRQ(21));
  86. platform_device_register(&ath79_nfc_device);
  87. }
  88. void __init ath79_nfc_set_select_chip(void (*f)(int chip_no))
  89. {
  90. ath79_nfc_data.select_chip = f;
  91. }
  92. void __init ath79_nfc_set_scan_fixup(int (*f)(struct mtd_info *mtd))
  93. {
  94. ath79_nfc_data.scan_fixup = f;
  95. }
  96. void __init ath79_nfc_set_swap_dma(bool enable)
  97. {
  98. ath79_nfc_data.swap_dma = enable;
  99. }
  100. void __init ath79_nfc_set_ecc_mode(enum ar934x_nfc_ecc_mode mode)
  101. {
  102. ath79_nfc_data.ecc_mode = mode;
  103. }
  104. void __init ath79_nfc_set_parts(struct mtd_partition *parts, int nr_parts)
  105. {
  106. ath79_nfc_data.parts = parts;
  107. ath79_nfc_data.nr_parts = nr_parts;
  108. }
  109. void __init ath79_register_nfc(void)
  110. {
  111. if (soc_is_ar934x())
  112. ar934x_nfc_setup();
  113. else if (soc_is_qca955x())
  114. qca955x_nfc_setup();
  115. else
  116. BUG();
  117. }