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