wspoon: Enable fan control to run at BMC standby

To allow thermal modes to be selected at BMC standby, the fan control
application must be running. The phosphor-fan-control@.service file is
needed to start fan control at BMC standby and the
phosphor-fan-control-init@.service is no longer required.

Tested:
    Witherspoon phosphor-fan-control@.service replaced in image
    phosphor-fan-control-init@.service removed from image
    fan watchdog configs appended to fan control service still
    phosphor-fan-control@.service started at BMC standby
    fan control thermal modes presented/changeable at BMC standby
    no function change in configured thermal modes

(From meta-ibm rev: f59761e1af85b3ae6432bf0297f5cfe5be71e557)

Change-Id: I4a946f58b6f0c22ebd402304ae9d8fd17a197571
Signed-off-by: Matthew Barth <msbarth@us.ibm.com>
Signed-off-by: Brad Bishop <bradleyb@fuzziesquirrel.com>
diff --git a/meta-ibm/meta-witherspoon/recipes-phosphor/fans/phosphor-fan/witherspoon/phosphor-fan-control@.service b/meta-ibm/meta-witherspoon/recipes-phosphor/fans/phosphor-fan/witherspoon/phosphor-fan-control@.service
new file mode 100644
index 0000000..489292b
--- /dev/null
+++ b/meta-ibm/meta-witherspoon/recipes-phosphor/fans/phosphor-fan/witherspoon/phosphor-fan-control@.service
@@ -0,0 +1,11 @@
+[Unit]
+Description=Phosphor Fan Control Daemon
+Requires=max31785-hwmon-helper@ahb-apb-bus\x401e78a000-i2c\x2dbus\x40100-max31785\x4052.service
+After=max31785-hwmon-helper@ahb-apb-bus\x401e78a000-i2c\x2dbus\x40100-max31785\x4052.service
+
+[Service]
+Restart=on-failure
+ExecStart=/usr/bin/phosphor-fan-control --control
+
+[Install]
+RequiredBy=obmc-chassis-poweron@%i.target
diff --git a/meta-ibm/meta-witherspoon/recipes-phosphor/fans/phosphor-fan_%.bbappend b/meta-ibm/meta-witherspoon/recipes-phosphor/fans/phosphor-fan_%.bbappend
index 085857c..243a02f 100644
--- a/meta-ibm/meta-witherspoon/recipes-phosphor/fans/phosphor-fan_%.bbappend
+++ b/meta-ibm/meta-witherspoon/recipes-phosphor/fans/phosphor-fan_%.bbappend
@@ -14,8 +14,8 @@
 
 TMPL_COOLING = "phosphor-cooling-type@.service"
 INSTFMT_COOLING = "phosphor-cooling-type@{0}.service"
-COOLING_TGT = "multi-user.target"
-FMT_COOLING = "../${TMPL_COOLING}:${COOLING_TGT}.requires/${INSTFMT_COOLING}"
+MULTI_USR_TGT = "multi-user.target"
+FMT_COOLING = "../${TMPL_COOLING}:${MULTI_USR_TGT}.requires/${INSTFMT_COOLING}"
 
 FILES_phosphor-cooling-type_append_ibm-ac-server = " ${bindir}/phosphor-cooling-type"
 SYSTEMD_SERVICE_phosphor-cooling-type_append_ibm-ac-server = " ${TMPL_COOLING}"
@@ -30,7 +30,6 @@
 SYSTEMD_ENVIRONMENT_FILE_phosphor-cooling-type_append_mihawk = " ${@compose_list(d, 'COOLING_ENV_FMT', 'OBMC_CHASSIS_INSTANCES')}"
 
 #These services are protected by the watchdog
-SYSTEMD_OVERRIDE_phosphor-fan-control_witherspoon += "fan-watchdog-monitor.conf:phosphor-fan-control-init@0.service.d/fan-watchdog-monitor.conf"
 SYSTEMD_OVERRIDE_phosphor-fan-control_witherspoon += "fan-watchdog-monitor.conf:phosphor-fan-control@0.service.d/fan-watchdog-monitor.conf"
 SYSTEMD_OVERRIDE_phosphor-fan-monitor_witherspoon += "fan-watchdog-monitor.conf:phosphor-fan-monitor-init@0.service.d/fan-watchdog-monitor.conf"
 SYSTEMD_OVERRIDE_phosphor-fan-monitor_witherspoon += "fan-watchdog-monitor.conf:phosphor-fan-monitor@0.service.d/fan-watchdog-monitor.conf"
