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