Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/freebsd-src
Path: blob/main/sys/dev/clk/clkdev_if.m
39536 views
1
#-
2
# Copyright 2016 Michal Meloun <[email protected]>
3
# All rights reserved.
4
#
5
# Redistribution and use in source and binary forms, with or without
6
# modification, are permitted provided that the following conditions
7
# are met:
8
# 1. Redistributions of source code must retain the above copyright
9
# notice, this list of conditions and the following disclaimer.
10
# 2. Redistributions in binary form must reproduce the above copyright
11
# notice, this list of conditions and the following disclaimer in the
12
# documentation and/or other materials provided with the distribution.
13
#
14
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24
# SUCH DAMAGE.
25
#
26
#
27
28
#include <machine/bus.h>
29
30
INTERFACE clkdev;
31
32
CODE {
33
#include <sys/systm.h>
34
#include <sys/bus.h>
35
static int
36
clkdev_default_write_4(device_t dev, bus_addr_t addr, uint32_t val)
37
{
38
device_t pdev;
39
40
pdev = device_get_parent(dev);
41
if (pdev == NULL)
42
return (ENXIO);
43
44
return (CLKDEV_WRITE_4(pdev, addr, val));
45
}
46
47
static int
48
clkdev_default_read_4(device_t dev, bus_addr_t addr, uint32_t *val)
49
{
50
device_t pdev;
51
52
pdev = device_get_parent(dev);
53
if (pdev == NULL)
54
return (ENXIO);
55
56
return (CLKDEV_READ_4(pdev, addr, val));
57
}
58
59
static int
60
clkdev_default_modify_4(device_t dev, bus_addr_t addr,
61
uint32_t clear_mask, uint32_t set_mask)
62
{
63
device_t pdev;
64
65
pdev = device_get_parent(dev);
66
if (pdev == NULL)
67
return (ENXIO);
68
69
return (CLKDEV_MODIFY_4(pdev, addr, clear_mask, set_mask));
70
}
71
72
static void
73
clkdev_default_device_lock(device_t dev)
74
{
75
device_t pdev;
76
77
pdev = device_get_parent(dev);
78
if (pdev == NULL)
79
panic("clkdev_device_lock not implemented");
80
81
CLKDEV_DEVICE_LOCK(pdev);
82
}
83
84
static void
85
clkdev_default_device_unlock(device_t dev)
86
{
87
device_t pdev;
88
89
pdev = device_get_parent(dev);
90
if (pdev == NULL)
91
panic("clkdev_device_unlock not implemented");
92
93
CLKDEV_DEVICE_UNLOCK(pdev);
94
}
95
}
96
97
#
98
# Write single register
99
#
100
METHOD int write_4 {
101
device_t dev;
102
bus_addr_t addr;
103
uint32_t val;
104
} DEFAULT clkdev_default_write_4;
105
106
#
107
# Read single register
108
#
109
METHOD int read_4 {
110
device_t dev;
111
bus_addr_t addr;
112
uint32_t *val;
113
} DEFAULT clkdev_default_read_4;
114
115
#
116
# Modify single register
117
#
118
METHOD int modify_4 {
119
device_t dev;
120
bus_addr_t addr;
121
uint32_t clear_mask;
122
uint32_t set_mask;
123
} DEFAULT clkdev_default_modify_4;
124
125
#
126
# Get exclusive access to underlying device
127
#
128
METHOD void device_lock {
129
device_t dev;
130
} DEFAULT clkdev_default_device_lock;
131
132
#
133
# Release exclusive access to underlying device
134
#
135
METHOD void device_unlock {
136
device_t dev;
137
} DEFAULT clkdev_default_device_unlock;
138
139