]>
Commit | Line | Data |
---|---|---|
fbb0efdd SG |
1 | // SPDX-License-Identifier: GPL-2.0 |
2 | /* | |
3 | * Sandbox driver for interrupts | |
4 | * | |
5 | * Copyright 2019 Google LLC | |
6 | */ | |
7 | ||
8 | #include <common.h> | |
9 | #include <dm.h> | |
10 | #include <irq.h> | |
02554355 SG |
11 | #include <asm/test.h> |
12 | ||
13 | /** | |
14 | * struct sandbox_irq_priv - private data for this driver | |
15 | * | |
16 | * @count: Counts the number calls to the read_and_clear() method | |
17 | * @pending: true if an interrupt is pending, else false | |
18 | */ | |
19 | struct sandbox_irq_priv { | |
20 | int count; | |
21 | bool pending; | |
22 | }; | |
fbb0efdd SG |
23 | |
24 | static int sandbox_set_polarity(struct udevice *dev, uint irq, bool active_low) | |
25 | { | |
26 | if (irq > 10) | |
27 | return -EINVAL; | |
28 | ||
29 | return 0; | |
30 | } | |
31 | ||
32 | static int sandbox_route_pmc_gpio_gpe(struct udevice *dev, uint pmc_gpe_num) | |
33 | { | |
34 | if (pmc_gpe_num > 10) | |
35 | return -ENOENT; | |
36 | ||
37 | return pmc_gpe_num + 1; | |
38 | } | |
39 | ||
40 | static int sandbox_snapshot_polarities(struct udevice *dev) | |
41 | { | |
42 | return 0; | |
43 | } | |
44 | ||
45 | static int sandbox_restore_polarities(struct udevice *dev) | |
46 | { | |
47 | return 0; | |
48 | } | |
49 | ||
02554355 SG |
50 | static int sandbox_irq_read_and_clear(struct irq *irq) |
51 | { | |
52 | struct sandbox_irq_priv *priv = dev_get_priv(irq->dev); | |
53 | ||
54 | if (irq->id != SANDBOX_IRQN_PEND) | |
55 | return -EINVAL; | |
56 | priv->count++; | |
57 | if (priv->pending) { | |
58 | priv->pending = false; | |
59 | return 1; | |
60 | } | |
61 | ||
62 | if (!(priv->count % 3)) | |
63 | priv->pending = true; | |
64 | ||
65 | return 0; | |
66 | } | |
67 | ||
68 | static int sandbox_irq_of_xlate(struct irq *irq, | |
69 | struct ofnode_phandle_args *args) | |
70 | { | |
71 | irq->id = args->args[0]; | |
72 | ||
73 | return 0; | |
74 | } | |
75 | ||
fbb0efdd SG |
76 | static const struct irq_ops sandbox_irq_ops = { |
77 | .route_pmc_gpio_gpe = sandbox_route_pmc_gpio_gpe, | |
78 | .set_polarity = sandbox_set_polarity, | |
79 | .snapshot_polarities = sandbox_snapshot_polarities, | |
80 | .restore_polarities = sandbox_restore_polarities, | |
02554355 SG |
81 | .read_and_clear = sandbox_irq_read_and_clear, |
82 | .of_xlate = sandbox_irq_of_xlate, | |
fbb0efdd SG |
83 | }; |
84 | ||
85 | static const struct udevice_id sandbox_irq_ids[] = { | |
ba876079 | 86 | { .compatible = "sandbox,irq", SANDBOX_IRQT_BASE }, |
fbb0efdd SG |
87 | { } |
88 | }; | |
89 | ||
90 | U_BOOT_DRIVER(sandbox_irq_drv) = { | |
91 | .name = "sandbox_irq", | |
92 | .id = UCLASS_IRQ, | |
93 | .of_match = sandbox_irq_ids, | |
94 | .ops = &sandbox_irq_ops, | |
02554355 | 95 | .priv_auto_alloc_size = sizeof(struct sandbox_irq_priv), |
fbb0efdd | 96 | }; |