ug_acpi.c revision 1.1
11.1Sxtraeme/* $NetBSD: ug_acpi.c,v 1.1 2007/05/08 16:48:38 xtraeme Exp $ */
21.1Sxtraeme
31.1Sxtraeme/*
41.1Sxtraeme * Copyright (c) 2007 Mihai Chelaru <kefren@netbsd.ro>
51.1Sxtraeme * All rights reserved.
61.1Sxtraeme *
71.1Sxtraeme * Redistribution and use in source and binary forms, with or without
81.1Sxtraeme * modification, are permitted provided that the following conditions
91.1Sxtraeme * are met:
101.1Sxtraeme * 1. Redistributions of source code must retain the above copyright
111.1Sxtraeme *    notice, this list of conditions and the following disclaimer.
121.1Sxtraeme * 2. The name of the author may not be used to endorse or promote products
131.1Sxtraeme *    derived from this software without specific prior written permission.
141.1Sxtraeme *
151.1Sxtraeme * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
161.1Sxtraeme * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
171.1Sxtraeme * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
181.1Sxtraeme * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
191.1Sxtraeme * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
201.1Sxtraeme * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
211.1Sxtraeme * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
221.1Sxtraeme * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
231.1Sxtraeme * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
241.1Sxtraeme * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
251.1Sxtraeme * SUCH DAMAGE.
261.1Sxtraeme */
271.1Sxtraeme
281.1Sxtraeme#include <sys/param.h>
291.1Sxtraeme#include <sys/systm.h>
301.1Sxtraeme#include <sys/errno.h>
311.1Sxtraeme#include <sys/ioctl.h>
321.1Sxtraeme#include <sys/syslog.h>
331.1Sxtraeme#include <sys/device.h>
341.1Sxtraeme#include <sys/proc.h>
351.1Sxtraeme#include <sys/envsys.h>
361.1Sxtraeme
371.1Sxtraeme#include <machine/bus.h>
381.1Sxtraeme
391.1Sxtraeme#include <dev/acpi/acpica.h>
401.1Sxtraeme#include <dev/acpi/acpireg.h>
411.1Sxtraeme#include <dev/acpi/acpivar.h>
421.1Sxtraeme
431.1Sxtraeme#include <dev/sysmon/sysmonvar.h>
441.1Sxtraeme
451.1Sxtraeme#include <dev/ic/ugreg.h>
461.1Sxtraeme#include <dev/ic/ugvar.h>
471.1Sxtraeme
481.1Sxtraeme/* autoconf(9) functions */
491.1Sxtraemestatic int	ug_acpi_match(struct device *, struct cfdata *, void *);
501.1Sxtraemestatic void	ug_acpi_attach(struct device *, struct device *, void *);
511.1Sxtraeme
521.1SxtraemeCFATTACH_DECL(ug_acpi, sizeof(struct ug_softc), ug_acpi_match,
531.1Sxtraeme    ug_acpi_attach, NULL, NULL);
541.1Sxtraeme
551.1Sxtraeme/*
561.1Sxtraeme * Supported devices
571.1Sxtraeme * XXX: only uGuru 2005 for now
581.1Sxtraeme */
591.1Sxtraeme
601.1Sxtraemestatic const char* const ug_acpi_ids[] = {
611.1Sxtraeme	"ABT2005",	/* uGuru 2005 */
621.1Sxtraeme	NULL
631.1Sxtraeme};
641.1Sxtraeme
651.1Sxtraemestatic int
661.1Sxtraemeug_acpi_match(struct device *parent, struct cfdata *match,
671.1Sxtraeme    void *aux)
681.1Sxtraeme{
691.1Sxtraeme	struct acpi_attach_args *aa = aux;
701.1Sxtraeme
711.1Sxtraeme	if (aa->aa_node->ad_type != ACPI_TYPE_DEVICE)
721.1Sxtraeme		return 0;
731.1Sxtraeme
741.1Sxtraeme	return acpi_match_hid(aa->aa_node->ad_devinfo, ug_acpi_ids);
751.1Sxtraeme}
761.1Sxtraeme
771.1Sxtraemestatic void
781.1Sxtraemeug_acpi_attach(struct device *parent, struct device *self, void *aux)
791.1Sxtraeme{
801.1Sxtraeme	struct ug_softc *sc = (struct ug_softc*)self;
811.1Sxtraeme	struct acpi_attach_args *aa = aux;
821.1Sxtraeme	struct acpi_resources res;
831.1Sxtraeme	struct acpi_io *io;
841.1Sxtraeme	bus_space_handle_t ioh;
851.1Sxtraeme	ACPI_STATUS rv;
861.1Sxtraeme
871.1Sxtraeme	aprint_naive("\n");
881.1Sxtraeme	aprint_normal("\n");
891.1Sxtraeme
901.1Sxtraeme	/* parse resources */
911.1Sxtraeme	rv = acpi_resource_parse(&sc->sc_dev, aa->aa_node->ad_handle, "_CRS",
921.1Sxtraeme	    &res, &acpi_resource_parse_ops_default);
931.1Sxtraeme	if (ACPI_FAILURE(rv))
941.1Sxtraeme		return;
951.1Sxtraeme
961.1Sxtraeme	/* find our i/o registers */
971.1Sxtraeme	io = acpi_res_io(&res, 0);
981.1Sxtraeme	if (io == NULL) {
991.1Sxtraeme		aprint_error("%s: unable to find i/o register resource\n",
1001.1Sxtraeme		    sc->sc_dev.dv_xname);
1011.1Sxtraeme		acpi_resource_cleanup(&res);
1021.1Sxtraeme		return;
1031.1Sxtraeme	}
1041.1Sxtraeme
1051.1Sxtraeme	if (bus_space_map(aa->aa_iot, io->ar_base, io->ar_length,
1061.1Sxtraeme	    0, &ioh)) {
1071.1Sxtraeme		aprint_error("%s: can't map i/o space\n",
1081.1Sxtraeme		    sc->sc_dev.dv_xname);
1091.1Sxtraeme		acpi_resource_cleanup(&res);
1101.1Sxtraeme		return;
1111.1Sxtraeme	}
1121.1Sxtraeme
1131.1Sxtraeme	aprint_normal("%s", sc->sc_dev.dv_xname);
1141.1Sxtraeme
1151.1Sxtraeme	sc->version = 2;	/* uGuru 2005 */
1161.1Sxtraeme	sc->sc_ioh = ioh;
1171.1Sxtraeme	sc->sc_iot = aa->aa_iot;
1181.1Sxtraeme	ug2_attach(sc);
1191.1Sxtraeme
1201.1Sxtraeme	acpi_resource_cleanup(&res);
1211.1Sxtraeme}
122