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