ec/google/chromeec: provide reboot function

Provide a common function to issue reboot commands to the EC.
Expose that function for external use and use it internal to
the module.

BUG=b:35580805

Change-Id: I1458bd7119b0df626a043ff3806c15ffb5446c9a
Signed-off-by: Aaron Durbin <adurbin@chromium.org>
Reviewed-on: https://review.coreboot.org/19573
Reviewed-by: Furquan Shaikh <furquan@google.com>
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Vadim Bendebury <vbendeb@chromium.org>
This commit is contained in:
Aaron Durbin 2017-05-04 12:32:52 -05:00
parent 44526cd1fc
commit e68d22fbbc
2 changed files with 27 additions and 30 deletions

View File

@ -202,6 +202,26 @@ int rtc_get(struct rtc_time *time)
} }
#endif #endif
int google_chromeec_reboot(int dev_idx, enum ec_reboot_cmd type, uint8_t flags)
{
struct ec_params_reboot_ec reboot_ec = {
.cmd = type,
.flags = flags,
};
struct ec_response_get_version cec_resp = { };
struct chromeec_command cec_cmd = {
.cmd_code = EC_CMD_REBOOT_EC,
.cmd_version = 0,
.cmd_data_in = &reboot_ec,
.cmd_data_out = &cec_resp,
.cmd_size_in = sizeof(reboot_ec),
.cmd_size_out = 0, /* ignore response, if any */
.cmd_dev_index = dev_idx,
};
return google_chromeec_command(&cec_cmd);
}
#ifndef __SMM__ #ifndef __SMM__
#ifdef __PRE_RAM__ #ifdef __PRE_RAM__
void google_chromeec_check_ec_image(int expected_type) void google_chromeec_check_ec_image(int expected_type)
@ -218,22 +238,13 @@ void google_chromeec_check_ec_image(int expected_type)
google_chromeec_command(&cec_cmd); google_chromeec_command(&cec_cmd);
if (cec_cmd.cmd_code || cec_resp.current_image != expected_type) { if (cec_cmd.cmd_code || cec_resp.current_image != expected_type) {
struct ec_params_reboot_ec reboot_ec;
/* Reboot the EC and make it come back in RO mode */ /* Reboot the EC and make it come back in RO mode */
reboot_ec.cmd = EC_REBOOT_COLD;
reboot_ec.flags = 0;
cec_cmd.cmd_code = EC_CMD_REBOOT_EC;
cec_cmd.cmd_version = 0;
cec_cmd.cmd_data_in = &reboot_ec;
cec_cmd.cmd_size_in = sizeof(reboot_ec);
cec_cmd.cmd_size_out = 0; /* ignore response, if any */
cec_cmd.cmd_dev_index = 0;
printk(BIOS_DEBUG, "Rebooting with EC in RO mode:\n"); printk(BIOS_DEBUG, "Rebooting with EC in RO mode:\n");
post_code(0); /* clear current post code */ post_code(0); /* clear current post code */
/* Let the platform prepare for the EC taking out the system power. */ /* Let the platform prepare for the EC taking out the system power. */
if (IS_ENABLED(CONFIG_VBOOT)) if (IS_ENABLED(CONFIG_VBOOT))
vboot_platform_prepare_reboot(); vboot_platform_prepare_reboot();
google_chromeec_command(&cec_cmd); google_chromeec_reboot(0, EC_REBOOT_COLD, 0);
udelay(1000); udelay(1000);
hard_reset(); hard_reset();
halt(); halt();
@ -268,18 +279,9 @@ void google_chromeec_check_pd_image(int expected_type)
google_chromeec_command(&cec_cmd); google_chromeec_command(&cec_cmd);
if (cec_cmd.cmd_code || cec_resp.current_image != expected_type) { if (cec_cmd.cmd_code || cec_resp.current_image != expected_type) {
struct ec_params_reboot_ec reboot_ec;
/* Reboot the PD and make it come back in RO mode */ /* Reboot the PD and make it come back in RO mode */
reboot_ec.cmd = EC_REBOOT_COLD;
reboot_ec.flags = 0;
cec_cmd.cmd_code = EC_CMD_REBOOT_EC;
cec_cmd.cmd_version = 0;
cec_cmd.cmd_data_in = &reboot_ec;
cec_cmd.cmd_size_in = sizeof(reboot_ec);
cec_cmd.cmd_size_out = 0; /* ignore response, if any */
cec_cmd.cmd_dev_index = 1; /* PD */
printk(BIOS_DEBUG, "Rebooting PD to RO mode\n"); printk(BIOS_DEBUG, "Rebooting PD to RO mode\n");
google_chromeec_command(&cec_cmd); google_chromeec_reboot(1 /* PD */, EC_REBOOT_COLD, 0);
udelay(1000); udelay(1000);
} }
} }
@ -578,19 +580,10 @@ void google_chromeec_init(void)
if (cec_cmd.cmd_code || if (cec_cmd.cmd_code ||
(vboot_recovery_mode_enabled() && (vboot_recovery_mode_enabled() &&
(cec_resp.current_image != EC_IMAGE_RO))) { (cec_resp.current_image != EC_IMAGE_RO))) {
struct ec_params_reboot_ec reboot_ec;
/* Reboot the EC and make it come back in RO mode */ /* Reboot the EC and make it come back in RO mode */
reboot_ec.cmd = EC_REBOOT_COLD;
reboot_ec.flags = 0;
cec_cmd.cmd_code = EC_CMD_REBOOT_EC;
cec_cmd.cmd_version = 0;
cec_cmd.cmd_data_in = &reboot_ec;
cec_cmd.cmd_size_in = sizeof(reboot_ec);
cec_cmd.cmd_size_out = 0; /* ignore response, if any */
cec_cmd.cmd_dev_index = 0;
printk(BIOS_DEBUG, "Rebooting with EC in RO mode:\n"); printk(BIOS_DEBUG, "Rebooting with EC in RO mode:\n");
post_code(0); /* clear current post code */ post_code(0); /* clear current post code */
google_chromeec_command(&cec_cmd); google_chromeec_reboot(0, EC_REBOOT_COLD, 0);
udelay(1000); udelay(1000);
hard_reset(); hard_reset();
halt(); halt();

View File

@ -57,6 +57,10 @@ int google_chromeec_vstore_info(uint32_t *locked);
int google_chromeec_vstore_read(int slot, uint8_t *data); int google_chromeec_vstore_read(int slot, uint8_t *data);
int google_chromeec_vstore_write(int slot, uint8_t *data, size_t size); int google_chromeec_vstore_write(int slot, uint8_t *data, size_t size);
/* Issue reboot command to EC with specified type and flags. Returns 0 on
success, < 0 otherwise. */
int google_chromeec_reboot(int dev_idx, enum ec_reboot_cmd type, uint8_t flags);
/* MEC uses 0x800/0x804 as register/index pair, thus an 8-byte resource. */ /* MEC uses 0x800/0x804 as register/index pair, thus an 8-byte resource. */
#define MEC_EMI_BASE 0x800 #define MEC_EMI_BASE 0x800
#define MEC_EMI_SIZE 8 #define MEC_EMI_SIZE 8