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