/* Copyright 2021 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.
 */

#include "common.h"
#include "sku.h"
#include "system.h"
#include "usbc_ppc.h"

void board_hibernate(void)
{
	int i;

	if (!board_is_clamshell()) {
		/*
		 * Sensors are unpowered in hibernate. Apply PD to the
		 * interrupt lines such that they don't float.
		 */
		gpio_set_flags(GPIO_ACCEL_GYRO_INT_L,
			       GPIO_INPUT | GPIO_PULL_DOWN);
		gpio_set_flags(GPIO_LID_ACCEL_INT_L,
			       GPIO_INPUT | GPIO_PULL_DOWN);
	}

	/*
	 * Board rev 5+ has the hardware fix. Don't need the following
	 * workaround. Limozeen's BRD_ID is not monotonically increasing.
         * 4 is the earliest revision.
	 */
	if ((system_get_board_version() >= 5) ||
		(board_is_clamshell() && ((system_get_board_version() != 4))))
		return;

	/*
	 * Enable the PPC power sink path before EC enters hibernate;
	 * otherwise, ACOK won't go High and can't wake EC up. Check the
	 * bug b/170324206 for details.
	 */
	for (i = 0; i < CONFIG_USB_PD_PORT_MAX_COUNT; i++)
		ppc_vbus_sink_enable(i, 1);
}

/* Copyright 2021 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.
 */

#include "common.h"
#include "sku.h"
#include "system.h"
#include "usbc_ppc.h"

void board_hibernate(void)
{
	int i;

	if (!board_is_clamshell()) {
		/*
		 * Sensors are unpowered in hibernate. Apply PD to the
		 * interrupt lines such that they don't float.
		 */
		gpio_set_flags(GPIO_ACCEL_GYRO_INT_L,
			       GPIO_INPUT | GPIO_PULL_DOWN);
		gpio_set_flags(GPIO_LID_ACCEL_INT_L,
			       GPIO_INPUT | GPIO_PULL_DOWN);
	}

	/*
	 * Board rev 5+ has the hardware fix. Don't need the following
	 * workaround.
	 */
	if (system_get_board_version() >= 5)
		return;

	/*
	 * Enable the PPC power sink path before EC enters hibernate;
	 * otherwise, ACOK won't go High and can't wake EC up. Check the
	 * bug b/170324206 for details.
	 */
	for (i = 0; i < CONFIG_USB_PD_PORT_MAX_COUNT; i++)
		ppc_vbus_sink_enable(i, 1);
}

Revert "limozeen: Refine the BRD_ID check"
Revert "limozeen: Refine the BRD_ID check"

This reverts commit 4860dccf9a0ea7c5ecba92d984491bd7151a31f0.

Reason for revert: lomozeen pvt buck ic board version change to 8.

Original change's description:
> limozeen: Refine the BRD_ID check
>
> Limozeen's BRD_ID is not monotonically increasing.
> The earliest revision is 4. The next BRD_ID after 7 is 0.
> Not support PPC workaround when BRD_ID 0 on limozeen.
>
> BUG=b:190250108
> BRANCH=trogdor
> TEST=make buildall success.
>
> Signed-off-by: David Huang <0bee89a4ff99f17b7e64fbf6530169dc03ff1a24@quanta.corp-partner.google.com>
> Change-Id: I16d7ff081306812c14aa31ce2b19af8e2d50ff76
> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2952802
> Reviewed-by: Wai-Hong Tam <04b587fdf5845741a0c5a8b9cd59ca72d73ef8fc@google.com>
> Commit-Queue: Wai-Hong Tam <04b587fdf5845741a0c5a8b9cd59ca72d73ef8fc@google.com>

Bug: b:190250108
Change-Id: Ib15e4d0b7b783c86541775955d5b74c51f2bbce2
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2965811
Bot-Commit: Rubber Stamper <d516c4cc2192058ab8dae3d306acbdaf2ce6574f@appspot.gserviceaccount.com>
Auto-Submit: David Huang <0bee89a4ff99f17b7e64fbf6530169dc03ff1a24@quanta.corp-partner.google.com>
Commit-Queue: Wai-Hong Tam <04b587fdf5845741a0c5a8b9cd59ca72d73ef8fc@google.com>
