summarylogtreecommitdiffstats
path: root/intelpwm
blob: 2b843cbb2ed523b752a6d2313e240893cf34239a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#!/usr/bin/env bash

source /etc/intelpwm.conf 1>/dev/null 2>&1 || >&2 echo "WARN:  /etc/intelpwm.conf does not exit"


if [ -z "$FREQ" ]; then
  >&2 echo "ERROR: FREQ is not defined. Specify in /etc/intelpwm.conf or in environment"
  exit 1
fi

function reg_read() {
  # this assumes fixed position of the value in intel_reg output
  # so far this has been the case though
  intel_reg  read "$1" | cut -c51-60
}

PCH_FREQ="$(reg_read ${PCH_RAWCLK_FREQ_REG})"
BLC_CTL2="$(reg_read ${BLC_PWM_PCH_CTL2_REG})"
CYCLE="${BLC_CTL2:6:4}"
HEX=$(printf "0x%08x" $((1000000*PCH_FREQ/128/FREQ)))
PERIOD="${HEX:6:9}"

>&2 echo "Writing 0x${PERIOD}${CYCLE} to register ${BLC_PWM_PCH_CTL2_REG}"
intel_reg write "${BLC_PWM_PCH_CTL2_REG}" "0x${PERIOD}${CYCLE}"