sam9_smc.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. /*
  2. * linux/arch/arm/mach-at91/sam9_smc.c
  3. *
  4. * Copyright (C) 2008 Andrew Victor
  5. * Copyright (C) 2011 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License version 2 as
  9. * published by the Free Software Foundation.
  10. */
  11. #include <linux/module.h>
  12. #include <linux/io.h>
  13. #include <linux/of.h>
  14. #include <linux/of_address.h>
  15. #include <mach/at91sam9_smc.h>
  16. #include "sam9_smc.h"
  17. #define AT91_SMC_CS(id, n) (smc_base_addr[id] + ((n) * 0x10))
  18. static void __iomem *smc_base_addr[2];
  19. static void sam9_smc_cs_write_mode(void __iomem *base,
  20. struct sam9_smc_config *config)
  21. {
  22. __raw_writel(config->mode
  23. | AT91_SMC_TDF_(config->tdf_cycles),
  24. base + AT91_SMC_MODE);
  25. }
  26. void sam9_smc_write_mode(int id, int cs,
  27. struct sam9_smc_config *config)
  28. {
  29. sam9_smc_cs_write_mode(AT91_SMC_CS(id, cs), config);
  30. }
  31. static void sam9_smc_cs_configure(void __iomem *base,
  32. struct sam9_smc_config *config)
  33. {
  34. /* Setup register */
  35. __raw_writel(AT91_SMC_NWESETUP_(config->nwe_setup)
  36. | AT91_SMC_NCS_WRSETUP_(config->ncs_write_setup)
  37. | AT91_SMC_NRDSETUP_(config->nrd_setup)
  38. | AT91_SMC_NCS_RDSETUP_(config->ncs_read_setup),
  39. base + AT91_SMC_SETUP);
  40. /* Pulse register */
  41. __raw_writel(AT91_SMC_NWEPULSE_(config->nwe_pulse)
  42. | AT91_SMC_NCS_WRPULSE_(config->ncs_write_pulse)
  43. | AT91_SMC_NRDPULSE_(config->nrd_pulse)
  44. | AT91_SMC_NCS_RDPULSE_(config->ncs_read_pulse),
  45. base + AT91_SMC_PULSE);
  46. /* Cycle register */
  47. __raw_writel(AT91_SMC_NWECYCLE_(config->write_cycle)
  48. | AT91_SMC_NRDCYCLE_(config->read_cycle),
  49. base + AT91_SMC_CYCLE);
  50. /* Mode register */
  51. sam9_smc_cs_write_mode(base, config);
  52. }
  53. void sam9_smc_configure(int id, int cs,
  54. struct sam9_smc_config *config)
  55. {
  56. sam9_smc_cs_configure(AT91_SMC_CS(id, cs), config);
  57. }
  58. static void sam9_smc_cs_read_mode(void __iomem *base,
  59. struct sam9_smc_config *config)
  60. {
  61. u32 val = __raw_readl(base + AT91_SMC_MODE);
  62. config->mode = (val & ~AT91_SMC_NWECYCLE);
  63. config->tdf_cycles = (val & AT91_SMC_NWECYCLE) >> 16 ;
  64. }
  65. void sam9_smc_read_mode(int id, int cs,
  66. struct sam9_smc_config *config)
  67. {
  68. sam9_smc_cs_read_mode(AT91_SMC_CS(id, cs), config);
  69. }
  70. static void sam9_smc_cs_read(void __iomem *base,
  71. struct sam9_smc_config *config)
  72. {
  73. u32 val;
  74. /* Setup register */
  75. val = __raw_readl(base + AT91_SMC_SETUP);
  76. config->nwe_setup = val & AT91_SMC_NWESETUP;
  77. config->ncs_write_setup = (val & AT91_SMC_NCS_WRSETUP) >> 8;
  78. config->nrd_setup = (val & AT91_SMC_NRDSETUP) >> 16;
  79. config->ncs_read_setup = (val & AT91_SMC_NCS_RDSETUP) >> 24;
  80. /* Pulse register */
  81. val = __raw_readl(base + AT91_SMC_PULSE);
  82. config->nwe_pulse = val & AT91_SMC_NWEPULSE;
  83. config->ncs_write_pulse = (val & AT91_SMC_NCS_WRPULSE) >> 8;
  84. config->nrd_pulse = (val & AT91_SMC_NRDPULSE) >> 16;
  85. config->ncs_read_pulse = (val & AT91_SMC_NCS_RDPULSE) >> 24;
  86. /* Cycle register */
  87. val = __raw_readl(base + AT91_SMC_CYCLE);
  88. config->write_cycle = val & AT91_SMC_NWECYCLE;
  89. config->read_cycle = (val & AT91_SMC_NRDCYCLE) >> 16;
  90. /* Mode register */
  91. sam9_smc_cs_read_mode(base, config);
  92. }
  93. void sam9_smc_read(int id, int cs, struct sam9_smc_config *config)
  94. {
  95. sam9_smc_cs_read(AT91_SMC_CS(id, cs), config);
  96. }
  97. void __init at91sam9_ioremap_smc(int id, u32 addr)
  98. {
  99. if (id > 1) {
  100. pr_warn("%s: id > 2\n", __func__);
  101. return;
  102. }
  103. smc_base_addr[id] = ioremap(addr, 512);
  104. if (!smc_base_addr[id])
  105. pr_warn("Impossible to ioremap smc.%d 0x%x\n", id, addr);
  106. }