Lee Leahy | 15843bd | 2016-05-15 15:05:56 -0700 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright (C) 2016 Intel Corp. |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; version 2 of the License. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied wacbmem_entryanty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | */ |
| 15 | |
| 16 | #define __SIMPLE_DEVICE__ |
| 17 | |
| 18 | #include <arch/io.h> |
| 19 | #include <console/console.h> |
| 20 | #include <device/i2c.h> |
| 21 | #include <soc/pci_devs.h> |
| 22 | #include <soc/reg_access.h> |
| 23 | #include "reg_access.h" |
| 24 | |
| 25 | #if ENV_RAMSTAGE |
| 26 | static uint64_t reg_read(struct reg_script_context *ctx) |
| 27 | { |
| 28 | int ret_code; |
| 29 | const struct reg_script *step; |
| 30 | uint8_t value = 0; |
| 31 | |
| 32 | step = ctx->step; |
| 33 | switch (step->id) { |
| 34 | default: |
| 35 | printk(BIOS_ERR, |
| 36 | "ERROR - Unknown register set (0x%08x)!\n", |
| 37 | step->id); |
| 38 | ctx->display_features = REG_SCRIPT_DISPLAY_NOTHING; |
| 39 | break; |
| 40 | |
| 41 | case GEN1_I2C_GPIO_EXP_0x20: |
| 42 | case GEN1_I2C_GPIO_EXP_0x21: |
| 43 | case GEN2_I2C_GPIO_EXP0: |
| 44 | case GEN2_I2C_GPIO_EXP1: |
| 45 | case GEN2_I2C_GPIO_EXP2: |
| 46 | case GEN2_I2C_LED_PWM: |
| 47 | if (ctx->display_features) |
| 48 | printk(BIOS_INFO, "I2C chip 0x%02x: ", step->id); |
| 49 | ret_code = i2c_readb(0, step->id, (UINT8)step->reg, &value); |
| 50 | ASSERT(ret_code == 2); |
| 51 | break; |
| 52 | } |
| 53 | return value; |
| 54 | } |
| 55 | |
| 56 | static void reg_write(struct reg_script_context *ctx) |
| 57 | { |
| 58 | int ret_code; |
| 59 | const struct reg_script *step; |
| 60 | uint8_t value; |
| 61 | |
| 62 | step = ctx->step; |
| 63 | switch (step->id) { |
| 64 | default: |
| 65 | printk(BIOS_ERR, |
| 66 | "ERROR - Unknown register set (0x%08x)!\n", |
| 67 | step->id); |
| 68 | ctx->display_features = REG_SCRIPT_DISPLAY_NOTHING; |
| 69 | break; |
| 70 | |
| 71 | case GEN1_I2C_GPIO_EXP_0x20: |
| 72 | case GEN1_I2C_GPIO_EXP_0x21: |
| 73 | case GEN2_I2C_GPIO_EXP0: |
| 74 | case GEN2_I2C_GPIO_EXP1: |
| 75 | case GEN2_I2C_GPIO_EXP2: |
| 76 | case GEN2_I2C_LED_PWM: |
| 77 | case RMU_TEMP_REGS: |
| 78 | if (ctx->display_features) |
| 79 | printk(BIOS_INFO, "I2C chip 0x%02x: ", step->id); |
| 80 | value = (UINT8)step->value; |
| 81 | ret_code = i2c_writeb(0, step->id, (UINT8)step->reg, value); |
| 82 | ASSERT(ret_code == 2); |
| 83 | break; |
| 84 | } |
| 85 | } |
| 86 | |
| 87 | const struct reg_script_bus_entry mainboard_reg_script_bus_table = { |
| 88 | MAINBOARD_TYPE, reg_read, reg_write |
| 89 | }; |
| 90 | |
| 91 | REG_SCRIPT_BUS_ENTRY(mainboard_reg_script_bus_table); |
| 92 | |
| 93 | #endif /* ENV_RAMSTAGE */ |