alarmDataOperation.c 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. /*
  2. * GPMC support functions
  3. *
  4. * Copyright (C) 2005-2006 Nokia Corporation
  5. *
  6. * Author: Juha Yrjola
  7. *
  8. * Copyright (C) 2009 Texas Instruments
  9. * Added OMAP4 support - Santosh Shilimkar <santosh.shilimkar@ti.com>
  10. *
  11. * This program is free software; you can redistribute it and/or modify
  12. * it under the terms of the GNU General Public License version 2 as
  13. * published by the Free Software Foundation.
  14. */
  15. #undef DEBUG
  16. #include <linux/irq.h>
  17. #include <linux/kernel.h>
  18. #include <linux/init.h>
  19. #include <linux/err.h>
  20. #include <linux/clk.h>
  21. #include <linux/ioport.h>
  22. #include <linux/spinlock.h>
  23. #include <linux/io.h>
  24. #include <linux/module.h>
  25. #include <linux/interrupt.h>
  26. #include <linux/platform_device.h>
  27. #include <linux/platform_data/mtd-nand-omap2.h>
  28. #include <asm/mach-types.h>
  29. #include "soc.h"
  30. #include "common.h"
  31. #include "omap_device.h"
  32. #include "gpmc.h"
  33. #define DEVICE_NAME "omap-gpmc"
  34. /* GPMC register offsets */
  35. #define GPMC_REVISION 0x00
  36. #define GPMC_SYSCONFIG 0x10
  37. #define GPMC_SYSSTATUS 0x14
  38. #define GPMC_IRQSTATUS 0x18
  39. #define GPMC_IRQENABLE 0x1c
  40. #define GPMC_TIMEOUT_CONTROL 0x40
  41. #define GPMC_ERR_ADDRESS 0x44
  42. #define GPMC_ERR_TYPE 0x48
  43. #define GPMC_CONFIG 0x50
  44. #define GPMC_STATUS 0x54
  45. #define GPMC_PREFETCH_CONFIG1 0x1e0
  46. #define GPMC_PREFETCH_CONFIG2 0x1e4
  47. #define GPMC_PREFETCH_CONTROL 0x1ec
  48. #define GPMC_PREFETCH_STATUS 0x1f0
  49. #define GPMC_ECC_CONFIG 0x1f4
  50. #define GPMC_ECC_CONTROL 0x1f8
  51. #define GPMC_ECC_SIZE_CONFIG 0x1fc
  52. #define GPMC_ECC1_RESULT 0x200
  53. #define GPMC_ECC_BCH_RESULT_0 0x240 /* not available on OMAP2 */
  54. #define GPMC_ECC_BCH_RESULT_1 0x244 /* not available on OMAP2 */
  55. #define GPMC_ECC_BCH_RESULT_2 0x248 /* not available on OMAP2 */
  56. #define GPMC_ECC_BCH_RESULT_3 0x24c /* not available on OMAP2 */
  57. /* GPMC ECC control settings */
  58. #define GPMC_ECC_CTRL_ECCCLEAR 0x100
  59. #define GPMC_ECC_CTRL_ECCDISABLE 0x000
  60. #define GPMC_ECC_CTRL_ECCREG1 0x001
  61. #define GPMC_ECC_CTRL_ECCREG2 0x002
  62. #define GPMC_ECC_CTRL_ECCREG3 0x003
  63. #define GPMC_ECC_CTRL_ECCREG4 0x004
  64. #define GPMC_ECC_CTRL_ECCREG5 0x005
  65. #define GPMC_ECC_CTRL_ECCREG6 0x006
  66. #define GPMC_ECC_CTRL_ECCREG7 0x007
  67. #define GPMC_ECC_CTRL_ECCREG8 0x008
  68. #define GPMC_ECC_CTRL_ECCREG9 0x009
  69. #define GPMC_CONFIG2_CSEXTRADELAY BIT(7)
  70. #define GPMC_CONFIG3_ADVEXTRADELAY BIT(7)
  71. #define GPMC_CONFIG4_OEEXTRADELAY BIT(7)
  72. #define GPMC_CONFIG4_WEEXTRADELAY BIT(23)
  73. #define GPMC_CONFIG6_CYCLE2CYCLEDIFFCSEN BIT(6)
  74. #define GPMC_CONFIG6_CYCLE2CYCLESAMECSEN BIT(7)
  75. #define GPMC_CS0_OFFSET 0x60
  76. #define GPMC_CS_SIZE 0x30
  77. #define GPMC_BCH_SIZE 0x10
  78. #define GPMC_MEM_START 0x00000000
  79. #define GPMC_MEM_END 0x3FFFFFFF
  80. #define BOOT_ROM_SPACE 0x100000 /* 1MB */
  81. #define GPMC_CHUNK_SHIFT 24 /* 16 MB */
  82. #define GPMC_SECTION_SHIFT 28 /* 128 MB */
  83. #define CS_NUM_SHIFT 24
  84. #define ENABLE_PREFETCH (0x1 << 7)
  85. #define DMA_MPU_MODE 2
  86. #define GPMC_REVISION_MAJOR(l) ((l >> 4) & 0xf)
  87. #define GPMC_REVISION_MINOR(l) (l & 0xf)
  88. #define GPMC_HAS_WR_ACCESS 0x1
  89. #define GPMC_HAS_WR_DATA_MUX_BUS 0x2
  90. /* XXX: Only NAND irq has been considered,currently these are the only ones used
  91. */
  92. #define GPMC_NR_IRQ 2
  93. struct gpmc_client_irq {
  94. unsigned irq;
  95. u32 bitmask;
  96. };
  97. /* Structure to save gpmc cs context */
  98. struct gpmc_cs_config {
  99. u32 config1;
  100. u32 config2;
  101. u32 config3;
  102. u32 config4;
  103. u32 config5;
  104. u32 config6;
  105. u32 config7;
  106. int is_valid;
  107. };
  108. /*
  109. * Structure to save/restore gpmc context
  110. * to support core off on OMAP3
  111. */
  112. struct omap3_gpmc_regs {
  113. u32 sysconfig;
  114. u32 irqenable;
  115. u32 timeout_ctrl;
  116. u32 config;
  117. u32 prefetch_config1;
  118. u32 prefetch_config2;
  119. u32 prefetch_control;
  120. struct gpmc_cs_config cs_context[GPMC_CS_NUM];
  121. };
  122. static struct gpmc_client_irq gpmc_client_irq[GPMC_NR_IRQ];
  123. static struct irq_chip gpmc_irq_chip;
  124. static unsigned gpmc_irq_start;
  125. static struct resource gpmc_mem_root;
  126. static struct resource gpmc_cs_mem[GPMC_CS_NUM];
  127. static DEFINE_SPINLOCK(gpmc_mem_lock);
  128. static unsigned int gpmc_cs_map; /* flag for cs which are initialized */
  129. static struct device *gpmc_dev;
  130. static int gpmc_irq;
  131. static resource_size_t phys_base, mem_size;
  132. static unsigned gpmc_capability;
  133. static void __iomem *gpmc_base;
  134. static struct clk *gpmc_l3_clk;
  135. static irqreturn_t gpmc_handle_irq(int irq, void *dev);
  136. static void gpmc_write_reg(int idx, u32 val)
  137. {
  138. __raw_writel(val, gpmc_base + idx);
  139. }
  140. static u32 gpmc_read_reg(int idx)
  141. {
  142. return __raw_readl(gpmc_base + idx);
  143. }
  144. void gpmc_cs_write_reg(int cs, int idx, u32 val)
  145. {
  146. void __iomem *reg_addr;
  147. reg_addr = gpmc_base + GPMC_CS0_OFFSET + (cs * GPMC_CS_SIZE) + idx;
  148. __raw_writel(val, reg_addr);
  149. }
  150. u32 gpmc_cs_read_reg(int cs, int idx)
  151. {
  152. void __iomem *reg_addr;
  153. reg_addr = gpmc_base + GPMC_CS0_OFFSET + (cs * GPMC_CS_SIZE) + idx;
  154. return __raw_readl(reg_addr);
  155. }
  156. /* TODO: Add support for gpmc_fck to clock framework and use it */
  157. unsigned long gpmc_get_fclk_period(void)
  158. {
  159. unsigned long rate = clk_get_rate(gpmc_l3_clk);
  160. if (rate == 0) {
  161. printk(KERN_WARNING "gpmc_l3_clk not enabled\n");
  162. return 0;
  163. }
  164. rate /= 1000;
  165. rate = 1000000000 / rate; /* In picoseconds */
  166. return rate;
  167. }
  168. unsigned int gpmc_ns_to_ticks(unsigned int time_ns)
  169. {
  170. unsigned long tick_ps;
  171. /* Calculate in picosecs to yield more exact results */
  172. tick_ps = gpmc_get_fclk_period();
  173. return (time_ns * 1000 + tick_ps - 1) / tick_ps;
  174. }
  175. unsigned int gpmc_ps_to_ticks(unsigned int time_ps)
  176. {
  177. unsigned long tick_ps;
  178. /* Calculate in picosecs to yield more exact results */
  179. tick_ps = gpmc_get_fclk_period();