0060-clocksource-Add-StarFive-timer-driver.patch 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540
  1. From 3fbdabd59bac0978536fb11b1b9deb81559f1c54 Mon Sep 17 00:00:00 2001
  2. From: Xingyu Wu <[email protected]>
  3. Date: Mon, 20 Mar 2023 21:54:32 +0800
  4. Subject: [PATCH 060/122] clocksource: Add StarFive timer driver
  5. Add timer driver for the StarFive JH7110 SoC.
  6. Signed-off-by: Xingyu Wu <[email protected]>
  7. ---
  8. drivers/clocksource/Kconfig | 12 +
  9. drivers/clocksource/Makefile | 1 +
  10. drivers/clocksource/timer-starfive.c | 390 +++++++++++++++++++++++++++
  11. drivers/clocksource/timer-starfive.h | 96 +++++++
  12. 4 files changed, 499 insertions(+)
  13. create mode 100644 drivers/clocksource/timer-starfive.c
  14. create mode 100644 drivers/clocksource/timer-starfive.h
  15. --- a/drivers/clocksource/Kconfig
  16. +++ b/drivers/clocksource/Kconfig
  17. @@ -630,6 +630,18 @@ config RISCV_TIMER
  18. is accessed via both the SBI and the rdcycle instruction. This is
  19. required for all RISC-V systems.
  20. +config STARFIVE_TIMER
  21. + bool "Timer for the STARFIVE SoCs"
  22. + depends on ARCH_STARFIVE || COMPILE_TEST
  23. + select TIMER_OF
  24. + select CLKSRC_MMIO
  25. + default ARCH_STARFIVE
  26. + help
  27. + This enables the timer for StarFive SoCs. On RISC-V platform,
  28. + the system has started RISCV_TIMER. But you can also use this timer
  29. + to do a lot more on StarFive SoCs. This timer can provide high
  30. + precision and four channels to use in JH7110 SoC.
  31. +
  32. config CLINT_TIMER
  33. bool "CLINT Timer for the RISC-V platform" if COMPILE_TEST
  34. depends on GENERIC_SCHED_CLOCK && RISCV
  35. --- a/drivers/clocksource/Makefile
  36. +++ b/drivers/clocksource/Makefile
  37. @@ -80,6 +80,7 @@ obj-$(CONFIG_INGENIC_TIMER) += ingenic-
  38. obj-$(CONFIG_CLKSRC_ST_LPC) += clksrc_st_lpc.o
  39. obj-$(CONFIG_X86_NUMACHIP) += numachip.o
  40. obj-$(CONFIG_RISCV_TIMER) += timer-riscv.o
  41. +obj-$(CONFIG_STARFIVE_TIMER) += timer-starfive.o
  42. obj-$(CONFIG_CLINT_TIMER) += timer-clint.o
  43. obj-$(CONFIG_CSKY_MP_TIMER) += timer-mp-csky.o
  44. obj-$(CONFIG_GX6605S_TIMER) += timer-gx6605s.o
  45. --- /dev/null
  46. +++ b/drivers/clocksource/timer-starfive.c
  47. @@ -0,0 +1,390 @@
  48. +// SPDX-License-Identifier: GPL-2.0
  49. +/*
  50. + * Starfive Timer driver
  51. + *
  52. + * Copyright (C) 2022 StarFive Technology Co., Ltd.
  53. + *
  54. + * Author:
  55. + * Xingyu Wu <[email protected]>
  56. + * Samin Guo <[email protected]>
  57. + */
  58. +
  59. +#include <linux/clk.h>
  60. +#include <linux/clockchips.h>
  61. +#include <linux/clocksource.h>
  62. +#include <linux/err.h>
  63. +#include <linux/interrupt.h>
  64. +#include <linux/io.h>
  65. +#include <linux/iopoll.h>
  66. +#include <linux/irq.h>
  67. +#include <linux/kernel.h>
  68. +#include <linux/module.h>
  69. +#include <linux/of.h>
  70. +#include <linux/of_device.h>
  71. +#include <linux/platform_device.h>
  72. +#include <linux/reset.h>
  73. +#include <linux/sched_clock.h>
  74. +
  75. +#include "timer-starfive.h"
  76. +
  77. +static const struct starfive_timer_chan_base starfive_timer_jh7110_base = {
  78. + .ctrl = STARFIVE_TIMER_JH7110_CTL,
  79. + .load = STARFIVE_TIMER_JH7110_LOAD,
  80. + .enable = STARFIVE_TIMER_JH7110_ENABLE,
  81. + .reload = STARFIVE_TIMER_JH7110_RELOAD,
  82. + .value = STARFIVE_TIMER_JH7110_VALUE,
  83. + .intclr = STARFIVE_TIMER_JH7110_INT_CLR,
  84. + .intmask = STARFIVE_TIMER_JH7110_INT_MASK,
  85. + .channel_num = STARFIVE_TIMER_CH_4,
  86. + .channel_base = {STARFIVE_TIMER_CH_BASE(0), STARFIVE_TIMER_CH_BASE(1),
  87. + STARFIVE_TIMER_CH_BASE(2), STARFIVE_TIMER_CH_BASE(3)},
  88. +};
  89. +
  90. +static inline struct starfive_clkevt *to_starfive_clkevt(struct clock_event_device *evt)
  91. +{
  92. + return container_of(evt, struct starfive_clkevt, evt);
  93. +}
  94. +
  95. +/* 0:continuous-run mode, 1:single-run mode */
  96. +static inline void starfive_timer_set_mod(struct starfive_clkevt *clkevt, int mod)
  97. +{
  98. + writel(mod, clkevt->ctrl);
  99. +}
  100. +
  101. +/* Interrupt Mask Register, 0:Unmask, 1:Mask */
  102. +static inline void starfive_timer_int_enable(struct starfive_clkevt *clkevt)
  103. +{
  104. + writel(STARFIVE_TIMER_INTMASK_DIS, clkevt->intmask);
  105. +}
  106. +
  107. +static inline void starfive_timer_int_disable(struct starfive_clkevt *clkevt)
  108. +{
  109. + writel(STARFIVE_TIMER_INTMASK_ENA, clkevt->intmask);
  110. +}
  111. +
  112. +/*
  113. + * BIT(0): Read value represent channel intr status.
  114. + * Write 1 to this bit to clear interrupt. Write 0 has no effects.
  115. + * BIT(1): "1" means that it is clearing interrupt. BIT(0) can not be written.
  116. + */
  117. +static inline int starfive_timer_int_clear(struct starfive_clkevt *clkevt)
  118. +{
  119. + u32 value;
  120. + int ret;
  121. +
  122. + /* waiting interrupt can be to clearing */
  123. + ret = readl_poll_timeout_atomic(clkevt->intclr, value,
  124. + !(value & STARFIVE_TIMER_JH7110_INT_CLR_AVA_MASK),
  125. + STARFIVE_DELAY_US, STARFIVE_TIMEOUT_US);
  126. + if (!ret)
  127. + writel(0x1, clkevt->intclr);
  128. +
  129. + return ret;
  130. +}
  131. +
  132. +/*
  133. + * The initial value to be loaded into the
  134. + * counter and is also used as the reload value.
  135. + * val = clock rate --> 1s
  136. + */
  137. +static inline void starfive_timer_set_load(struct starfive_clkevt *clkevt, u32 val)
  138. +{
  139. + writel(val, clkevt->load);
  140. +}
  141. +
  142. +static inline u32 starfive_timer_get_val(struct starfive_clkevt *clkevt)
  143. +{
  144. + return readl(clkevt->value);
  145. +}
  146. +
  147. +/*
  148. + * Write RELOAD register to reload preset value to counter.
  149. + * (Write 0 and write 1 are both ok)
  150. + */
  151. +static inline void starfive_timer_set_reload(struct starfive_clkevt *clkevt)
  152. +{
  153. + writel(0, clkevt->reload);
  154. +}
  155. +
  156. +static inline void starfive_timer_enable(struct starfive_clkevt *clkevt)
  157. +{
  158. + writel(STARFIVE_TIMER_ENA, clkevt->enable);
  159. +}
  160. +
  161. +static inline void starfive_timer_disable(struct starfive_clkevt *clkevt)
  162. +{
  163. + writel(STARFIVE_TIMER_DIS, clkevt->enable);
  164. +}
  165. +
  166. +static int starfive_timer_int_init_enable(struct starfive_clkevt *clkevt)
  167. +{
  168. + int ret;
  169. +
  170. + starfive_timer_int_disable(clkevt);
  171. + ret = starfive_timer_int_clear(clkevt);
  172. + if (ret)
  173. + return ret;
  174. +
  175. + starfive_timer_int_enable(clkevt);
  176. + starfive_timer_enable(clkevt);
  177. +
  178. + return 0;
  179. +}
  180. +
  181. +static int starfive_timer_shutdown(struct clock_event_device *evt)
  182. +{
  183. + struct starfive_clkevt *clkevt = to_starfive_clkevt(evt);
  184. +
  185. + starfive_timer_disable(clkevt);
  186. + return starfive_timer_int_clear(clkevt);
  187. +}
  188. +
  189. +static void starfive_timer_suspend(struct clock_event_device *evt)
  190. +{
  191. + struct starfive_clkevt *clkevt = to_starfive_clkevt(evt);
  192. +
  193. + clkevt->reload_val = starfive_timer_get_val(clkevt);
  194. + starfive_timer_shutdown(evt);
  195. +}
  196. +
  197. +static void starfive_timer_resume(struct clock_event_device *evt)
  198. +{
  199. + struct starfive_clkevt *clkevt = to_starfive_clkevt(evt);
  200. +
  201. + starfive_timer_set_load(clkevt, clkevt->reload_val);
  202. + starfive_timer_set_reload(clkevt);
  203. + starfive_timer_int_enable(clkevt);
  204. + starfive_timer_enable(clkevt);
  205. +}
  206. +
  207. +static int starfive_timer_tick_resume(struct clock_event_device *evt)
  208. +{
  209. + starfive_timer_resume(evt);
  210. +
  211. + return 0;
  212. +}
  213. +
  214. +static int starfive_clocksource_init(struct starfive_clkevt *clkevt)
  215. +{
  216. + int ret;
  217. +
  218. + starfive_timer_set_mod(clkevt, STARFIVE_TIMER_MOD_CONTIN);
  219. + starfive_timer_set_load(clkevt, STARFIVE_TIMER_MAX_TICKS);
  220. + ret = starfive_timer_int_init_enable(clkevt);
  221. + if (ret)
  222. + return ret;
  223. +
  224. + return clocksource_mmio_init(clkevt->value, clkevt->name, clkevt->rate,
  225. + STARFIVE_CLOCK_SOURCE_RATING, STARFIVE_VALID_BITS,
  226. + clocksource_mmio_readl_down);
  227. +}
  228. +
  229. +/* IRQ handler for the timer */
  230. +static irqreturn_t starfive_timer_interrupt(int irq, void *priv)
  231. +{
  232. + struct clock_event_device *evt = (struct clock_event_device *)priv;
  233. + struct starfive_clkevt *clkevt = to_starfive_clkevt(evt);
  234. +
  235. + if (starfive_timer_int_clear(clkevt))
  236. + return IRQ_NONE;
  237. +
  238. + if (evt->event_handler)
  239. + evt->event_handler(evt);
  240. +
  241. + return IRQ_HANDLED;
  242. +}
  243. +
  244. +static int starfive_timer_set_periodic(struct clock_event_device *evt)
  245. +{
  246. + struct starfive_clkevt *clkevt = to_starfive_clkevt(evt);
  247. +
  248. + starfive_timer_disable(clkevt);
  249. + starfive_timer_set_mod(clkevt, STARFIVE_TIMER_MOD_CONTIN);
  250. + starfive_timer_set_load(clkevt, clkevt->periodic);
  251. +
  252. + return starfive_timer_int_init_enable(clkevt);
  253. +}
  254. +
  255. +static int starfive_timer_set_oneshot(struct clock_event_device *evt)
  256. +{
  257. + struct starfive_clkevt *clkevt = to_starfive_clkevt(evt);
  258. +
  259. + starfive_timer_disable(clkevt);
  260. + starfive_timer_set_mod(clkevt, STARFIVE_TIMER_MOD_SINGLE);
  261. + starfive_timer_set_load(clkevt, STARFIVE_TIMER_MAX_TICKS);
  262. +
  263. + return starfive_timer_int_init_enable(clkevt);
  264. +}
  265. +
  266. +static int starfive_timer_set_next_event(unsigned long next,
  267. + struct clock_event_device *evt)
  268. +{
  269. + struct starfive_clkevt *clkevt = to_starfive_clkevt(evt);
  270. +
  271. + starfive_timer_disable(clkevt);
  272. + starfive_timer_set_mod(clkevt, STARFIVE_TIMER_MOD_SINGLE);
  273. + starfive_timer_set_load(clkevt, next);
  274. + starfive_timer_enable(clkevt);
  275. +
  276. + return 0;
  277. +}
  278. +
  279. +static void starfive_set_clockevent(struct clock_event_device *evt)
  280. +{
  281. + evt->features = CLOCK_EVT_FEAT_PERIODIC |
  282. + CLOCK_EVT_FEAT_ONESHOT |
  283. + CLOCK_EVT_FEAT_DYNIRQ;
  284. + evt->set_state_shutdown = starfive_timer_shutdown;
  285. + evt->set_state_periodic = starfive_timer_set_periodic;
  286. + evt->set_state_oneshot = starfive_timer_set_oneshot;
  287. + evt->set_state_oneshot_stopped = starfive_timer_shutdown;
  288. + evt->tick_resume = starfive_timer_tick_resume;
  289. + evt->set_next_event = starfive_timer_set_next_event;
  290. + evt->suspend = starfive_timer_suspend;
  291. + evt->resume = starfive_timer_resume;
  292. + evt->rating = STARFIVE_CLOCKEVENT_RATING;
  293. +}
  294. +
  295. +static void starfive_clockevents_register(struct starfive_clkevt *clkevt)
  296. +{
  297. + clkevt->rate = clk_get_rate(clkevt->clk);
  298. + clkevt->periodic = DIV_ROUND_CLOSEST(clkevt->rate, HZ);
  299. +
  300. + starfive_set_clockevent(&clkevt->evt);
  301. + clkevt->evt.name = clkevt->name;
  302. + clkevt->evt.irq = clkevt->irq;
  303. + clkevt->evt.cpumask = cpu_possible_mask;
  304. +
  305. + clockevents_config_and_register(&clkevt->evt, clkevt->rate,
  306. + STARFIVE_TIMER_MIN_TICKS, STARFIVE_TIMER_MAX_TICKS);
  307. +}
  308. +
  309. +static void __init starfive_clkevt_base_init(const struct starfive_timer_chan_base *timer,
  310. + struct starfive_clkevt *clkevt,
  311. + void __iomem *base, int ch)
  312. +{
  313. + void __iomem *channel_base;
  314. +
  315. + channel_base = base + timer->channel_base[ch];
  316. + clkevt->base = channel_base;
  317. + clkevt->ctrl = channel_base + timer->ctrl;
  318. + clkevt->load = channel_base + timer->load;
  319. + clkevt->enable = channel_base + timer->enable;
  320. + clkevt->reload = channel_base + timer->reload;
  321. + clkevt->value = channel_base + timer->value;
  322. + clkevt->intclr = channel_base + timer->intclr;
  323. + clkevt->intmask = channel_base + timer->intmask;
  324. +}
  325. +
  326. +static int __init starfive_timer_probe(struct platform_device *pdev)
  327. +{
  328. + const struct starfive_timer_chan_base *timer_base = of_device_get_match_data(&pdev->dev);
  329. + char name[10];
  330. + struct starfive_timer_priv *priv;
  331. + struct starfive_clkevt *clkevt;
  332. + struct clk *pclk;
  333. + struct reset_control *rst;
  334. + int ch;
  335. + int ret;
  336. +
  337. + priv = devm_kzalloc(&pdev->dev, struct_size(priv, clkevt, timer_base->channel_num),
  338. + GFP_KERNEL);
  339. + if (!priv)
  340. + return -ENOMEM;
  341. +
  342. + priv->base = devm_platform_ioremap_resource(pdev, 0);
  343. + if (IS_ERR(priv->base))
  344. + return dev_err_probe(&pdev->dev, PTR_ERR(priv->base),
  345. + "failed to map registers\n");
  346. +
  347. + rst = devm_reset_control_get_exclusive(&pdev->dev, "apb");
  348. + if (IS_ERR(rst))
  349. + return dev_err_probe(&pdev->dev, PTR_ERR(rst), "failed to get apb reset\n");
  350. +
  351. + pclk = devm_clk_get_enabled(&pdev->dev, "apb");
  352. + if (IS_ERR(pclk))
  353. + return dev_err_probe(&pdev->dev, PTR_ERR(pclk),
  354. + "failed to get & enable apb clock\n");
  355. +
  356. + ret = reset_control_deassert(rst);
  357. + if (ret)
  358. + goto err;
  359. +
  360. + priv->dev = &pdev->dev;
  361. + platform_set_drvdata(pdev, priv);
  362. +
  363. + for (ch = 0; ch < timer_base->channel_num; ch++) {
  364. + clkevt = &priv->clkevt[ch];
  365. + snprintf(name, sizeof(name), "ch%d", ch);
  366. +
  367. + starfive_clkevt_base_init(timer_base, clkevt, priv->base, ch);
  368. + /* Ensure timers are disabled */
  369. + starfive_timer_disable(clkevt);
  370. +
  371. + rst = devm_reset_control_get_exclusive(&pdev->dev, name);
  372. + if (IS_ERR(rst)) {
  373. + ret = PTR_ERR(rst);
  374. + goto err;
  375. + }
  376. +
  377. + clkevt->clk = devm_clk_get_enabled(&pdev->dev, name);
  378. + if (IS_ERR(clkevt->clk)) {
  379. + ret = PTR_ERR(clkevt->clk);
  380. + goto err;
  381. + }
  382. +
  383. + ret = reset_control_deassert(rst);
  384. + if (ret)
  385. + goto ch_err;
  386. +
  387. + clkevt->irq = platform_get_irq(pdev, ch);
  388. + if (clkevt->irq < 0) {
  389. + ret = clkevt->irq;
  390. + goto ch_err;
  391. + }
  392. +
  393. + snprintf(clkevt->name, sizeof(clkevt->name), "%s.ch%d", pdev->name, ch);
  394. + starfive_clockevents_register(clkevt);
  395. +
  396. + ret = devm_request_irq(&pdev->dev, clkevt->irq, starfive_timer_interrupt,
  397. + IRQF_TIMER | IRQF_IRQPOLL,
  398. + clkevt->name, &clkevt->evt);
  399. + if (ret)
  400. + goto ch_err;
  401. +
  402. + ret = starfive_clocksource_init(clkevt);
  403. + if (ret)
  404. + goto ch_err;
  405. + }
  406. +
  407. + return 0;
  408. +
  409. +ch_err:
  410. + /* Only unregister the failed channel and the rest timer channels continue to work. */
  411. + clk_disable_unprepare(clkevt->clk);
  412. +err:
  413. + /* If no other channel successfully registers, pclk should be disabled. */
  414. + if (!ch)
  415. + clk_disable_unprepare(pclk);
  416. +
  417. + return ret;
  418. +}
  419. +
  420. +static const struct of_device_id starfive_timer_match[] = {
  421. + { .compatible = "starfive,jh7110-timer", .data = &starfive_timer_jh7110_base },
  422. + { /* sentinel */ }
  423. +};
  424. +MODULE_DEVICE_TABLE(of, starfive_timer_match);
  425. +
  426. +static struct platform_driver starfive_timer_driver = {
  427. + .probe = starfive_timer_probe,
  428. + .driver = {
  429. + .name = "starfive-timer",
  430. + .of_match_table = starfive_timer_match,
  431. + },
  432. +};
  433. +module_platform_driver(starfive_timer_driver);
  434. +
  435. +MODULE_AUTHOR("Xingyu Wu <[email protected]>");
  436. +MODULE_DESCRIPTION("StarFive timer driver");
  437. +MODULE_LICENSE("GPL");
  438. --- /dev/null
  439. +++ b/drivers/clocksource/timer-starfive.h
  440. @@ -0,0 +1,96 @@
  441. +/* SPDX-License-Identifier: GPL-2.0 */
  442. +/*
  443. + * Copyright (C) 2022 StarFive Technology Co., Ltd.
  444. + */
  445. +
  446. +#ifndef __STARFIVE_TIMER_H__
  447. +#define __STARFIVE_TIMER_H__
  448. +
  449. +/* Bias: Ch0-0x0, Ch1-0x40, Ch2-0x80, and so on. */
  450. +#define STARFIVE_TIMER_CH_LEN 0x40
  451. +#define STARFIVE_TIMER_CH_BASE(x) ((STARFIVE_TIMER_CH_##x) * STARFIVE_TIMER_CH_LEN)
  452. +
  453. +#define STARFIVE_CLOCK_SOURCE_RATING 200
  454. +#define STARFIVE_VALID_BITS 32
  455. +#define STARFIVE_DELAY_US 0
  456. +#define STARFIVE_TIMEOUT_US 10000
  457. +#define STARFIVE_CLOCKEVENT_RATING 300
  458. +#define STARFIVE_TIMER_MAX_TICKS 0xffffffff
  459. +#define STARFIVE_TIMER_MIN_TICKS 0xf
  460. +
  461. +#define STARFIVE_TIMER_JH7110_INT_STATUS 0x00 /* RO[0:4]: Interrupt Status for channel0~4 */
  462. +#define STARFIVE_TIMER_JH7110_CTL 0x04 /* RW[0]: 0-continuous run, 1-single run */
  463. +#define STARFIVE_TIMER_JH7110_LOAD 0x08 /* RW: load value to counter */
  464. +#define STARFIVE_TIMER_JH7110_ENABLE 0x10 /* RW[0]: timer enable register */
  465. +#define STARFIVE_TIMER_JH7110_RELOAD 0x14 /* RW: write 1 or 0 both reload counter */
  466. +#define STARFIVE_TIMER_JH7110_VALUE 0x18 /* RO: timer value register */
  467. +#define STARFIVE_TIMER_JH7110_INT_CLR 0x20 /* RW: timer interrupt clear register */
  468. +#define STARFIVE_TIMER_JH7110_INT_MASK 0x24 /* RW[0]: timer interrupt mask register */
  469. +#define STARFIVE_TIMER_JH7110_INT_CLR_AVA_MASK BIT(1)
  470. +
  471. +enum STARFIVE_TIMER_CH {
  472. + STARFIVE_TIMER_CH_0 = 0,
  473. + STARFIVE_TIMER_CH_1,
  474. + STARFIVE_TIMER_CH_2,
  475. + STARFIVE_TIMER_CH_3,
  476. + STARFIVE_TIMER_CH_4,
  477. + STARFIVE_TIMER_CH_5,
  478. + STARFIVE_TIMER_CH_6,
  479. + STARFIVE_TIMER_CH_7,
  480. + STARFIVE_TIMER_CH_MAX
  481. +};
  482. +
  483. +enum STARFIVE_TIMER_INTMASK {
  484. + STARFIVE_TIMER_INTMASK_DIS = 0,
  485. + STARFIVE_TIMER_INTMASK_ENA = 1
  486. +};
  487. +
  488. +enum STARFIVE_TIMER_MOD {
  489. + STARFIVE_TIMER_MOD_CONTIN = 0,
  490. + STARFIVE_TIMER_MOD_SINGLE = 1
  491. +};
  492. +
  493. +enum STARFIVE_TIMER_CTL_EN {
  494. + STARFIVE_TIMER_DIS = 0,
  495. + STARFIVE_TIMER_ENA = 1
  496. +};
  497. +
  498. +struct starfive_timer_chan_base {
  499. + /* Resgister */
  500. + unsigned int ctrl;
  501. + unsigned int load;
  502. + unsigned int enable;
  503. + unsigned int reload;
  504. + unsigned int value;
  505. + unsigned int intclr;
  506. + unsigned int intmask;
  507. +
  508. + unsigned int channel_num; /* timer channel numbers */
  509. + unsigned int channel_base[];
  510. +};
  511. +
  512. +struct starfive_clkevt {
  513. + struct clock_event_device evt;
  514. + struct clk *clk;
  515. + char name[20];
  516. + int irq;
  517. + u32 periodic;
  518. + u32 rate;
  519. + u32 reload_val;
  520. + void __iomem *base;
  521. + void __iomem *ctrl;
  522. + void __iomem *load;
  523. + void __iomem *enable;
  524. + void __iomem *reload;
  525. + void __iomem *value;
  526. + void __iomem *intclr;
  527. + void __iomem *intmask;
  528. +};
  529. +
  530. +struct starfive_timer_priv {
  531. + struct device *dev;
  532. + void __iomem *base;
  533. + struct starfive_clkevt clkevt[];
  534. +};
  535. +
  536. +#endif /* __STARFIVE_TIMER_H__ */