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 a low level function to change 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 <linux/platform_data/dmtimer-omap.h>
  28. #include <clocksource/timer-ti-dm.h>
  29. #include "soc.h"
  30. #define OMAP1610_GPTIMER1_BASE 0xfffb1400
  31. #define OMAP1610_GPTIMER2_BASE 0xfffb1c00
  32. #define OMAP1610_GPTIMER3_BASE 0xfffb2400
  33. #define OMAP1610_GPTIMER4_BASE 0xfffb2c00
  34. #define OMAP1610_GPTIMER5_BASE 0xfffb3400
  35. #define OMAP1610_GPTIMER6_BASE 0xfffb3c00
  36. #define OMAP1610_GPTIMER7_BASE 0xfffb7400
  37. #define OMAP1610_GPTIMER8_BASE 0xfffbd400
  38. #define OMAP1_DM_TIMER_COUNT 8
  39. static int omap1_dm_timer_set_src(struct platform_device *pdev,
  40. int source)
  41. {
  42. int n = (pdev->id - 1) << 1;
  43. u32 l;
  44. l = omap_readl(MOD_CONF_CTRL_1) & ~(0x03 << n);
  45. l |= source << n;
  46. omap_writel(l, MOD_CONF_CTRL_1);
  47. return 0;
  48. }
  49. static int __init omap1_dm_timer_init(void)
  50. {
  51. int i;
  52. int ret;
  53. struct dmtimer_platform_data *pdata;
  54. struct platform_device *pdev;
  55. if (!cpu_is_omap16xx())
  56. return 0;
  57. for (i = 1; i <= OMAP1_DM_TIMER_COUNT; i++) {
  58. struct resource res[2];
  59. u32 base, irq;
  60. switch (i) {
  61. case 1:
  62. base = OMAP1610_GPTIMER1_BASE;
  63. irq = INT_1610_GPTIMER1;
  64. break;
  65. case 2:
  66. base = OMAP1610_GPTIMER2_BASE;
  67. irq = INT_1610_GPTIMER2;
  68. break;
  69. case 3:
  70. base = OMAP1610_GPTIMER3_BASE;
  71. irq = INT_1610_GPTIMER3;
  72. break;
  73. case 4:
  74. base = OMAP1610_GPTIMER4_BASE;
  75. irq = INT_1610_GPTIMER4;
  76. break;
  77. case 5:
  78. base = OMAP1610_GPTIMER5_BASE;
  79. irq = INT_1610_GPTIMER5;
  80. break;
  81. case 6:
  82. base = OMAP1610_GPTIMER6_BASE;
  83. irq = INT_1610_GPTIMER6;
  84. break;
  85. case 7:
  86. base = OMAP1610_GPTIMER7_BASE;
  87. irq = INT_1610_GPTIMER7;
  88. break;
  89. case 8:
  90. base = OMAP1610_GPTIMER8_BASE;
  91. irq = INT_1610_GPTIMER8;
  92. break;
  93. default:
  94. /*
  95. * not supposed to reach here.
  96. * this is to remove warning.
  97. */
  98. return -EINVAL;
  99. }
  100. pdev = platform_device_alloc("omap_timer", i);
  101. if (!pdev) {
  102. pr_err("%s: Failed to device alloc for dmtimer%d\n",
  103. __func__, i);
  104. return -ENOMEM;
  105. }
  106. memset(res, 0, 2 * sizeof(struct resource));
  107. res[0].start = base;
  108. res[0].end = base + 0x46;
  109. res[0].flags = IORESOURCE_MEM;
  110. res[1].start = irq;
  111. res[1].end = irq;
  112. res[1].flags = IORESOURCE_IRQ;
  113. ret = platform_device_add_resources(pdev, res,
  114. ARRAY_SIZE(res));
  115. if (ret) {
  116. dev_err(&pdev->dev, "%s: Failed to add resources.\n",
  117. __func__);
  118. goto err_free_pdev;
  119. }
  120. pdata = kzalloc(sizeof(*pdata), GFP_KERNEL);
  121. if (!pdata) {
  122. ret = -ENOMEM;
  123. goto err_free_pdata;
  124. }
  125. pdata->set_timer_src = omap1_dm_timer_set_src;
  126. pdata->timer_capability = OMAP_TIMER_ALWON |
  127. OMAP_TIMER_NEEDS_RESET | OMAP_TIMER_HAS_DSP_IRQ;
  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);