blob: c595dffba7efaf4749411efd40f98e38c81dee6d [file] [log] [blame]
Lee Leahy15843bd2016-05-15 15:05:56 -07001/*
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,
Marshall Dawsone8c527e2017-01-13 14:23:49 -070011 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Lee Leahy15843bd2016-05-15 15:05:56 -070012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 */
15
16#define __SIMPLE_DEVICE__
17
Lee Leahyb0afbad2016-07-21 09:28:56 -070018#include <assert.h>
Lee Leahy15843bd2016-05-15 15:05:56 -070019#include <arch/io.h>
20#include <console/console.h>
21#include <device/i2c.h>
22#include <soc/pci_devs.h>
23#include <soc/reg_access.h>
24#include "reg_access.h"
25
Lee Leahy15843bd2016-05-15 15:05:56 -070026static 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);
Lee Leahyb0afbad2016-07-21 09:28:56 -070049 ret_code = i2c_readb(0, step->id, (uint8_t)step->reg, &value);
Lee Leahy15843bd2016-05-15 15:05:56 -070050 ASSERT(ret_code == 2);
51 break;
52 }
53 return value;
54}
55
56static 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);
Lee Leahyb0afbad2016-07-21 09:28:56 -070080 value = (uint8_t)step->value;
81 ret_code = i2c_writeb(0, step->id, (uint8_t)step->reg, value);
Lee Leahy15843bd2016-05-15 15:05:56 -070082 ASSERT(ret_code == 2);
83 break;
84 }
85}
86
87const struct reg_script_bus_entry mainboard_reg_script_bus_table = {
88 MAINBOARD_TYPE, reg_read, reg_write
89};
90
91REG_SCRIPT_BUS_ENTRY(mainboard_reg_script_bus_table);