Nick Hawkins | 3cd8cfb | 2022-06-08 16:21:35 -0500 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
| 2 | /* |
| 3 | * GXP timer driver |
| 4 | * |
| 5 | * (C) Copyright 2022 Hewlett Packard Enterprise Development LP. |
| 6 | * Author: Nick Hawkins <nick.hawkins@hpe.com> |
| 7 | * Author: Jean-Marie Verdun <verdun@hpe.com> |
| 8 | */ |
| 9 | |
| 10 | #include <clk.h> |
| 11 | #include <dm.h> |
| 12 | #include <timer.h> |
| 13 | #include <asm/io.h> |
| 14 | |
| 15 | #define USTIMELO 0x18 |
| 16 | #define USTIMEHI 0x1C |
| 17 | |
| 18 | struct gxp_timer_priv { |
| 19 | void __iomem *base; |
| 20 | }; |
| 21 | |
| 22 | static u64 gxp_timer_get_count(struct udevice *dev) |
| 23 | { |
| 24 | struct gxp_timer_priv *priv = dev_get_priv(dev); |
| 25 | u64 val; |
| 26 | |
| 27 | val = readl(priv->base + USTIMEHI); |
| 28 | val = (val << 32) | readl(priv->base + USTIMELO); |
| 29 | |
| 30 | return val; |
| 31 | } |
| 32 | |
| 33 | static int gxp_timer_probe(struct udevice *dev) |
| 34 | { |
| 35 | struct timer_dev_priv *uc_priv = dev_get_uclass_priv(dev); |
| 36 | struct gxp_timer_priv *priv = dev_get_priv(dev); |
| 37 | |
| 38 | priv->base = dev_read_addr_ptr(dev); |
| 39 | if (!priv->base) |
| 40 | return -ENOENT; |
| 41 | |
| 42 | uc_priv->clock_rate = 1000000; |
| 43 | |
| 44 | return 0; |
| 45 | } |
| 46 | |
| 47 | static const struct timer_ops gxp_timer_ops = { |
| 48 | .get_count = gxp_timer_get_count, |
| 49 | }; |
| 50 | |
| 51 | static const struct udevice_id gxp_timer_ids[] = { |
| 52 | { .compatible = "hpe,gxp-timer" }, |
| 53 | {} |
| 54 | }; |
| 55 | |
| 56 | U_BOOT_DRIVER(gxp_timer) = { |
| 57 | .name = "gxp-timer", |
| 58 | .id = UCLASS_TIMER, |
| 59 | .of_match = gxp_timer_ids, |
| 60 | .priv_auto = sizeof(struct gxp_timer_priv), |
| 61 | .probe = gxp_timer_probe, |
| 62 | .ops = &gxp_timer_ops, |
| 63 | .flags = DM_FLAG_PRE_RELOC, |
| 64 | }; |