ug_acpi.c revision 1.4
11.4Sxtraeme/* $NetBSD: ug_acpi.c,v 1.4 2008/03/26 16:09:37 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.2Sxtraeme#include <sys/cdefs.h>
291.4Sxtraeme__KERNEL_RCSID(0, "$NetBSD: ug_acpi.c,v 1.4 2008/03/26 16:09:37 xtraeme Exp $");
301.2Sxtraeme
311.1Sxtraeme#include <sys/param.h>
321.1Sxtraeme#include <sys/systm.h>
331.1Sxtraeme#include <sys/errno.h>
341.1Sxtraeme#include <sys/ioctl.h>
351.1Sxtraeme#include <sys/syslog.h>
361.1Sxtraeme#include <sys/device.h>
371.1Sxtraeme#include <sys/proc.h>
381.1Sxtraeme#include <sys/envsys.h>
391.1Sxtraeme
401.3Sad#include <sys/bus.h>
411.1Sxtraeme
421.1Sxtraeme#include <dev/acpi/acpica.h>
431.1Sxtraeme#include <dev/acpi/acpireg.h>
441.1Sxtraeme#include <dev/acpi/acpivar.h>
451.1Sxtraeme
461.1Sxtraeme#include <dev/sysmon/sysmonvar.h>
471.1Sxtraeme
481.1Sxtraeme#include <dev/ic/ugreg.h>
491.1Sxtraeme#include <dev/ic/ugvar.h>
501.1Sxtraeme
511.1Sxtraeme/* autoconf(9) functions */
521.4Sxtraemestatic int	ug_acpi_match(device_t, cfdata_t, void *);
531.4Sxtraemestatic void	ug_acpi_attach(device_t, device_t, void *);
541.1Sxtraeme
551.4SxtraemeCFATTACH_DECL_NEW(ug_acpi, sizeof(struct ug_softc), ug_acpi_match,
561.1Sxtraeme    ug_acpi_attach, NULL, NULL);
571.1Sxtraeme
581.1Sxtraeme/*
591.1Sxtraeme * Supported devices
601.1Sxtraeme * XXX: only uGuru 2005 for now
611.1Sxtraeme */
621.1Sxtraeme
631.1Sxtraemestatic const char* const ug_acpi_ids[] = {
641.1Sxtraeme	"ABT2005",	/* uGuru 2005 */
651.1Sxtraeme	NULL
661.1Sxtraeme};
671.1Sxtraeme
681.1Sxtraemestatic int
691.4Sxtraemeug_acpi_match(device_t parent, cfdata_t match, void *aux)
701.1Sxtraeme{
711.1Sxtraeme	struct acpi_attach_args *aa = aux;
721.1Sxtraeme
731.1Sxtraeme	if (aa->aa_node->ad_type != ACPI_TYPE_DEVICE)
741.1Sxtraeme		return 0;
751.1Sxtraeme
761.1Sxtraeme	return acpi_match_hid(aa->aa_node->ad_devinfo, ug_acpi_ids);
771.1Sxtraeme}
781.1Sxtraeme
791.1Sxtraemestatic void
801.4Sxtraemeug_acpi_attach(device_t parent, device_t self, void *aux)
811.1Sxtraeme{
821.4Sxtraeme	struct ug_softc *sc = device_private(self);
831.1Sxtraeme	struct acpi_attach_args *aa = aux;
841.1Sxtraeme	struct acpi_resources res;
851.1Sxtraeme	struct acpi_io *io;
861.1Sxtraeme	bus_space_handle_t ioh;
871.1Sxtraeme	ACPI_STATUS rv;
881.1Sxtraeme
891.1Sxtraeme	aprint_naive("\n");
901.1Sxtraeme	aprint_normal("\n");
911.1Sxtraeme
921.1Sxtraeme	/* parse resources */
931.4Sxtraeme	rv = acpi_resource_parse(self, aa->aa_node->ad_handle, "_CRS",
941.1Sxtraeme	    &res, &acpi_resource_parse_ops_default);
951.1Sxtraeme	if (ACPI_FAILURE(rv))
961.1Sxtraeme		return;
971.1Sxtraeme
981.1Sxtraeme	/* find our i/o registers */
991.1Sxtraeme	io = acpi_res_io(&res, 0);
1001.1Sxtraeme	if (io == NULL) {
1011.4Sxtraeme		aprint_error_dev(self,
1021.4Sxtraeme		    "unable to find i/o register resource\n");
1031.1Sxtraeme		acpi_resource_cleanup(&res);
1041.1Sxtraeme		return;
1051.1Sxtraeme	}
1061.1Sxtraeme
1071.1Sxtraeme	if (bus_space_map(aa->aa_iot, io->ar_base, io->ar_length,
1081.1Sxtraeme	    0, &ioh)) {
1091.4Sxtraeme		aprint_error_dev(self, "can't map i/o space\n");
1101.1Sxtraeme		acpi_resource_cleanup(&res);
1111.1Sxtraeme		return;
1121.1Sxtraeme	}
1131.1Sxtraeme
1141.4Sxtraeme	aprint_normal("%s", device_xname(self));
1151.1Sxtraeme
1161.1Sxtraeme	sc->version = 2;	/* uGuru 2005 */
1171.1Sxtraeme	sc->sc_ioh = ioh;
1181.1Sxtraeme	sc->sc_iot = aa->aa_iot;
1191.4Sxtraeme	ug2_attach(self);
1201.1Sxtraeme
1211.1Sxtraeme	acpi_resource_cleanup(&res);
1221.1Sxtraeme}
123