#-1# Copyright 2016 Michal Meloun <[email protected]>2# All rights reserved.3#4# Redistribution and use in source and binary forms, with or without5# modification, are permitted provided that the following conditions6# are met:7# 1. Redistributions of source code must retain the above copyright8# notice, this list of conditions and the following disclaimer.9# 2. Redistributions in binary form must reproduce the above copyright10# notice, this list of conditions and the following disclaimer in the11# documentation and/or other materials provided with the distribution.12#13# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND14# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE15# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE16# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE17# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL18# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS19# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)20# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT21# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY22# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF23# SUCH DAMAGE.24#25#2627#include <machine/bus.h>2829INTERFACE clkdev;3031CODE {32#include <sys/systm.h>33#include <sys/bus.h>34static int35clkdev_default_write_4(device_t dev, bus_addr_t addr, uint32_t val)36{37device_t pdev;3839pdev = device_get_parent(dev);40if (pdev == NULL)41return (ENXIO);4243return (CLKDEV_WRITE_4(pdev, addr, val));44}4546static int47clkdev_default_read_4(device_t dev, bus_addr_t addr, uint32_t *val)48{49device_t pdev;5051pdev = device_get_parent(dev);52if (pdev == NULL)53return (ENXIO);5455return (CLKDEV_READ_4(pdev, addr, val));56}5758static int59clkdev_default_modify_4(device_t dev, bus_addr_t addr,60uint32_t clear_mask, uint32_t set_mask)61{62device_t pdev;6364pdev = device_get_parent(dev);65if (pdev == NULL)66return (ENXIO);6768return (CLKDEV_MODIFY_4(pdev, addr, clear_mask, set_mask));69}7071static void72clkdev_default_device_lock(device_t dev)73{74device_t pdev;7576pdev = device_get_parent(dev);77if (pdev == NULL)78panic("clkdev_device_lock not implemented");7980CLKDEV_DEVICE_LOCK(pdev);81}8283static void84clkdev_default_device_unlock(device_t dev)85{86device_t pdev;8788pdev = device_get_parent(dev);89if (pdev == NULL)90panic("clkdev_device_unlock not implemented");9192CLKDEV_DEVICE_UNLOCK(pdev);93}94}9596#97# Write single register98#99METHOD int write_4 {100device_t dev;101bus_addr_t addr;102uint32_t val;103} DEFAULT clkdev_default_write_4;104105#106# Read single register107#108METHOD int read_4 {109device_t dev;110bus_addr_t addr;111uint32_t *val;112} DEFAULT clkdev_default_read_4;113114#115# Modify single register116#117METHOD int modify_4 {118device_t dev;119bus_addr_t addr;120uint32_t clear_mask;121uint32_t set_mask;122} DEFAULT clkdev_default_modify_4;123124#125# Get exclusive access to underlying device126#127METHOD void device_lock {128device_t dev;129} DEFAULT clkdev_default_device_lock;130131#132# Release exclusive access to underlying device133#134METHOD void device_unlock {135device_t dev;136} DEFAULT clkdev_default_device_unlock;137138139