Advertisement
uaa

[wip:20200101] add F1C100s support for sunxi_timer.c

uaa
Jan 1st, 2020
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.65 KB | None | 0 0
  1. Index: sunxi_timer.c
  2. ===================================================================
  3. RCS file: /cvsroot/src/sys/arch/arm/sunxi/sunxi_timer.c,v
  4. retrieving revision 1.7
  5. diff -u -p -r1.7 sunxi_timer.c
  6. --- sunxi_timer.c 14 Jun 2019 21:48:43 -0000 1.7
  7. +++ sunxi_timer.c 1 Jan 2020 10:23:22 -0000
  8. @@ -91,9 +91,11 @@ __KERNEL_RCSID(0, "$NetBSD: sunxi_timer.
  9. #define LOSC_CTRL_OSC32K_AUTO_SWT_EN __BIT(14)
  10. #define LOSC_CTRL_OSC32K_SEL __BIT(0)
  11.  
  12. -static const char * const compatible[] = {
  13. - "allwinner,sun4i-a10-timer",
  14. - NULL
  15. +static const struct of_compat_data compat_data[] = {
  16. + { "allwinner,sun4i-a10-timer", 6 },
  17. + { "allwinner,sun8i-v3s-timer", 3 },
  18. + { "allwinner,suniv-f1c100s-timer", 3 },
  19. + { NULL }
  20. };
  21.  
  22. struct sunxi_timer_softc {
  23. @@ -103,6 +105,8 @@ struct sunxi_timer_softc {
  24. int sc_phandle;
  25. struct clk *sc_clk;
  26.  
  27. + int sc_ntimers;
  28. +
  29. struct timecounter sc_tc;
  30. struct timecounter sc_tc_losc;
  31. };
  32. @@ -178,7 +182,7 @@ sunxi_timer_match(device_t parent, cfdat
  33. {
  34. struct fdt_attach_args * const faa = aux;
  35.  
  36. - return of_match_compatible(faa->faa_phandle, compatible);
  37. + return of_match_compat_data(faa->faa_phandle, compat_data);
  38. }
  39.  
  40. static void
  41. @@ -211,6 +215,7 @@ sunxi_timer_attach(device_t parent, devi
  42. aprint_error(": couldn't map registers\n");
  43. return;
  44. }
  45. + sc->sc_ntimers = of_search_compatible(phandle, compat_data)->data;
  46.  
  47. aprint_naive("\n");
  48. aprint_normal(": Timer\n");
  49. @@ -230,9 +235,6 @@ sunxi_timer_attach(device_t parent, devi
  50. TIMER_WRITE(sc, TMR2_CTRL_REG,
  51. __SHIFTIN(TMR2_CTRL_CLK_SRC_OSC24M, TMR2_CTRL_CLK_SRC) |
  52. TMR2_CTRL_RELOAD | TMR2_CTRL_EN);
  53. - /* Enable Timer 4 (timecounter for LOSC) */
  54. - TIMER_WRITE(sc, TMR4_INTV_VALUE_REG, ~0u);
  55. - TIMER_WRITE(sc, TMR4_CTRL_REG, TMR4_CTRL_RELOAD | TMR4_CTRL_EN);
  56.  
  57. /* Timecounter setup */
  58. tc->tc_get_timecount = sunxi_timer_get_timecount;
  59. @@ -242,26 +244,31 @@ sunxi_timer_attach(device_t parent, devi
  60. tc->tc_quality = 200;
  61. tc->tc_priv = sc;
  62. tc_init(tc);
  63. - tc_losc->tc_get_timecount = sunxi_timer_get_timecount_losc;
  64. - tc_losc->tc_counter_mask = ~0u;
  65. - tc_losc->tc_frequency = 32768;
  66. - tc_losc->tc_name = "LOSC";
  67. - tc_losc->tc_quality = 150;
  68. - tc_losc->tc_priv = sc;
  69. - /*
  70. - * LOSC is optional to implement in hardware.
  71. - * Make sure it ticks before registering it.
  72. - */
  73. - reg = __SHIFTIN(LOSC_CTRL_KEY_FIELD_V, LOSC_CTRL_KEY_FIELD) |
  74. - LOSC_CTRL_OSC32K_AUTO_SWT_EN |
  75. - LOSC_CTRL_OSC32K_SEL;
  76. - TIMER_WRITE(sc, LOSC_CTRL_REG, reg);
  77. - ticks = sunxi_timer_get_timecount_losc(tc_losc);
  78. - delay(100);
  79. - if (ticks != sunxi_timer_get_timecount_losc(tc_losc))
  80. - tc_init(tc_losc);
  81. - else
  82. - TIMER_WRITE(sc, LOSC_CTRL_REG, reg & ~LOSC_CTRL_OSC32K_SEL);
  83. +
  84. + /* Timer 4 (timecounter for LOSC) is optional */
  85. + if (sc->sc_ntimers > 3) {
  86. + tc_losc->tc_get_timecount = sunxi_timer_get_timecount_losc;
  87. + tc_losc->tc_counter_mask = ~0u;
  88. + tc_losc->tc_frequency = 32768;
  89. + tc_losc->tc_name = "LOSC";
  90. + tc_losc->tc_quality = 150;
  91. + tc_losc->tc_priv = sc;
  92. +
  93. + /* Make sure it ticks before registering it. */
  94. + TIMER_WRITE(sc, TMR4_INTV_VALUE_REG, ~0u);
  95. + TIMER_WRITE(sc, TMR4_CTRL_REG, TMR4_CTRL_RELOAD | TMR4_CTRL_EN);
  96. + reg = __SHIFTIN(LOSC_CTRL_KEY_FIELD_V, LOSC_CTRL_KEY_FIELD) |
  97. + LOSC_CTRL_OSC32K_AUTO_SWT_EN |
  98. + LOSC_CTRL_OSC32K_SEL;
  99. + TIMER_WRITE(sc, LOSC_CTRL_REG, reg);
  100. + ticks = sunxi_timer_get_timecount_losc(tc_losc);
  101. + delay(100);
  102. + if (ticks != sunxi_timer_get_timecount_losc(tc_losc))
  103. + tc_init(tc_losc);
  104. + else
  105. + TIMER_WRITE(sc, LOSC_CTRL_REG,
  106. + reg & ~LOSC_CTRL_OSC32K_SEL);
  107. + }
  108.  
  109. /* Use this as the OS timer in UP configurations */
  110. if (!arm_has_mpext_p) {
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement