1/*- 2 * Copyright (c) 2019 Justin Hibbits 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 7 * 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 15 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 16 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 17 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 18 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 19 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 20 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 21 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 */ 25 26#include <sys/param.h> 27#include <sys/systm.h> 28#include <sys/kernel.h> 29#include <sys/bus.h> 30#include <sys/malloc.h> 31#include <sys/smp.h> 32 33#include <machine/intr_machdep.h> 34#include <machine/platform.h> 35#include <machine/platformvar.h> 36 37#include <dev/ofw/openfirm.h> 38#include <dev/ofw/ofw_bus.h> 39 40#include <powerpc/mpc85xx/mpc85xx.h> 41 42#include "platform_if.h" 43 44static void aeon_pbutton_intr(void *_unused); 45static void aeon_setup_intr(void *unused); 46 47static int aeon_probe(platform_t); 48static int aeon_attach(platform_t); 49 50static platform_method_t aeon_methods[] = { 51 PLATFORMMETHOD(platform_probe, aeon_probe), 52 PLATFORMMETHOD(platform_attach, aeon_attach), 53 PLATFORMMETHOD_END 54}; 55 56DEFINE_CLASS_1(aeon, aeon_platform, aeon_methods, 0, mpc85xx_platform); 57 58PLATFORM_DEF(aeon_platform); 59 60static bool is_aeon; 61 62static int 63aeon_probe(platform_t plat) 64{ 65 phandle_t rootnode; 66 char model[32]; 67 68 rootnode = OF_finddevice("/"); 69 70 if (OF_getprop(rootnode, "model", model, sizeof(model)) > 0) { 71 if (strncmp(model, "varisys,", strlen("varisys,")) == 0) 72 return (BUS_PROBE_SPECIFIC); 73 } 74 75 return (ENXIO); 76} 77 78static int 79aeon_attach(platform_t plat) 80{ 81 int error; 82 83 error = mpc85xx_attach(plat); 84 if (error) 85 return (error); 86 87 is_aeon = true; 88 89 return (0); 90} 91 92/* Notify devd(8) that the power button was pressed (IRQ#4 on A-Eon machines). */ 93static void 94aeon_pbutton_intr(void *_unused) 95{ 96 devctl_notify("AEON", "power", "press", NULL); 97} 98 99/* Manually configure the power button IRQ handler. */ 100static void 101aeon_setup_intr(void *unused) 102{ 103 int irq; 104 105 if (!is_aeon) 106 return; 107 108 if (bootverbose) 109 printf("Configuring AmigaOne power button.\n"); 110 111 irq = 4; /* From TRM, IRQ4 is raised when power button is pressed. */ 112 113 /* Get us the root PIC. */ 114 irq = MAP_IRQ(0, irq); 115 powerpc_config_intr(irq, INTR_TRIGGER_EDGE, INTR_POLARITY_LOW); 116 powerpc_setup_intr("power_button", irq, NULL, aeon_pbutton_intr, NULL, 117 INTR_TYPE_MISC, NULL, 0); 118} 119 120SYSINIT(aeon_setup_intr, SI_SUB_CONFIGURE, SI_ORDER_ANY, aeon_setup_intr, NULL); 121