0077-clocksource-add-common-of_clksrc_init-function.patch 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. From 517d8e6ba345620c6704ec3db5b23c56fde06392 Mon Sep 17 00:00:00 2001
  2. From: John Crispin <[email protected]>
  3. Date: Thu, 20 Jun 2013 19:16:03 +0200
  4. Subject: [PATCH 77/79] clocksource: add common of_clksrc_init() function
  5. It is desirable to move all clocksource drivers to drivers/clocksource,
  6. yet each requires its own initialization function. We'd rather not
  7. pollute <linux/> with a header for each function. Instead, create a
  8. single of_clksrc_init() function which will determine which clocksource
  9. driver to initialize based on device tree.
  10. Based on a similar patch for drivers/irqchip by Thomas Petazzoni.
  11. Signed-off-by: Stephen Warren <[email protected]>
  12. ---
  13. drivers/clocksource/Kconfig | 3 +++
  14. drivers/clocksource/Makefile | 1 +
  15. drivers/clocksource/clksrc-of.c | 35 +++++++++++++++++++++++++++++++++++
  16. include/asm-generic/vmlinux.lds.h | 9 +++++++++
  17. include/linux/clocksource.h | 9 +++++++++
  18. 5 files changed, 57 insertions(+)
  19. create mode 100644 drivers/clocksource/clksrc-of.c
  20. diff --git a/drivers/clocksource/Kconfig b/drivers/clocksource/Kconfig
  21. index 7fdcbd3..a32b7a9 100644
  22. --- a/drivers/clocksource/Kconfig
  23. +++ b/drivers/clocksource/Kconfig
  24. @@ -1,3 +1,6 @@
  25. +config CLKSRC_OF
  26. + bool
  27. +
  28. config CLKSRC_I8253
  29. bool
  30. diff --git a/drivers/clocksource/Makefile b/drivers/clocksource/Makefile
  31. index f93453d..a33f792 100644
  32. --- a/drivers/clocksource/Makefile
  33. +++ b/drivers/clocksource/Makefile
  34. @@ -1,3 +1,4 @@
  35. +obj-$(CONFIG_CLKSRC_OF) += clksrc-of.o
  36. obj-$(CONFIG_ATMEL_TCB_CLKSRC) += tcb_clksrc.o
  37. obj-$(CONFIG_X86_CYCLONE_TIMER) += cyclone.o
  38. obj-$(CONFIG_X86_PM_TIMER) += acpi_pm.o
  39. diff --git a/drivers/clocksource/clksrc-of.c b/drivers/clocksource/clksrc-of.c
  40. new file mode 100644
  41. index 0000000..bdabdaa
  42. --- /dev/null
  43. +++ b/drivers/clocksource/clksrc-of.c
  44. @@ -0,0 +1,35 @@
  45. +/*
  46. + * Copyright (c) 2012, NVIDIA CORPORATION. All rights reserved.
  47. + *
  48. + * This program is free software; you can redistribute it and/or modify it
  49. + * under the terms and conditions of the GNU General Public License,
  50. + * version 2, as published by the Free Software Foundation.
  51. + *
  52. + * This program is distributed in the hope it will be useful, but WITHOUT
  53. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  54. + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  55. + * more details.
  56. + *
  57. + * You should have received a copy of the GNU General Public License
  58. + * along with this program. If not, see <http://www.gnu.org/licenses/>.
  59. + */
  60. +
  61. +#include <linux/init.h>
  62. +#include <linux/of.h>
  63. +
  64. +extern struct of_device_id __clksrc_of_table[];
  65. +
  66. +static const struct of_device_id __clksrc_of_table_sentinel
  67. + __used __section(__clksrc_of_table_end);
  68. +
  69. +void __init clocksource_of_init(void)
  70. +{
  71. + struct device_node *np;
  72. + const struct of_device_id *match;
  73. + void (*init_func)(void);
  74. +
  75. + for_each_matching_node_and_match(np, __clksrc_of_table, &match) {
  76. + init_func = match->data;
  77. + init_func();
  78. + }
  79. +}
  80. diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
  81. index d1ea7ce..1e744c5 100644
  82. --- a/include/asm-generic/vmlinux.lds.h
  83. +++ b/include/asm-generic/vmlinux.lds.h
  84. @@ -149,6 +149,14 @@
  85. #define TRACE_SYSCALLS()
  86. #endif
  87. +#ifdef CONFIG_CLKSRC_OF
  88. +#define CLKSRC_OF_TABLES() . = ALIGN(8); \
  89. + VMLINUX_SYMBOL(__clksrc_of_table) = .; \
  90. + *(__clksrc_of_table) \
  91. + *(__clksrc_of_table_end)
  92. +#else
  93. +#define CLKSRC_OF_TABLES()
  94. +#endif
  95. #define KERNEL_DTB() \
  96. STRUCT_ALIGN(); \
  97. @@ -493,6 +501,7 @@
  98. DEV_DISCARD(init.rodata) \
  99. CPU_DISCARD(init.rodata) \
  100. MEM_DISCARD(init.rodata) \
  101. + CLKSRC_OF_TABLES() \
  102. KERNEL_DTB()
  103. #define INIT_TEXT \
  104. diff --git a/include/linux/clocksource.h b/include/linux/clocksource.h
  105. index 4dceaf8..7944f14 100644
  106. --- a/include/linux/clocksource.h
  107. +++ b/include/linux/clocksource.h
  108. @@ -332,4 +332,13 @@ extern int clocksource_mmio_init(void __iomem *, const char *,
  109. extern int clocksource_i8253_init(void);
  110. +#ifdef CONFIG_CLKSRC_OF
  111. +extern void clocksource_of_init(void);
  112. +
  113. +#define CLOCKSOURCE_OF_DECLARE(name, compat, fn) \
  114. + static const struct of_device_id __clksrc_of_table_##name \
  115. + __used __section(__clksrc_of_table) \
  116. + = { .compatible = compat, .data = fn };
  117. +#endif
  118. +
  119. #endif /* _LINUX_CLOCKSOURCE_H */
  120. --
  121. 1.7.10.4