@@ -38,3 +37,16 @@
 #These services need to be stopped when watchdog expires
 SYSTEMD_OVERRIDE_phosphor-fan-control_witherspoon += "fan-watchdog-conflicts.conf:phosphor-fan-control@0.service.d/fan-watchdog-conflicts.conf"
 SYSTEMD_OVERRIDE_phosphor-fan-monitor_witherspoon += "fan-watchdog-conflicts.conf:phosphor-fan-monitor@0.service.d/fan-watchdog-conflicts.conf"
+
+# Remove fan control init service completely
+SYSTEMD_SERVICE_${PN}-control_remove_witherspoon = "${TMPL_CONTROL_INIT}"
+SYSTEMD_LINK_${PN}-control_remove_witherspoon = "${@compose_list(d, 'FMT_CONTROL_INIT', 'OBMC_CHASSIS_INSTANCES')}"
+# Remove fan control from being linked
+SYSTEMD_LINK_${PN}-control_remove_witherspoon = "${@compose_list(d, 'FMT_CONTROL', 'OBMC_CHASSIS_INSTANCES')}"
+
+# Link fan control service to be started at standby
+FMT_CONTROL_STDBY_witherspoon = "../${TMPL_CONTROL}:${MULTI_USR_TGT}.wants/${INSTFMT_CONTROL}"
+SYSTEMD_LINK_${PN}-control_witherspoon += "${@compose_list(d, 'FMT_CONTROL_STDBY', 'OBMC_CHASSIS_INSTANCES')}"
+# Link fan control service to also start at poweron
+FMT_CONTROL_PWRON_witherspoon = "../${TMPL_CONTROL}:${POWERON_TGT}.requires/${INSTFMT_CONTROL}"
+SYSTEMD_LINK_${PN}-control_witherspoon += "${@compose_list(d, 'FMT_CONTROL_PWRON', 'OBMC_CHASSIS_INSTANCES')}"
diff --git a/meta-ibm/meta-witherspoon/recipes-phosphor/fans/witherspoon-fan-watchdog/witherspoon-fan-watchdog.service b/meta-ibm/meta-witherspoon/recipes-phosphor/fans/witherspoon-fan-watchdog/witherspoon-fan-watchdog.service
index 5b59546..597ee03 100644
--- a/meta-ibm/meta-witherspoon/recipes-phosphor/fans/witherspoon-fan-watchdog/witherspoon-fan-watchdog.service
+++ b/meta-ibm/meta-witherspoon/recipes-phosphor/fans/witherspoon-fan-watchdog/witherspoon-fan-watchdog.service
@@ -1,7 +1,7 @@
 [Unit]
 Description=Witherspoon Fan Watchdog Daemon
-Wants=phosphor-fan-control-init@0.service
-Before=phosphor-fan-control-init@0.service
+Wants=phosphor-fan-monitor-init@0.service
+Before=phosphor-fan-monitor-init@0.service
 Conflicts=obmc-fan-watchdog-takeover.target
 
 [Service]
diff --git a/meta-ibm/meta-witherspoon/recipes-phosphor/fans/witherspoon-fan-watchdog/witherspoon-reset-fan-watchdog.service b/meta-ibm/meta-witherspoon/recipes-phosphor/fans/witherspoon-fan-watchdog/witherspoon-reset-fan-watchdog.service
index e0ef0ae..675a672 100644
--- a/meta-ibm/meta-witherspoon/recipes-phosphor/fans/witherspoon-fan-watchdog/witherspoon-reset-fan-watchdog.service
+++ b/meta-ibm/meta-witherspoon/recipes-phosphor/fans/witherspoon-fan-watchdog/witherspoon-reset-fan-watchdog.service
@@ -1,7 +1,7 @@
 [Unit]
 Description=Witherspoon Fan Watchdog Reset
-Wants=phosphor-fan-control-init@0.service
-Before=phosphor-fan-control-init@0.service
+Wants=phosphor-fan-monitor-init@0.service
+Before=phosphor-fan-monitor-init@0.service
 Conflicts=obmc-chassis-poweroff@0.target
 
 [Service]