1 /* $NetBSD: clkctrl.c,v 1.7 2022/04/20 23:32:17 macallan Exp $ */ 2 3 /* 4 * Copyright (c) 2005 Michael Lorenz 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 1. Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * 2. Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * 15 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 16 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 17 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 18 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 19 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 20 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 21 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 24 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 25 * POSSIBILITY OF SUCH DAMAGE. 26 */ 27 28 #include <sys/cdefs.h> 29 __KERNEL_RCSID(0, "$NetBSD: clkctrl.c,v 1.7 2022/04/20 23:32:17 macallan Exp $"); 30 31 #include <sys/param.h> 32 #include <sys/systm.h> 33 #include <sys/device.h> 34 #include <sys/kernel.h> 35 36 #include <machine/autoconf.h> 37 #include <machine/cpu.h> 38 39 #include <sparc/sparc/vaddrs.h> 40 41 static int clkctrl_match(device_t, cfdata_t, void *); 42 static void clkctrl_attach(device_t, device_t, void *); 43 44 CFATTACH_DECL_NEW(clkctrl, 0, 45 clkctrl_match, clkctrl_attach, NULL, NULL); 46 47 static void tadpole_cpu_sleep(void); 48 volatile uint8_t *clkctrl_reg = NULL; 49 50 static int 51 clkctrl_match(device_t parent, cfdata_t cf, void *aux) 52 { 53 union obio_attach_args *uoba = aux; 54 55 if ((uoba->uoba_isobio4 != 0) || (clkctrl_reg != NULL)) 56 return (0); 57 58 return (strcmp("clk-ctrl", uoba->uoba_sbus.sa_name) == 0); 59 } 60 61 static void 62 clkctrl_attach(device_t parent, device_t self, void *aux) 63 { 64 union obio_attach_args *uoba = aux; 65 struct sbus_attach_args *sa = &uoba->uoba_sbus; 66 bus_space_handle_t bh; 67 struct cpu_info *cur; 68 69 if (clkctrl_reg != NULL) { 70 aprint_error("unable to attach more than once\n"); 71 return; 72 } 73 if (sbus_bus_map(sa->sa_bustag, 74 sa->sa_slot, sa->sa_offset, 75 1, 76 BUS_SPACE_MAP_LINEAR, &bh) != 0) { 77 aprint_error("unable to map register\n"); 78 return; 79 } 80 81 clkctrl_reg = (volatile uint8_t *)bus_space_vaddr(sa->sa_bustag, bh); 82 83 #ifdef DEBUG 84 printf(" reg: %x", (uint32_t)clkctrl_reg); 85 #endif 86 cur = curcpu(); 87 cur->idlespin = tadpole_cpu_sleep; 88 89 printf("\n"); 90 } 91 92 /* ARGSUSED */ 93 static void 94 tadpole_cpu_sleep(void) 95 { 96 97 if (clkctrl_reg == 0) 98 return; 99 *clkctrl_reg = 0; 100 } 101