Re: Apple SMC chip - driver to read sensors and temperatures
Hi, On Fri, Jan 24, 2014 at 11:00:32PM +, peb.nowa...@bluewin.ch wrote: I was working on the asmc kernel driver for the Macbooks. I have a MBPro8.2 (mid 2011), and came to get the driver installed, reading all sensors and temperatures into the hw.sensors framework. See attached diffs. Beginning line 30 I describe the ideas for the driver. Further information available, also a todo list. Thx to Joshua@, who helped me to create the diffs below, and provided input for the todo list. Looking forward to get some feedback, especially on other Apple hardware. I tested this on my MacBook Air 4,2 and got the following in dmesg: ASMC_MATCH BIOS: vendor Apple Inc., product MacBookAir4,2 ** ERROR: no model found for MacBookAir4,2 Hence, I added blindly the following asmc_model line to your diff: + { MacBookAir4,2, 3, 0, 0, 63, 511, 10 }, With this line I got the following in sysctl output: hw.sensors.applesmc.fan0=1992 RPM (fan0_speed) hw.sensors.applesmc.fan1=0 RPM (fan1_speed), UNKNOWN hw.sensors.applesmc.fan2=2000 RPM (fan0_targetspeed) hw.sensors.applesmc.fan3=0 RPM (fan1_targetspeed), UNKNOWN hw.sensors.applesmc.fan4=0 RPM (fan0_safespeed), UNKNOWN hw.sensors.applesmc.fan5=0 RPM (fan1_safespeed), UNKNOWN hw.sensors.applesmc.fan6=2000 RPM (fan0_minspeed) hw.sensors.applesmc.fan7=0 RPM (fan1_minspeed), UNKNOWN hw.sensors.applesmc.fan8=6500 RPM (fan0_maxspeed) hw.sensors.applesmc.fan9=0 RPM (fan1_maxspeed), UNKNOWN hw.sensors.applesmc.raw0=36 (Enclosure Bottom) hw.sensors.applesmc.raw1=76 (CPU Temperature Diode) hw.sensors.applesmc.illuminance0=0.00 lx (lightright) hw.sensors.applesmc.illuminance1=0.00 lx (lightleft) hw.sensors.applesmc.acceleration0=0. m/s^2 (sms_x), UNKNOWN hw.sensors.applesmc.acceleration1=0. m/s^2 (sms_y), UNKNOWN hw.sensors.applesmc.acceleration2=0. m/s^2 (sms_z), UNKNOWN Since, it works only partially, I guess the asmc_model line requires further tweaking? Anything else I can test? Whole dmesg follows below. Thanks, Regards, Joerg OpenBSD 5.5-beta (GENERIC.MP) #1: Sun Feb 2 13:14:43 CET 2014 r...@marvin.hq.umaxx.net:/usr/src_apple/sys/arch/amd64/compile/GENERIC.MP RTC BIOS diagnostic error cfclock_battery,ROM_cksum,fixed_disk,invalid_time real mem = 4185079808 (3991MB) avail mem = 4065439744 (3877MB) mainbus0 at root bios0 at mainbus0: SMBIOS rev. 2.4 @ 0xe (53 entries) bios0: vendor Apple Inc. version MBA41.88Z.0077.B0F.1201241549 date 01/24/2012 bios0: Apple Inc. MacBookAir4,2 acpi0 at bios0: rev 2 acpi0: sleep states S0 S3 S4 S5 acpi0: tables DSDT FACP HPET APIC SBST ECDT SSDT SSDT SSDT SSDT SSDT SSDT SSDT SSDT MCFG SSDT SSDT SSDT acpi0: wakeup devices P0P2(S4) EC__(S4) HDEF(S4) ARPT(S4) RP02(S4) EHC1(S3) EHC2(S3) ADP1(S4) LID0(S4) acpitimer0 at acpi0: 3579545 Hz, 24 bits acpihpet0 at acpi0: 14318179 Hz acpimadt0 at acpi0 addr 0xfee0: PC-AT compat cpu0 at mainbus0: apid 0 (boot processor) cpu0: Intel(R) Core(TM) i7-2677M CPU @ 1.80GHz, 1800.30 MHz cpu0: FPU,VME,DE,PSE,TSC,MSR,PAE,MCE,CX8,APIC,SEP,MTRR,PGE,MCA,CMOV,PAT,PSE36,CFLUSH,DS,ACPI,MMX,FXSR,SSE,SSE2,SS,HTT,TM,PBE,SSE3,PCLMUL,DTES64,MWAIT,DS-CPL,VMX,SMX,EST,TM2,SSSE3,CX16,xTPR,PDCM,PCID,SSE4.1,SSE4.2,x2APIC,POPCNT,DEADLINE,AES,XSAVE,AVX,NXE,LONG,LAHF,PERF,ITSC cpu0: 256KB 64b/line 8-way L2 cache cpu0: smt 0, core 0, package 0 mtrr: Pentium Pro MTRR support, 10 var ranges, 88 fixed ranges cpu0: apic clock running at 100MHz cpu0: mwait min=64, max=64, C-substates=0.2.1.1.2, IBE cpu1 at mainbus0: apid 2 (application processor) cpu1: Intel(R) Core(TM) i7-2677M CPU @ 1.80GHz, 1800.02 MHz cpu1: FPU,VME,DE,PSE,TSC,MSR,PAE,MCE,CX8,APIC,SEP,MTRR,PGE,MCA,CMOV,PAT,PSE36,CFLUSH,DS,ACPI,MMX,FXSR,SSE,SSE2,SS,HTT,TM,PBE,SSE3,PCLMUL,DTES64,MWAIT,DS-CPL,VMX,SMX,EST,TM2,SSSE3,CX16,xTPR,PDCM,PCID,SSE4.1,SSE4.2,x2APIC,POPCNT,DEADLINE,AES,XSAVE,AVX,NXE,LONG,LAHF,PERF,ITSC cpu1: 256KB 64b/line 8-way L2 cache cpu1: smt 0, core 1, package 0 cpu2 at mainbus0: apid 1 (application processor) cpu2: Intel(R) Core(TM) i7-2677M CPU @ 1.80GHz, 1800.02 MHz cpu2: FPU,VME,DE,PSE,TSC,MSR,PAE,MCE,CX8,APIC,SEP,MTRR,PGE,MCA,CMOV,PAT,PSE36,CFLUSH,DS,ACPI,MMX,FXSR,SSE,SSE2,SS,HTT,TM,PBE,SSE3,PCLMUL,DTES64,MWAIT,DS-CPL,VMX,SMX,EST,TM2,SSSE3,CX16,xTPR,PDCM,PCID,SSE4.1,SSE4.2,x2APIC,POPCNT,DEADLINE,AES,XSAVE,AVX,NXE,LONG,LAHF,PERF,ITSC cpu2: 256KB 64b/line 8-way L2 cache cpu2: smt 1, core 0, package 0 cpu3 at mainbus0: apid 3 (application processor) cpu3: Intel(R) Core(TM) i7-2677M CPU @ 1.80GHz, 1800.02 MHz cpu3: FPU,VME,DE,PSE,TSC,MSR,PAE,MCE,CX8,APIC,SEP,MTRR,PGE,MCA,CMOV,PAT,PSE36,CFLUSH,DS,ACPI,MMX,FXSR,SSE,SSE2,SS,HTT,TM,PBE,SSE3,PCLMUL,DTES64,MWAIT,DS-CPL,VMX,SMX,EST,TM2,SSSE3,CX16,xTPR,PDCM,PCID,SSE4.1,SSE4.2,x2APIC,POPCNT,DEADLINE,AES,XSAVE,AVX,NXE,LONG,LAHF,PERF,ITSC cpu3: 256KB 64b/line 8-way L2 cache cpu3: smt 1, core 1, package 0 ioapic0 at mainbus0: apid 2 pa 0xfec0, version 20, 24 pins ioapic0: misconfigured as apic 0, remapped to apid 2 acpiec0 at acpi0 acpimcfg0 at
Re: Apple SMC chip - driver to read sensors and temperatures
Thanx for testing the driver. As you say, the driver needs further tweaking. I am in a very preliminary state a ith the coding :-) Your information is valuable for the future process. I would correct the mode line for your model. Need to get the right values for the temps and sensors;-) It is interesting, that the MacBook air has no x, y, z support - good! There is only SDD Drive, no need to get the heads of a standard HDD drive parked by the motion sensors. I am currently working on the light sensors to get my keyboard backlit... have you tried the trackpad driver from Joshua? MfG, regards, cordialement Volker Nowarra +41 79 503 4849 Envoyé de mon iPhone Am 02.02.2014 um 13:45 schrieb Joerg Jung m...@umaxx.net: Hi, On Fri, Jan 24, 2014 at 11:00:32PM +, peb.nowa...@bluewin.ch wrote: I was working on the asmc kernel driver for the Macbooks. I have a MBPro8.2 (mid 2011), and came to get the driver installed, reading all sensors and temperatures into the hw.sensors framework. See attached diffs. Beginning line 30 I describe the ideas for the driver. Further information available, also a todo list. Thx to Joshua@, who helped me to create the diffs below, and provided input for the todo list. Looking forward to get some feedback, especially on other Apple hardware. I tested this on my MacBook Air 4,2 and got the following in dmesg: ASMC_MATCH BIOS: vendor Apple Inc., product MacBookAir4,2 ** ERROR: no model found for MacBookAir4,2 Hence, I added blindly the following asmc_model line to your diff: +{ MacBookAir4,2, 3, 0, 0, 63, 511, 10 }, With this line I got the following in sysctl output: hw.sensors.applesmc.fan0=1992 RPM (fan0_speed) hw.sensors.applesmc.fan1=0 RPM (fan1_speed), UNKNOWN hw.sensors.applesmc.fan2=2000 RPM (fan0_targetspeed) hw.sensors.applesmc.fan3=0 RPM (fan1_targetspeed), UNKNOWN hw.sensors.applesmc.fan4=0 RPM (fan0_safespeed), UNKNOWN hw.sensors.applesmc.fan5=0 RPM (fan1_safespeed), UNKNOWN hw.sensors.applesmc.fan6=2000 RPM (fan0_minspeed) hw.sensors.applesmc.fan7=0 RPM (fan1_minspeed), UNKNOWN hw.sensors.applesmc.fan8=6500 RPM (fan0_maxspeed) hw.sensors.applesmc.fan9=0 RPM (fan1_maxspeed), UNKNOWN hw.sensors.applesmc.raw0=36 (Enclosure Bottom) hw.sensors.applesmc.raw1=76 (CPU Temperature Diode) hw.sensors.applesmc.illuminance0=0.00 lx (lightright) hw.sensors.applesmc.illuminance1=0.00 lx (lightleft) hw.sensors.applesmc.acceleration0=0. m/s^2 (sms_x), UNKNOWN hw.sensors.applesmc.acceleration1=0. m/s^2 (sms_y), UNKNOWN hw.sensors.applesmc.acceleration2=0. m/s^2 (sms_z), UNKNOWN Since, it works only partially, I guess the asmc_model line requires further tweaking? Anything else I can test? Whole dmesg follows below. Thanks, Regards, Joerg OpenBSD 5.5-beta (GENERIC.MP) #1: Sun Feb 2 13:14:43 CET 2014 r...@marvin.hq.umaxx.net:/usr/src_apple/sys/arch/amd64/compile/GENERIC.MP RTC BIOS diagnostic error cfclock_battery,ROM_cksum,fixed_disk,invalid_time real mem = 4185079808 (3991MB) avail mem = 4065439744 (3877MB) mainbus0 at root bios0 at mainbus0: SMBIOS rev. 2.4 @ 0xe (53 entries) bios0: vendor Apple Inc. version MBA41.88Z.0077.B0F.1201241549 date 01/24/2012 bios0: Apple Inc. MacBookAir4,2 acpi0 at bios0: rev 2 acpi0: sleep states S0 S3 S4 S5 acpi0: tables DSDT FACP HPET APIC SBST ECDT SSDT SSDT SSDT SSDT SSDT SSDT SSDT SSDT MCFG SSDT SSDT SSDT acpi0: wakeup devices P0P2(S4) EC__(S4) HDEF(S4) ARPT(S4) RP02(S4) EHC1(S3) EHC2(S3) ADP1(S4) LID0(S4) acpitimer0 at acpi0: 3579545 Hz, 24 bits acpihpet0 at acpi0: 14318179 Hz acpimadt0 at acpi0 addr 0xfee0: PC-AT compat cpu0 at mainbus0: apid 0 (boot processor) cpu0: Intel(R) Core(TM) i7-2677M CPU @ 1.80GHz, 1800.30 MHz cpu0: FPU,VME,DE,PSE,TSC,MSR,PAE,MCE,CX8,APIC,SEP,MTRR,PGE,MCA,CMOV,PAT,PSE36,CFLUSH,DS,ACPI,MMX,FXSR,SSE,SSE2,SS,HTT,TM,PBE,SSE3,PCLMUL,DTES64,MWAIT,DS-CPL,VMX,SMX,EST,TM2,SSSE3,CX16,xTPR,PDCM,PCID,SSE4.1,SSE4.2,x2APIC,POPCNT,DEADLINE,AES,XSAVE,AVX,NXE,LONG,LAHF,PERF,ITSC cpu0: 256KB 64b/line 8-way L2 cache cpu0: smt 0, core 0, package 0 mtrr: Pentium Pro MTRR support, 10 var ranges, 88 fixed ranges cpu0: apic clock running at 100MHz cpu0: mwait min=64, max=64, C-substates=0.2.1.1.2, IBE cpu1 at mainbus0: apid 2 (application processor) cpu1: Intel(R) Core(TM) i7-2677M CPU @ 1.80GHz, 1800.02 MHz cpu1: FPU,VME,DE,PSE,TSC,MSR,PAE,MCE,CX8,APIC,SEP,MTRR,PGE,MCA,CMOV,PAT,PSE36,CFLUSH,DS,ACPI,MMX,FXSR,SSE,SSE2,SS,HTT,TM,PBE,SSE3,PCLMUL,DTES64,MWAIT,DS-CPL,VMX,SMX,EST,TM2,SSSE3,CX16,xTPR,PDCM,PCID,SSE4.1,SSE4.2,x2APIC,POPCNT,DEADLINE,AES,XSAVE,AVX,NXE,LONG,LAHF,PERF,ITSC cpu1: 256KB 64b/line 8-way L2 cache cpu1: smt 0, core 1, package 0 cpu2 at mainbus0: apid 1 (application processor) cpu2: Intel(R) Core(TM) i7-2677M CPU @ 1.80GHz, 1800.02 MHz cpu2:
Apple SMC chip - driver to read sensors and temperatures
Hi all running OpenBSD on Apple hardware: I was working on the asmc kernel driver for the Macbooks. I have a MBPro8.2 (mid 2011), and came to get the driver installed, reading all sensors and temperatures into the hw.sensors framework. See attached diffs. Beginning line 30 I describe the ideas for the driver. Further information available, also a todo list. Thx to Joshua@, who helped me to create the diffs below, and provided input for the todo list. Looking forward to get some feedback, especially on other Apple hardware. rgds, Volker Index: dev/isa/asmc.c === RCS file: dev/isa/asmc.c diff -N dev/isa/asmc.c --- /dev/null 1 Jan 1970 00:00:00 - +++ dev/isa/asmc.c 24 Jan 2014 20:24:38 - @@ -0,0 +1,1317 @@ +/* $OpenBSD: asmc.c,v 0.1 2014/01/14 15:47:16 volker $ */ +/* + * Copyright (c) 2013, 2014 Volker Nowarra + * Complete rewrite of code in Nov/Dec 2013 from following sources: + * + * MACOSX: + * SmcFanControl.m by Hendrik Holtmann + * SmcCommand.c (no reference) + * FREEBSD driver by Rui Paulo rpa...@freebsd.org + * LINUX driver by Nicolas Boichat nico...@boichat.ch and + *Henrik Rydberg rydb...@euromail.se + * and the OpenBSD aps.c driver by Jonathan Gray j...@openbsd.org and + *Can Erkin Acar cana...@openbsd.org + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED AS IS AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +/* + * Driver for Apple's System Management Console (SMC). SMC can be found + * on the MacBook, MacBook Pro and Mac Mini, and possibly others ... + * + * Idea is to match / attach into the kernel, as defined in man 8 config, + * section EXAMPLES (kernel building). The function asmc_match() would + * read the BIOS, compare it to a defined model in *asmc_models[], and + * if match, returns success. The asmc_attach() function would do the + * man 9 bus_space handling, and call on success asmc_init(). + * asmc_init() tries to talk to the SMC chip, and if success prepares + * the sensors framework (sysctl hw), and sets up the the calls to + * the SMC chip to readsensor values. The Apple SMC has read and write + * areas, usually 10 read only values for FANs, 2 values for reading + * backlit, and 3 for motion sensors (SMS). + * Values can be written to change the FAN speeds. The different Apple + * Macs provide up to 36 temperatur sensors ! + * + * Main driver for this development was reduction of code size into kernel, + * two binary integers are used for the sensors and temps. This way code + * size was reduced from 50KB down to 25KB, and to 15KB on i386. + * Details see struct asmc_model. + */ + +/* + * man style says, either param.h or types.h, but not both ! + */ +#include sys/param.h +#include sys/systm.h +#include sys/device.h +#include sys/kernel.h +#include sys/limits.h +#include sys/sensors.h +#include sys/timeout.h +#include sys/types.h +#include sys/event.h + +#include dev/isa/isareg.h +#include dev/isa/isavar.h + +#include machine/apmvar.h +#include machine/biosvar.h +#include machine/bus.h +#include machine/smbiosvar.h + + +#define ASMCDEBUG +#if defined(ASMCDEBUG) +#define DPRINTF(x) do { printf x; } while (0) +#else +#define DPRINTF(x) +#endif + +/* ASMC DETAILED DEBUG :-) */ +#define XSMCDDEBUG +#if defined(ASMCDDEBUG) +#define DDPRINTF(x)do { printf x; } while (0) +#else +#define DDPRINTF(x) +#endif + + +/* + * Observed values, partially from Linux and FreeBSD driver + * data and command/status port used by Apple SMC + */ + +#define ASMC_DATAPORT_OFFSET 0x00 +#define ASMC_CMDPORT_OFFSET0x04 +#define ASMC_ADDR_SIZE 0x1f +#define ASMC_MAX_DATA_LENGTH 32 /* 0x300-0x31f */ + +/* + * Interrupt port + */ +#define ASMC_INTPORT_READ()bus_space_read_1(0x300, 0x00, ASMC_ADDR_SIZE) + +/* + * SMC command modes + */ +#define ASMC_READ_CMD 0x10 +#define ASMC_WRITE_CMD 0x11 +#define ASMC_GETKEYBYINDEX_CMD 0x12 +#define ASMC_GETKEYBYTYPE_CMD 0x13 + +/* + * Timings + */ +#define ASMC_MIN_WAIT 0x0010 +#define ASMC_MAX_WAIT 0x8000 +#define ASMC_RETRY_WAIT0x0400 +#define ASMC_REFRESH_RATE 7 /* in seconds */ + +/* + * status from SMC chip + */ +#define ASMC_STATUS_02 0x02 +#define