xref: /freebsd/sys/dev/syscon/syscon_if.m (revision 78ae60b4)
1#-
2# Copyright (c) 2015 Michal Meloun
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
30INTERFACE syscon;
31
32HEADER {
33	struct syscon;
34	int syscon_get_handle_default(device_t dev, struct syscon **syscon);
35}
36
37CODE {
38	#include <sys/systm.h>
39	#include <sys/bus.h>
40
41	int
42	syscon_get_handle_default(device_t dev, struct syscon **syscon)
43	{
44		device_t parent;
45
46		parent = device_get_parent(dev);
47		if (parent == NULL)
48			return (ENODEV);
49		return (SYSCON_GET_HANDLE(parent, syscon));
50	}
51
52	static void
53	syscon_device_lock_default(device_t dev)
54	{
55
56		panic("syscon_device_lock is not implemented");
57	};
58
59	static void
60	syscon_device_unlock_default(device_t dev)
61	{
62
63		panic("syscon_device_unlock is not implemented");
64	};
65}
66
67METHOD int init {
68	struct syscon	*syscon;
69};
70
71METHOD int uninit {
72	struct syscon	*syscon;
73};
74
75/**
76 * Accessor functions for syscon register space
77 */
78METHOD uint32_t read_4 {
79	struct syscon	*syscon;
80	bus_size_t	offset;
81};
82
83METHOD int write_4 {
84	struct syscon	*syscon;
85	bus_size_t	offset;
86	uint32_t	val;
87};
88
89METHOD int modify_4 {
90	struct syscon	*syscon;
91	bus_size_t	offset;
92	uint32_t	clear_bits;
93	uint32_t	set_bits;
94};
95
96/**
97 * Unlocked verion of access function
98 */
99METHOD uint32_t unlocked_read_4 {
100	struct syscon	*syscon;
101	bus_size_t	offset;
102};
103
104METHOD int unlocked_write_4 {
105	struct syscon	*syscon;
106	bus_size_t	offset;
107	uint32_t	val;
108};
109
110METHOD int unlocked_modify_4 {
111	struct syscon	*syscon;
112	bus_size_t	offset;
113	uint32_t	clear_bits;
114	uint32_t	set_bits;
115};
116
117/**
118* Locking for exclusive access to underlying device
119*/
120METHOD void device_lock {
121	device_t	dev;
122} DEFAULT syscon_device_lock_default;
123
124METHOD void device_unlock {
125	device_t	dev;
126} DEFAULT syscon_device_unlock_default;
127
128/**
129 * Get syscon handle from parent driver
130 */
131METHOD int get_handle {
132	device_t	dev;
133	struct syscon	**syscon;
134} DEFAULT syscon_get_handle_default;
135