timer.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. /**
  2. * OMAP1 Dual-Mode Timers - platform device registration
  3. *
  4. * Contains first level initialization routines which internally
  5. * generates timer device information and registers with linux
  6. * device model. It also has low level function to chnage the timer
  7. * input clock source.
  8. *
  9. * Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com/
  10. * Tarun Kanti DebBarma <tarun.kanti@ti.com>
  11. * Thara Gopinath <thara@ti.com>
  12. *
  13. * This program is free software; you can redistribute it and/or modify
  14. * it under the terms of the GNU General Public License version 2 as
  15. * published by the Free Software Foundation.
  16. *
  17. * This program is distributed "as is" WITHOUT ANY WARRANTY of any
  18. * kind, whether express or implied; without even the implied warranty
  19. * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU General Public License for more details.
  21. */
  22. #include <linux/clk.h>
  23. #include <linux/io.h>
  24. #include <linux/err.h>
  25. #include <linux/slab.h>
  26. #include <linux/platform_device.h>
  27. #include <mach/irqs.h>
  28. #include <plat/dmtimer.h>
  29. #define OMAP1610_GPTIMER1_BASE 0xfffb1400
  30. #define OMAP1610_GPTIMER2_BASE 0xfffb1c00
  31. #define OMAP1610_GPTIMER3_BASE 0xfffb2400
  32. #define OMAP1610_GPTIMER4_BASE 0xfffb2c00
  33. #define OMAP1610_GPTIMER5_BASE 0xfffb3400
  34. #define OMAP1610_GPTIMER6_BASE 0xfffb3c00
  35. #define OMAP1610_GPTIMER7_BASE 0xfffb7400
  36. #define OMAP1610_GPTIMER8_BASE 0xfffbd400
  37. #define OMAP1_DM_TIMER_COUNT 8
  38. static int omap1_dm_timer_set_src(struct platform_device *pdev,
  39. int source)
  40. {
  41. int n = (pdev->id - 1) << 1;
  42. u32 l;
  43. l = __raw_readl(MOD_CONF_CTRL_1) & ~(0x03 << n);
  44. l |= source << n;
  45. __raw_writel(l, MOD_CONF_CTRL_1);
  46. return 0;
  47. }
  48. int __init omap1_dm_timer_init(void)
  49. {
  50. int i;
  51. int ret;
  52. struct dmtimer_platform_data *pdata;
  53. struct platform_device *pdev;
  54. if (!cpu_is_omap16xx())
  55. return 0;
  56. for (i = 1; i <= OMAP1_DM_TIMER_COUNT; i++) {
  57. struct resource res[2];
  58. u32 base, irq;
  59. switch (i) {
  60. case 1:
  61. base = OMAP1610_GPTIMER1_BASE;
  62. irq = INT_1610_GPTIMER1;
  63. break;
  64. case 2:
  65. base = OMAP1610_GPTIMER2_BASE;
  66. irq = INT_1610_GPTIMER2;
  67. break;
  68. case 3:
  69. base = OMAP1610_GPTIMER3_BASE;
  70. irq = INT_1610_GPTIMER3;
  71. break;
  72. case 4:
  73. base = OMAP1610_GPTIMER4_BASE;
  74. irq = INT_1610_GPTIMER4;
  75. break;
  76. case 5:
  77. base = OMAP1610_GPTIMER5_BASE;
  78. irq = INT_1610_GPTIMER5;
  79. break;
  80. case 6:
  81. base = OMAP1610_GPTIMER6_BASE;
  82. irq = INT_1610_GPTIMER6;
  83. break;
  84. case 7:
  85. base = OMAP1610_GPTIMER7_BASE;
  86. irq = INT_1610_GPTIMER7;
  87. break;
  88. case 8:
  89. base = OMAP1610_GPTIMER8_BASE;
  90. irq = INT_1610_GPTIMER8;
  91. break;
  92. default:
  93. /*
  94. * not supposed to reach here.
  95. * this is to remove warning.
  96. */
  97. return -EINVAL;
  98. }
  99. pdev = platform_device_alloc("omap_timer", i);
  100. if (!pdev) {
  101. pr_err("%s: Failed to device alloc for dmtimer%d\n",
  102. __func__, i);
  103. return -ENOMEM;
  104. }
  105. memset(res, 0, 2 * sizeof(struct resource));
  106. res[0].start = base;
  107. res[0].end = base + 0x46;
  108. res[0].flags = IORESOURCE_MEM;
  109. res[1].start = irq;
  110. res[1].end = irq;
  111. res[1].flags = IORESOURCE_IRQ;
  112. ret = platform_device_add_resources(pdev, res,
  113. ARRAY_SIZE(res));
  114. if (ret) {
  115. dev_err(&pdev->dev, "%s: Failed to add resources.\n",
  116. __func__);
  117. goto err_free_pdev;
  118. }
  119. pdata = kzalloc(sizeof(*pdata), GFP_KERNEL);
  120. if (!pdata) {
  121. dev_err(&pdev->dev, "%s: Failed to allocate pdata.\n",
  122. __func__);
  123. ret = -ENOMEM;
  124. goto err_free_pdata;
  125. }
  126. pdata->set_timer_src = omap1_dm_timer_set_src;
  127. pdata->needs_manual_reset = 1;
  128. ret = platform_device_add_data(pdev, pdata, sizeof(*pdata));
  129. if (ret) {
  130. dev_err(&pdev->dev, "%s: Failed to add platform data.\n",
  131. __func__);
  132. goto err_free_pdata;
  133. }
  134. ret = platform_device_add(pdev);
  135. if (ret) {
  136. dev_err(&pdev->dev, "%s: Failed to add platform device.\n",
  137. __func__);
  138. goto err_free_pdata;
  139. }
  140. dev_dbg(&pdev->dev, " Registered.\n");
  141. }
  142. return 0;
  143. err_free_pdata:
  144. kfree(pdata);
  145. err_free_pdev:
  146. platform_device_unregister(pdev);
  147. return ret;
  148. }
  149. arch_initcall(omap1_dm_timer_init);