blob: a85e6a0d6dd99f647caa5283f1ea99d8042cc1be [file] [log] [blame]
#!/bin/sh
# Copyright 2019 The Chromium OS Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
# This script configures link power management for sata devices. It is executed
# at boot time and whenever power is plugged or unplugged (through udev).
#
# When battery is plugged in and the device supports it, set link to min_power.
# On charger, use max_power, it improves latencies.
. /usr/share/misc/chromeos-common.sh
. /usr/sbin/write_gpt.sh
load_base_vars
if dump_power_status | grep -qF 'line_power_connected 1'; then
on_ac="1"
else
on_ac="0"
fi
drive="$(get_fixed_dst_drive)"
if [ -z "${drive}" ]; then
# Root device could not be located."
exit
fi
dev_sysfs="/sys/block/${drive##*/}"
dev_sysfs_full_path="/sys/block/$(readlink "${dev_sysfs}")"
link_pm_path_glob="$(echo "${dev_sysfs_full_path}" | \
sed 's|target.*|scsi_host/host*/link_power_management_policy|')"
# No "" inside, link_pm_path_glob has wildcard.
link_pm_path="$(echo ${link_pm_path_glob})"
if [ ! -f "${link_pm_path}" ]; then
# Older kernel, or the device is not a SATA device.
exit
fi
if [ "${on_ac}" = "1" ]; then
link_pm_policy="max_performance"
else
# Transcend SSD have issues with DLPM: b:115398975
if grep -q "TS.*MTS400" "${dev_sysfs}/device/model"; then
link_pm_policy="max_performance"
else
link_pm_policy="min_power"
fi
fi
echo "${link_pm_policy}" > "${link_pm_path}"