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