1294660Smmel#-
2294660Smmel# Copyright 2016 Michal Meloun <mmel@FreeBSD.org>
3294660Smmel# All rights reserved.
4294660Smmel#
5294660Smmel# Redistribution and use in source and binary forms, with or without
6294660Smmel# modification, are permitted provided that the following conditions
7294660Smmel# are met:
8294660Smmel# 1. Redistributions of source code must retain the above copyright
9294660Smmel#    notice, this list of conditions and the following disclaimer.
10294660Smmel# 2. Redistributions in binary form must reproduce the above copyright
11294660Smmel#    notice, this list of conditions and the following disclaimer in the
12294660Smmel#    documentation and/or other materials provided with the distribution.
13294660Smmel#
14294660Smmel# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15294660Smmel# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16294660Smmel# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17294660Smmel# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18294660Smmel# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19294660Smmel# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20294660Smmel# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21294660Smmel# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22294660Smmel# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23294660Smmel# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24294660Smmel# SUCH DAMAGE.
25294660Smmel#
26294660Smmel# $FreeBSD: releng/11.0/sys/dev/extres/clk/clkdev_if.m 297350 2016-03-28 11:51:35Z jmcneill $
27294660Smmel#
28294660Smmel
29294660Smmel#include <machine/bus.h>
30294660Smmel
31294660SmmelINTERFACE clkdev;
32294660Smmel
33296905SmmelCODE {
34296905Smmel	#include <sys/systm.h>
35297350Sjmcneill	#include <sys/bus.h>
36297350Sjmcneill	static int
37297350Sjmcneill	clkdev_default_write_4(device_t dev, bus_addr_t addr, uint32_t val)
38297350Sjmcneill	{
39297350Sjmcneill		device_t pdev;
40297350Sjmcneill
41297350Sjmcneill		pdev = device_get_parent(dev);
42297350Sjmcneill		if (pdev == NULL)
43297350Sjmcneill			return (ENXIO);
44297350Sjmcneill
45297350Sjmcneill		return (CLKDEV_WRITE_4(pdev, addr, val));
46297350Sjmcneill	}
47297350Sjmcneill
48297350Sjmcneill	static int
49297350Sjmcneill	clkdev_default_read_4(device_t dev, bus_addr_t addr, uint32_t *val)
50297350Sjmcneill	{
51297350Sjmcneill		device_t pdev;
52297350Sjmcneill
53297350Sjmcneill		pdev = device_get_parent(dev);
54297350Sjmcneill		if (pdev == NULL)
55297350Sjmcneill			return (ENXIO);
56297350Sjmcneill
57297350Sjmcneill		return (CLKDEV_READ_4(pdev, addr, val));
58297350Sjmcneill	}
59297350Sjmcneill
60297350Sjmcneill	static int
61297350Sjmcneill	clkdev_default_modify_4(device_t dev, bus_addr_t addr,
62297350Sjmcneill	    uint32_t clear_mask, uint32_t set_mask)
63297350Sjmcneill	{
64297350Sjmcneill		device_t pdev;
65297350Sjmcneill
66297350Sjmcneill		pdev = device_get_parent(dev);
67297350Sjmcneill		if (pdev == NULL)
68297350Sjmcneill			return (ENXIO);
69297350Sjmcneill
70297350Sjmcneill		return (CLKDEV_MODIFY_4(pdev, addr, clear_mask, set_mask));
71297350Sjmcneill	}
72297350Sjmcneill
73296905Smmel	static void
74296905Smmel	clkdev_default_device_lock(device_t dev)
75296905Smmel	{
76297350Sjmcneill		device_t pdev;
77296905Smmel
78297350Sjmcneill		pdev = device_get_parent(dev);
79297350Sjmcneill		if (pdev == NULL)
80297350Sjmcneill			panic("clkdev_device_lock not implemented");
81297350Sjmcneill
82297350Sjmcneill		CLKDEV_DEVICE_LOCK(pdev);
83296905Smmel	}
84296905Smmel
85296905Smmel	static void
86296905Smmel	clkdev_default_device_unlock(device_t dev)
87296905Smmel	{
88297350Sjmcneill		device_t pdev;
89296905Smmel
90297350Sjmcneill		pdev = device_get_parent(dev);
91297350Sjmcneill		if (pdev == NULL)
92297350Sjmcneill			panic("clkdev_device_unlock not implemented");
93297350Sjmcneill
94297350Sjmcneill		CLKDEV_DEVICE_UNLOCK(pdev);
95296905Smmel	}
96296905Smmel}
97296905Smmel
98294660Smmel#
99294660Smmel# Write single register
100294660Smmel#
101294660SmmelMETHOD int write_4 {
102294660Smmel	device_t	dev;
103294660Smmel	bus_addr_t	addr;
104294660Smmel	uint32_t	val;
105297350Sjmcneill} DEFAULT clkdev_default_write_4;
106294660Smmel
107294660Smmel#
108294660Smmel# Read single register
109294660Smmel#
110294660SmmelMETHOD int read_4 {
111294660Smmel	device_t	dev;
112294660Smmel	bus_addr_t	addr;
113294660Smmel	uint32_t	*val;
114297350Sjmcneill} DEFAULT clkdev_default_read_4;
115294660Smmel
116294660Smmel#
117294660Smmel# Modify single register
118294660Smmel#
119294660SmmelMETHOD int modify_4 {
120294660Smmel	device_t	dev;
121294660Smmel	bus_addr_t	addr;
122294660Smmel	uint32_t	clear_mask;
123294660Smmel	uint32_t	set_mask;
124297350Sjmcneill} DEFAULT clkdev_default_modify_4;
125296905Smmel
126296905Smmel#
127296905Smmel# Get exclusive access to underlying device
128296905Smmel#
129296905SmmelMETHOD void device_lock {
130296905Smmel	device_t	dev;
131296905Smmel} DEFAULT clkdev_default_device_lock;
132296905Smmel
133296905Smmel#
134296905Smmel# Release exclusive access to underlying device
135296905Smmel#
136296905SmmelMETHOD void device_unlock {
137296905Smmel	device_t	dev;
138296905Smmel} DEFAULT clkdev_default_device_unlock;
139