Path: blob/main/sys/powerpc/amigaone/platform_amigaone.c
39536 views
/*-1* Copyright (c) 2019 Justin Hibbits2*3* Redistribution and use in source and binary forms, with or without4* modification, are permitted provided that the following conditions5* are met:6*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 ``AS IS'' AND ANY EXPRESS OR14* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES15* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.16* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,17* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT18* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,19* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY20* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT21* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF22* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.23*/2425#include <sys/param.h>26#include <sys/systm.h>27#include <sys/kernel.h>28#include <sys/bus.h>29#include <sys/malloc.h>30#include <sys/smp.h>3132#include <machine/intr_machdep.h>33#include <machine/platform.h>34#include <machine/platformvar.h>3536#include <dev/ofw/openfirm.h>37#include <dev/ofw/ofw_bus.h>3839#include <powerpc/mpc85xx/mpc85xx.h>4041#include "platform_if.h"4243static void aeon_pbutton_intr(void *_unused);44static void aeon_setup_intr(void *unused);4546static int aeon_probe(platform_t);47static int aeon_attach(platform_t);4849static platform_method_t aeon_methods[] = {50PLATFORMMETHOD(platform_probe, aeon_probe),51PLATFORMMETHOD(platform_attach, aeon_attach),52PLATFORMMETHOD_END53};5455DEFINE_CLASS_1(aeon, aeon_platform, aeon_methods, 0, mpc85xx_platform);5657PLATFORM_DEF(aeon_platform);5859static bool is_aeon;6061static int62aeon_probe(platform_t plat)63{64phandle_t rootnode;65char model[32];6667rootnode = OF_finddevice("/");6869if (OF_getprop(rootnode, "model", model, sizeof(model)) > 0) {70if (strncmp(model, "varisys,", strlen("varisys,")) == 0)71return (BUS_PROBE_SPECIFIC);72}7374return (ENXIO);75}7677static int78aeon_attach(platform_t plat)79{80int error;8182error = mpc85xx_attach(plat);83if (error)84return (error);8586is_aeon = true;8788return (0);89}9091/* Notify devd(8) that the power button was pressed (IRQ#4 on A-Eon machines). */92static void93aeon_pbutton_intr(void *_unused)94{95devctl_notify("AEON", "power", "press", NULL);96}9798/* Manually configure the power button IRQ handler. */99static void100aeon_setup_intr(void *unused)101{102int irq;103104if (!is_aeon)105return;106107if (bootverbose)108printf("Configuring AmigaOne power button.\n");109110irq = 4; /* From TRM, IRQ4 is raised when power button is pressed. */111112/* Get us the root PIC. */113irq = MAP_IRQ(0, irq);114powerpc_config_intr(irq, INTR_TRIGGER_EDGE, INTR_POLARITY_LOW);115powerpc_setup_intr("power_button", irq, NULL, aeon_pbutton_intr, NULL,116INTR_TYPE_MISC, NULL, 0);117}118119SYSINIT(aeon_setup_intr, SI_SUB_CONFIGURE, SI_ORDER_ANY, aeon_setup_intr, NULL);120121122