ug_acpi.c revision 1.2
11.2Sxtraeme/* $NetBSD: ug_acpi.c,v 1.2 2007/05/08 17:17:14 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.2Sxtraeme__KERNEL_RCSID(0, "$NetBSD: ug_acpi.c,v 1.2 2007/05/08 17:17:14 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.1Sxtraeme#include <machine/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.1Sxtraemestatic int	ug_acpi_match(struct device *, struct cfdata *, void *);
531.1Sxtraemestatic void	ug_acpi_attach(struct device *, struct device *, void *);
541.1Sxtraeme
551.1SxtraemeCFATTACH_DECL(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.1Sxtraemeug_acpi_match(struct device *parent, struct cfdata *match,
701.1Sxtraeme    void *aux)
711.1Sxtraeme{
721.1Sxtraeme	struct acpi_attach_args *aa = aux;
731.1Sxtraeme
741.1Sxtraeme	if (aa->aa_node->ad_type != ACPI_TYPE_DEVICE)
751.1Sxtraeme		return 0;
761.1Sxtraeme
771.1Sxtraeme	return acpi_match_hid(aa->aa_node->ad_devinfo, ug_acpi_ids);
781.1Sxtraeme}
791.1Sxtraeme
801.1Sxtraemestatic void
811.1Sxtraemeug_acpi_attach(struct device *parent, struct device *self, void *aux)
821.1Sxtraeme{
831.1Sxtraeme	struct ug_softc *sc = (struct ug_softc*)self;
841.1Sxtraeme	struct acpi_attach_args *aa = aux;
851.1Sxtraeme	struct acpi_resources res;
861.1Sxtraeme	struct acpi_io *io;
871.1Sxtraeme	bus_space_handle_t ioh;
881.1Sxtraeme	ACPI_STATUS rv;
891.1Sxtraeme
901.1Sxtraeme	aprint_naive("\n");
911.1Sxtraeme	aprint_normal("\n");
921.1Sxtraeme
931.1Sxtraeme	/* parse resources */
941.1Sxtraeme	rv = acpi_resource_parse(&sc->sc_dev, aa->aa_node->ad_handle, "_CRS",
951.1Sxtraeme	    &res, &acpi_resource_parse_ops_default);
961.1Sxtraeme	if (ACPI_FAILURE(rv))
971.1Sxtraeme		return;
981.1Sxtraeme
991.1Sxtraeme	/* find our i/o registers */
1001.1Sxtraeme	io = acpi_res_io(&res, 0);
1011.1Sxtraeme	if (io == NULL) {
1021.1Sxtraeme		aprint_error("%s: unable to find i/o register resource\n",
1031.1Sxtraeme		    sc->sc_dev.dv_xname);
1041.1Sxtraeme		acpi_resource_cleanup(&res);
1051.1Sxtraeme		return;
1061.1Sxtraeme	}
1071.1Sxtraeme
1081.1Sxtraeme	if (bus_space_map(aa->aa_iot, io->ar_base, io->ar_length,
1091.1Sxtraeme	    0, &ioh)) {
1101.1Sxtraeme		aprint_error("%s: can't map i/o space\n",
1111.1Sxtraeme		    sc->sc_dev.dv_xname);
1121.1Sxtraeme		acpi_resource_cleanup(&res);
1131.1Sxtraeme		return;
1141.1Sxtraeme	}
1151.1Sxtraeme
1161.1Sxtraeme	aprint_normal("%s", sc->sc_dev.dv_xname);
1171.1Sxtraeme
1181.1Sxtraeme	sc->version = 2;	/* uGuru 2005 */
1191.1Sxtraeme	sc->sc_ioh = ioh;
1201.1Sxtraeme	sc->sc_iot = aa->aa_iot;
1211.1Sxtraeme	ug2_attach(sc);
1221.1Sxtraeme
1231.1Sxtraeme	acpi_resource_cleanup(&res);
1241.1Sxtraeme}
125