diff options
Diffstat (limited to 'meta-facebook/meta-yosemite/recipes-yosemite/fan-ctrl')
5 files changed, 296 insertions, 0 deletions
diff --git a/meta-facebook/meta-yosemite/recipes-yosemite/fan-ctrl/fan-ctrl/get_fan_speed.sh b/meta-facebook/meta-yosemite/recipes-yosemite/fan-ctrl/fan-ctrl/get_fan_speed.sh new file mode 100755 index 0000000..c77c6f0 --- /dev/null +++ b/meta-facebook/meta-yosemite/recipes-yosemite/fan-ctrl/fan-ctrl/get_fan_speed.sh @@ -0,0 +1,53 @@ +#!/bin/sh +# +# Copyright 2015-present Facebook. All Rights Reserved. +# +# This program file is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by the +# Free Software Foundation; version 2 of the License. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +# for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program in a file named COPYING; if not, write to the +# Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, +# Boston, MA 02110-1301 USA +# +usage() { + echo "Usage: $0 [Fan Unit (0..1)]" >&2 +} + +PWM_DIR=/sys/devices/platform/ast_pwm_tacho.0 +set -e + +# refer to the comments in init_pwn.sh regarding +# the fan unit and tacho mapping +if [ "$#" -eq 0 ]; then + TACHOS="0:0 1:1" +elif [ "$#" -eq 1 ]; then + case "$1" in + "0") + TACHOS="0:0" + ;; + "1") + TACHOS="1:1" + ;; + *) + usage + exit 1 + ;; + esac +else + usage + exit 1 +fi + +for fan_tacho in $TACHOS; do + fan=${fan_tacho%%:*} + tacho=${fan_tacho##*:} + echo "Fan $fan RPM: $(cat $PWM_DIR/tacho${tacho}_rpm)" +done diff --git a/meta-facebook/meta-yosemite/recipes-yosemite/fan-ctrl/fan-ctrl/init_pwm.sh b/meta-facebook/meta-yosemite/recipes-yosemite/fan-ctrl/fan-ctrl/init_pwm.sh new file mode 100755 index 0000000..8c8adc6 --- /dev/null +++ b/meta-facebook/meta-yosemite/recipes-yosemite/fan-ctrl/fan-ctrl/init_pwm.sh @@ -0,0 +1,64 @@ +#!/bin/sh +# +# Copyright 2015-present Facebook. All Rights Reserved. +# +# This program file is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by the +# Free Software Foundation; version 2 of the License. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +# for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program in a file named COPYING; if not, write to the +# Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, +# Boston, MA 02110-1301 USA +# +PWM_DIR=/sys/devices/platform/ast_pwm_tacho.0 + +set -e + +# The PWM frequency is + +# clk_source / ((2 ^ division_) * (2 * division_l) * (unit + 1)) +# +# Our clk_source is 24Mhz. 4-pin fans are generally supposed to be driven with +# a 25Khz PWM control signal. Therefore we want the divisor to equal 960. +# +# We also want the unit to be as large as possible, since this controls the +# granularity with which we can modulate the PWM signal. The following +# settings allow us to set the fan from 0 to 100% in increments of 1/96th. +# +# The AST chip supports 3 different PWM clock configurations, but we only use +# type M for now. +echo 0 > $PWM_DIR/pwm_type_m_division_h +echo 5 > $PWM_DIR/pwm_type_m_division_l +echo 95 > $PWM_DIR/pwm_type_m_unit + +# On Yosemite, there are 2 fans connected. +# Each fan uses same PWM input and provide one tacho output. +# Here is the mapping between the fan and PWN/Tacho, +# staring from the one from the edge +# Fan 0: PWM 0, Tacho0 +# Fan 1: PWM 0, Tacho1 + +# For each fan, setting the type, and 100% initially +for pwm in 0 1; do + echo 0 > $PWM_DIR/pwm${pwm}_type + echo 0 > $PWM_DIR/pwm${pwm}_rising + echo 0 > $PWM_DIR/pwm${pwm}_falling + echo 1 > $PWM_DIR/pwm${pwm}_en +done + +# Enable Tach 0..1 +echo 0 > $PWM_DIR/tacho0_source +echo 1 > $PWM_DIR/tacho1_source + +t=0 +while [ $t -le 1 ]; do + echo 1 > $PWM_DIR/tacho${t}_en + t=$((t+1)) +done diff --git a/meta-facebook/meta-yosemite/recipes-yosemite/fan-ctrl/fan-ctrl/set_fan_speed.sh b/meta-facebook/meta-yosemite/recipes-yosemite/fan-ctrl/fan-ctrl/set_fan_speed.sh new file mode 100755 index 0000000..49ef55b --- /dev/null +++ b/meta-facebook/meta-yosemite/recipes-yosemite/fan-ctrl/fan-ctrl/set_fan_speed.sh @@ -0,0 +1,79 @@ +#!/bin/sh +# +# Copyright 2004-present Facebook. All Rights Reserved. +# +# This program file is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by the +# Free Software Foundation; version 2 of the License. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +# for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program in a file named COPYING; if not, write to the +# Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, +# Boston, MA 02110-1301 USA +# +usage() { + echo "Usage: $0 <PERCENT (0..100)> <Fan Unit (0..1)> " >&2 +} + +PWM_DIR=/sys/devices/platform/ast_pwm_tacho.0 + +# The maximum unit setting. +# This should be the value in pwm_type_m_unit plus 1 +PWM_UNIT_MAX=96 + +set -e + +if [ "$#" -ne 2 ] && [ "$#" -ne 1 ]; then + usage + exit 1 +fi + +# refer to the comments in init_pwn.sh regarding +# the fan unit and PWM mapping +if [ "$#" -eq 1 ]; then + PWMS="0:0 1:0" +else + case "$2" in + "0") + PWMS="0:0" + ;; + "1") + PWMS="1:0" + ;; + *) + usage + exit 1 + ;; + esac +fi + +# Convert the percentage to our 1/96th unit. +unit=$(( ( $1 * $PWM_UNIT_MAX ) / 100 )) + +for FAN_PWM in $PWMS; do + FAN_N=${FAN_PWM%%:*} + PWM_N=${FAN_PWM##*:} + if [ "$unit" -eq 0 ]; then + # For 0%, turn off the PWM entirely + echo 0 > $PWM_DIR/pwm${PWM_N}_en + else + if [ "$unit" -eq $PWM_UNIT_MAX ]; then + # For 100%, set falling and rising to the same value + unit=0 + fi + + # always use type M. refer to the comments in init_pwm.sh + echo 0 > $PWM_DIR/pwm${PWM_N}_type + echo 0 > $PWM_DIR/pwm${PWM_N}_rising + echo "$unit" > $PWM_DIR/pwm${PWM_N}_falling + echo 1 > $PWM_DIR/pwm${PWM_N}_en + fi + + echo "Successfully set fan ${FAN_N} (PWM: $PWM_N) speed to $1%" +done diff --git a/meta-facebook/meta-yosemite/recipes-yosemite/fan-ctrl/fan-ctrl/setup-fan.sh b/meta-facebook/meta-yosemite/recipes-yosemite/fan-ctrl/fan-ctrl/setup-fan.sh new file mode 100644 index 0000000..72016d0 --- /dev/null +++ b/meta-facebook/meta-yosemite/recipes-yosemite/fan-ctrl/fan-ctrl/setup-fan.sh @@ -0,0 +1,36 @@ +#!/bin/sh +# +# Copyright 2015-present Facebook. All Rights Reserved. +# +# This program file is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by the +# Free Software Foundation; version 2 of the License. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +# for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program in a file named COPYING; if not, write to the +# Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, +# Boston, MA 02110-1301 USA +# + +### BEGIN INIT INFO +# Provides: setup-fan +# Required-Start: board-id +# Required-Stop: +# Default-Start: S +# Default-Stop: +# Short-Description: Set fan speed +### END INIT INFO + +. /usr/local/fbpackages/utils/ast-functions + +echo -n "Setup fan speed... " +/usr/local/bin/init_pwm.sh +/usr/local/bin/set_fan_speed.sh 50 +/usr/local/bin/fand +echo "done." diff --git a/meta-facebook/meta-yosemite/recipes-yosemite/fan-ctrl/fan-ctrl_0.1.bbappend b/meta-facebook/meta-yosemite/recipes-yosemite/fan-ctrl/fan-ctrl_0.1.bbappend new file mode 100644 index 0000000..d5659ae --- /dev/null +++ b/meta-facebook/meta-yosemite/recipes-yosemite/fan-ctrl/fan-ctrl_0.1.bbappend @@ -0,0 +1,64 @@ +# Copyright 2014-present Facebook. All Rights Reserved. +# +# This program file is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by the +# Free Software Foundation; version 2 of the License. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +# for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program in a file named COPYING; if not, write to the +# Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, +# Boston, MA 02110-1301 USA + +DEPENDS_append = "update-rc.d-native libyosemite-sensor" + +FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:" +SRC_URI += "file://get_fan_speed.sh \ + file://init_pwm.sh \ + file://set_fan_speed.sh \ + file://setup-fan.sh \ + " + +S = "${WORKDIR}" + +binfiles += "get_fan_speed.sh \ + init_pwm.sh \ + set_fan_speed.sh \ + " + +CXXFLAGS_prepend = "-DCONFIG_YOSEMITE " +LDFLAGS_append = " -lyosemite_sensor" + +pkgdir = "fan_ctrl" + +do_install() { + dst="${D}/usr/local/fbpackages/${pkgdir}" + bin="${D}/usr/local/bin" + install -d $dst + install -d $bin + for f in ${binfiles}; do + install -m 755 $f ${dst}/$f + ln -snf ../fbpackages/${pkgdir}/$f ${bin}/$f + done + for f in ${otherfiles}; do + install -m 644 $f ${dst}/$f + done + install -d ${D}${sysconfdir}/init.d + install -d ${D}${sysconfdir}/rcS.d + install -m 755 setup-fan.sh ${D}${sysconfdir}/init.d/setup-fan.sh + update-rc.d -r ${D} setup-fan.sh start 91 S . +} + +FBPACKAGEDIR = "${prefix}/local/fbpackages" + +FILES_${PN} = "${FBPACKAGEDIR}/fan_ctrl ${prefix}/local/bin ${sysconfdir} " + +# Inhibit complaints about .debug directories for the fand binary: + +INHIBIT_PACKAGE_DEBUG_SPLIT = "1" +INHIBIT_PACKAGE_STRIP = "1" |