#!/bin/sh

# Copyright 2015,2016 Cumulus Networks, Inc.
# All rights reserved

# amd64 architecture initramfs-tools script.
#
# This script is run *before* the common "cumulus-top" script to
# arrange things specific for this CPU architecture.

PREREQ=""

prereqs()
{
	echo "$PREREQ"
}

case $1 in
# get pre-requisites
prereqs)
	prereqs
	exit 0
	;;
esac

# Parse kernel command line options for cl_platform
for x in $(cat /proc/cmdline); do
    parm=${x%%=*}
    val=${x#*=}
    case $parm in
	cl_platform)
            cl_platform="$val"
            break
            ;;
    esac
done

if [ $cl_platform = 'quanta_ly8_rangeley' ] || [ $cl_platform = 'quanta_ly6_rangeley' ] || \
    [ $cl_platform = 'quanta_ly9_rangeley' ]; then
    # Quanta LY8/LY6/LY9 use an external RTC present on the I2C bus.
    # Start using this instead of built-in SOC RTC as soon as you can.
    echo ds1339 0x68 > /sys/bus/i2c/devices/i2c-0/new_device
    # instantiating the device and /dev/rtc1 takes time.
    sleep 1
    # Set system time from RTC1
    hwclock -f /dev/rtc1 -s --utc
fi
