Home | History | Annotate | Line # | Download | only in dev
smartbat.c revision 1.1
      1  1.1  macallan /*	$NetBSD: smartbat.c,v 1.1 2007/03/25 23:22:46 macallan Exp $ */
      2  1.1  macallan 
      3  1.1  macallan /*-
      4  1.1  macallan  * Copyright (c) 2007 Michael Lorenz
      5  1.1  macallan  * All rights reserved.
      6  1.1  macallan  *
      7  1.1  macallan  * Redistribution and use in source and binary forms, with or without
      8  1.1  macallan  * modification, are permitted provided that the following conditions
      9  1.1  macallan  * are met:
     10  1.1  macallan  * 1. Redistributions of source code must retain the above copyright
     11  1.1  macallan  *    notice, this list of conditions and the following disclaimer.
     12  1.1  macallan  * 2. Redistributions in binary form must reproduce the above copyright
     13  1.1  macallan  *    notice, this list of conditions and the following disclaimer in the
     14  1.1  macallan  *    documentation and/or other materials provided with the distribution.
     15  1.1  macallan  * 3. Neither the name of The NetBSD Foundation nor the names of its
     16  1.1  macallan  *    contributors may be used to endorse or promote products derived
     17  1.1  macallan  *    from this software without specific prior written permission.
     18  1.1  macallan  *
     19  1.1  macallan  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20  1.1  macallan  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21  1.1  macallan  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22  1.1  macallan  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23  1.1  macallan  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24  1.1  macallan  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25  1.1  macallan  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26  1.1  macallan  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27  1.1  macallan  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28  1.1  macallan  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29  1.1  macallan  * POSSIBILITY OF SUCH DAMAGE.
     30  1.1  macallan  */
     31  1.1  macallan 
     32  1.1  macallan #include <sys/cdefs.h>
     33  1.1  macallan __KERNEL_RCSID(0, "$NetBSD: smartbat.c,v 1.1 2007/03/25 23:22:46 macallan Exp $");
     34  1.1  macallan 
     35  1.1  macallan #include <sys/param.h>
     36  1.1  macallan #include <sys/systm.h>
     37  1.1  macallan #include <sys/kernel.h>
     38  1.1  macallan #include <sys/device.h>
     39  1.1  macallan #include <sys/proc.h>
     40  1.1  macallan 
     41  1.1  macallan #include <dev/sysmon/sysmonvar.h>
     42  1.1  macallan #include <dev/sysmon/sysmon_taskq.h>
     43  1.1  macallan 
     44  1.1  macallan #include <macppc/dev/pmuvar.h>
     45  1.1  macallan #include <macppc/dev/batteryvar.h>
     46  1.1  macallan #include <machine/bus.h>
     47  1.1  macallan #include "opt_battery.h"
     48  1.1  macallan 
     49  1.1  macallan #ifdef SMARTBAT_DEBUG
     50  1.1  macallan #define DPRINTF printf
     51  1.1  macallan #else
     52  1.1  macallan #define DPRINTF while (0) printf
     53  1.1  macallan #endif
     54  1.1  macallan 
     55  1.1  macallan #define BAT_CPU_TEMPERATURE	0
     56  1.1  macallan #define BAT_AC_PRESENT		1
     57  1.1  macallan #define BAT_PRESENT		2
     58  1.1  macallan #define BAT_VOLTAGE		3
     59  1.1  macallan #define BAT_CURRENT		4
     60  1.1  macallan #define BAT_MAX_CHARGE		5
     61  1.1  macallan #define BAT_CHARGE		6
     62  1.1  macallan #define BAT_CHARGING		7
     63  1.1  macallan #define BAT_DISCHARGING		8
     64  1.1  macallan #define BAT_FULL		9
     65  1.1  macallan #define BAT_TEMPERATURE		10
     66  1.1  macallan #define BAT_NSENSORS		11  /* number of sensors */
     67  1.1  macallan 
     68  1.1  macallan struct smartbat_softc {
     69  1.1  macallan 	struct device sc_dev;
     70  1.1  macallan 	struct pmu_ops *sc_pmu_ops;
     71  1.1  macallan 	int sc_num;
     72  1.1  macallan 
     73  1.1  macallan 	/* envsys stuff */
     74  1.1  macallan 	struct sysmon_envsys sc_sysmon;
     75  1.1  macallan 	struct envsys_basic_info sc_sinfo[BAT_NSENSORS];
     76  1.1  macallan 	struct envsys_tre_data sc_sdata[BAT_NSENSORS];
     77  1.1  macallan };
     78  1.1  macallan 
     79  1.1  macallan static void smartbat_attach(struct device *, struct device *, void *);
     80  1.1  macallan static int smartbat_match(struct device *, struct cfdata *, void *);
     81  1.1  macallan 
     82  1.1  macallan CFATTACH_DECL(smartbat, sizeof(struct smartbat_softc),
     83  1.1  macallan     smartbat_match, smartbat_attach, NULL, NULL);
     84  1.1  macallan 
     85  1.1  macallan static int
     86  1.1  macallan smartbat_match(struct device *parent, struct cfdata *cf, void *aux)
     87  1.1  macallan {
     88  1.1  macallan 	struct battery_attach_args *baa = aux;
     89  1.1  macallan 
     90  1.1  macallan 	if (baa->baa_type == BATTERY_TYPE_SMART)
     91  1.1  macallan 		return 1;
     92  1.1  macallan 
     93  1.1  macallan 	return 0;
     94  1.1  macallan }
     95  1.1  macallan 
     96  1.1  macallan static void
     97  1.1  macallan smartbat_attach(struct device *parent, struct device *self, void *aux)
     98  1.1  macallan {
     99  1.1  macallan 	struct battery_attach_args *baa = aux;
    100  1.1  macallan 	struct smartbat_softc *sc = (struct smartbat_softc *)self;
    101  1.1  macallan 
    102  1.1  macallan 	sc->sc_pmu_ops = baa->baa_pmu_ops;
    103  1.1  macallan 	sc->sc_num = baa->baa_num;
    104  1.1  macallan 
    105  1.1  macallan 	printf(" addr %d: smart battery\n", sc->sc_num);
    106  1.1  macallan 
    107  1.1  macallan }
    108