asmcvar.h revision 182850
190075Sobrien/*-
290075Sobrien * Copyright (c) 2007, 2008 Rui Paulo <rpaulo@FreeBSD.org>
390075Sobrien * All rights reserved.
490075Sobrien *
590075Sobrien * Redistribution and use in source and binary forms, with or without
690075Sobrien * modification, are permitted provided that the following conditions
790075Sobrien * are met:
890075Sobrien * 1. Redistributions of source code must retain the above copyright
990075Sobrien *    notice, this list of conditions and the following disclaimer.
1090075Sobrien * 2. Redistributions in binary form must reproduce the above copyright
1190075Sobrien *    notice, this list of conditions and the following disclaimer in the
1290075Sobrien *    documentation and/or other materials provided with the distribution.
1390075Sobrien *
1490075Sobrien * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
1590075Sobrien * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
1690075Sobrien * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
1790075Sobrien * DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
1890075Sobrien * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
1990075Sobrien * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
2090075Sobrien * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2190075Sobrien * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
2290075Sobrien * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
2390075Sobrien * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2490075Sobrien * POSSIBILITY OF SUCH DAMAGE.
2590075Sobrien *
2690075Sobrien * $FreeBSD: head/sys/dev/asmc/asmcvar.h 182850 2008-09-07 18:15:34Z rpaulo $
2790075Sobrien *
2890075Sobrien */
2990075Sobrien
3090075Sobrien#define ASMC_MAXFANS	2
3190075Sobrien
3290075Sobrienstruct asmc_softc {
3390075Sobrien	device_t 		sc_dev;
3490075Sobrien	struct mtx 		sc_mtx;
3590075Sobrien	int 			sc_nfan;
3690075Sobrien	int16_t			sms_rest_x;
3790075Sobrien	int16_t			sms_rest_y;
3890075Sobrien	int16_t			sms_rest_z;
3990075Sobrien	struct sysctl_oid 	*sc_fan_tree[ASMC_MAXFANS+1];
4090075Sobrien	struct sysctl_oid 	*sc_temp_tree;
4190075Sobrien	struct sysctl_oid 	*sc_sms_tree;
4290075Sobrien	struct sysctl_oid 	*sc_light_tree;
4390075Sobrien	struct asmc_model 	*sc_model;
4490075Sobrien	int 			sc_rid_port;
4590075Sobrien	int 			sc_rid_irq;
4690075Sobrien	struct resource 	*sc_ioport;
4790075Sobrien	struct resource 	*sc_irq;
4890075Sobrien	void 			*sc_cookie;
4990075Sobrien	int 			sc_sms_intrtype;
5090075Sobrien	struct taskqueue 	*sc_sms_tq;
5190075Sobrien	struct task 		sc_sms_task;
5290075Sobrien};
5390075Sobrien
5490075Sobrien/*
5590075Sobrien * Data port.
5690075Sobrien */
5790075Sobrien#define ASMC_DATAPORT_READ(sc)	bus_read_1(sc->sc_ioport, 0x00)
5890075Sobrien#define ASMC_DATAPORT_WRITE(sc, val) \
5990075Sobrien	bus_write_1(sc->sc_ioport, 0x00, val)
6090075Sobrien#define ASMC_STATUS_MASK 	0x0f
6190075Sobrien
6290075Sobrien/*
6390075Sobrien * Command port.
6490075Sobrien */
6590075Sobrien#define ASMC_CMDPORT_READ(sc)	bus_read_1(sc->sc_ioport, 0x04)
6690075Sobrien#define ASMC_CMDPORT_WRITE(sc, val) \
6790075Sobrien	bus_write_1(sc->sc_ioport, 0x04, val)
6890075Sobrien#define ASMC_CMDREAD		0x10
6990075Sobrien#define ASMC_CMDWRITE		0x11
7090075Sobrien
7190075Sobrien/*
7290075Sobrien * Interrupt port.
7390075Sobrien */
7490075Sobrien#define ASMC_INTPORT_READ(sc)	bus_read_1(sc->sc_ioport, 0x1f)
7590075Sobrien
7690075Sobrien
7790075Sobrien/* Number of keys */
7890075Sobrien#define ASMC_NKEYS		"#KEY"	/* RO; 4 bytes */
7990075Sobrien
8090075Sobrien/*
8190075Sobrien * Fan control via SMC.
8290075Sobrien */
8390075Sobrien#define ASMC_KEY_FANCOUNT	"FNum"	/* RO; 1 byte */
8490075Sobrien#define ASMC_KEY_FANMANUAL	"FS! "	/* RW; 2 bytes */
8590075Sobrien#define ASMC_KEY_FANSPEED	"F%dAc"	/* RO; 2 bytes */
8690075Sobrien#define ASMC_KEY_FANMINSPEED	"F%dMn"	/* RO; 2 bytes */
8790075Sobrien#define ASMC_KEY_FANMAXSPEED	"F%dMx"	/* RO; 2 bytes */
8890075Sobrien#define ASMC_KEY_FANSAFESPEED	"F%dSf"	/* RO; 2 bytes */
8990075Sobrien#define ASMC_KEY_FANTARGETSPEED	"F%dTg"	/* RW; 2 bytes */
9090075Sobrien
9190075Sobrien/*
9290075Sobrien * Sudden Motion Sensor (SMS).
9390075Sobrien */
9490075Sobrien#define ASMC_SMS_INIT1		0xe0
9590075Sobrien#define ASMC_SMS_INIT2		0xf8
9690075Sobrien#define ASMC_KEY_SMS		"MOCN"	/* RW; 2 bytes */
9790075Sobrien#define ASMC_KEY_SMS_X		"MO_X"	/* RO; 2 bytes */
9890075Sobrien#define ASMC_KEY_SMS_Y		"MO_Y"	/* RO; 2 bytes */
9990075Sobrien#define ASMC_KEY_SMS_Z		"MO_Z"	/* RO; 2 bytes */
10090075Sobrien#define ASMC_KEY_SMS_LOW	"MOLT"	/* RW; 2 bytes */
10190075Sobrien#define ASMC_KEY_SMS_HIGH	"MOHT"	/* RW; 2 bytes */
10290075Sobrien#define ASMC_KEY_SMS_LOW_INT	"MOLD"	/* RW; 1 byte */
10390075Sobrien#define ASMC_KEY_SMS_HIGH_INT	"MOHD"	/* RW; 1 byte */
10490075Sobrien#define ASMC_KEY_SMS_FLAG	"MSDW"	/* RW; 1 byte */
10590075Sobrien#define ASMC_SMS_INTFF		0x60	/* Free fall Interrupt */
10690075Sobrien#define ASMC_SMS_INTHA		0x6f	/* High Acceleration Interrupt */
10790075Sobrien#define ASMC_SMS_INTSH		0x80	/* Shock Interrupt */
10890075Sobrien
10990075Sobrien/*
11090075Sobrien * Keyboard backlight.
11190075Sobrien */
11290075Sobrien#define ASMC_KEY_LIGHTLEFT	"ALV0"	/* RO; 6 bytes */
11390075Sobrien#define ASMC_KEY_LIGHTRIGHT	"ALV1"	/* RO; 6 bytes */
11490075Sobrien#define ASMC_KEY_LIGHTVALUE	"LKSB"	/* WO; 2 bytes */
11590075Sobrien
11690075Sobrien/*
11790075Sobrien * Clamshell.
11890075Sobrien */
11990075Sobrien#define ASMC_KEY_CLAMSHELL	"MSLD"	/* RO; 1 byte */
12090075Sobrien
12190075Sobrien/*
12290075Sobrien * Interrupt keys.
12390075Sobrien */
12490075Sobrien#define ASMC_KEY_INTOK		"NTOK"	/* WO; 1 byte */
12590075Sobrien
12690075Sobrien/*
12790075Sobrien * Temperatures.
12890075Sobrien *
12990075Sobrien * First for MacBook, second for MacBook Pro, third for Intel Mac Mini,
13090075Sobrien * fourth the Mac Pro 8-core and finally the MacBook Air.
13190075Sobrien *
13290075Sobrien */
13390075Sobrien/* maximum array size for temperatures including the last NULL */
13490075Sobrien#define ASMC_TEMP_MAX		36
13590075Sobrien#define ASMC_MB_TEMPS		{ "TB0T", "TN0P", "TN1P", "Th0H", "Th1H", \
13690075Sobrien				  "TM0P", NULL }
13790075Sobrien#define ASMC_MB_TEMPNAMES	{ "enclosure", "northbridge1", \
13890075Sobrien				  "northbridge2", "heatsink1", \
13990075Sobrien				  "heatsink2", "memory", }
14090075Sobrien#define ASMC_MB_TEMPDESCS	{ "Enclosure Bottomside", \
14190075Sobrien				  "Northbridge Point 1", \
14290075Sobrien				  "Northbridge Point 2", "Heatsink 1", \
14390075Sobrien				  "Heatsink 2", "Memory Bank A", }
14490075Sobrien
14590075Sobrien#define ASMC_MBP_TEMPS		{ "TB0T", "Th0H", "Th1H", "Tm0P", \
14690075Sobrien				  "TG0H", "TG0P", "TG0T", NULL }
14790075Sobrien
14890075Sobrien#define ASMC_MBP_TEMPNAMES	{ "enclosure", "heatsink1", \
14990075Sobrien				  "heatsink2", "memory", "graphics", \
15090075Sobrien				  "graphicssink", "unknown", }
15190075Sobrien
15290075Sobrien#define ASMC_MBP_TEMPDESCS	{ "Enclosure Bottomside", \
15390075Sobrien				  "Heatsink 1", "Heatsink 2", \
15490075Sobrien				  "Memory Controller", \
15590075Sobrien				  "Graphics Chip", "Graphics Heatsink", \
15690075Sobrien				  "Unknown", }
15790075Sobrien
15890075Sobrien#define ASMC_MM_TEMPS		{ "TN0P", "TN1P", NULL }
15990075Sobrien#define ASMC_MM_TEMPNAMES	{ "northbridge1", "northbridge2" }
16090075Sobrien#define ASMC_MM_TEMPDESCS	{ "Northbridge Point 1", \
16190075Sobrien				  "Northbridge Point 2" }
16290075Sobrien
16390075Sobrien#define ASMC_MP_TEMPS		{ "TA0P", "TCAG", "TCAH", "TCBG", "TCBH", \
16490075Sobrien				  "TC0C", "TC0D", "TC0P", "TC1C", "TC1D", \
16590075Sobrien				  "TC2C", "TC2D", "TC3C", "TC3D", "THTG", \
16690075Sobrien				  "TH0P", "TH1P", "TH2P", "TH3P", "TMAP", \
16790075Sobrien				  "TMAS", "TMBS", "TM0P", "TM0S", "TM1P", \
16890075Sobrien				  "TM1S", "TM2P", "TM2S", "TM3S", "TM8P", \
16990075Sobrien				  "TM8S", "TM9P", "TM9S", "TN0H", "TS0C", \
17090075Sobrien				  NULL }
17190075Sobrien
17290075Sobrien#define ASMC_MP_TEMPNAMES	{ "TA0P", "TCAG", "TCAH", "TCBG", "TCBH", \
17390075Sobrien				  "TC0C", "TC0D", "TC0P", "TC1C", "TC1D", \
17490075Sobrien				  "TC2C", "TC2D", "TC3C", "TC3D", "THTG", \
17590075Sobrien				  "TH0P", "TH1P", "TH2P", "TH3P", "TMAP", \
17690075Sobrien				  "TMAS", "TMBS", "TM0P", "TM0S", "TM1P", \
17790075Sobrien				  "TM1S", "TM2P", "TM2S", "TM3S", "TM8P", \
17890075Sobrien				  "TM8S", "TM9P", "TM9S", "TN0H", "TS0C", \
17990075Sobrien				  NULL }
18090075Sobrien
18190075Sobrien#define ASMC_MP_TEMPDESCS	{ "TA0P", "TCAG", "TCAH", "TCBG", "TCBH", \
18290075Sobrien				  "TC0C", "TC0D", "TC0P", "TC1C", "TC1D", \
18390075Sobrien				  "TC2C", "TC2D", "TC3C", "TC3D", "THTG", \
18490075Sobrien				  "TH0P", "TH1P", "TH2P", "TH3P", "TMAP", \
18590075Sobrien				  "TMAS", "TMBS", "TM0P", "TM0S", "TM1P", \
18690075Sobrien				  "TM1S", "TM2P", "TM2S", "TM3S", "TM8P", \
18790075Sobrien				  "TM8S", "TM9P", "TM9S", "TN0H", "TS0C", \
18890075Sobrien				  NULL }
18990075Sobrien
19090075Sobrien#define	ASMC_MBA_TEMPS		{ "TB0T", NULL }
19190075Sobrien#define	ASMC_MBA_TEMPNAMES	{ "enclosure" }
19290075Sobrien#define	ASMC_MBA_TEMPDESCS	{ "Enclosure Bottom" }
19390075Sobrien