blob: 36345ffddd6a262c19259497bec16050f0e6ee7a [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,
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
Lee Leahy15843bd2016-05-15 15:05:56 -070025static uint64_t reg_read(struct reg_script_context *ctx)
26{
27 int ret_code;
28 const struct reg_script *step;
29 uint8_t value = 0;
30
31 step = ctx->step;
32 switch (step->id) {
33 default:
34 printk(BIOS_ERR,
35 "ERROR - Unknown register set (0x%08x)!\n",
36 step->id);
37 ctx->display_features = REG_SCRIPT_DISPLAY_NOTHING;
38 break;
39
40 case GEN1_I2C_GPIO_EXP_0x20:
41 case GEN1_I2C_GPIO_EXP_0x21:
42 case GEN2_I2C_GPIO_EXP0:
43 case GEN2_I2C_GPIO_EXP1:
44 case GEN2_I2C_GPIO_EXP2:
45 case GEN2_I2C_LED_PWM:
46 if (ctx->display_features)
47 printk(BIOS_INFO, "I2C chip 0x%02x: ", step->id);
48 ret_code = i2c_readb(0, step->id, (UINT8)step->reg, &value);
49 ASSERT(ret_code == 2);
50 break;
51 }
52 return value;
53}
54
55static void reg_write(struct reg_script_context *ctx)
56{
57 int ret_code;
58 const struct reg_script *step;
59 uint8_t value;
60
61 step = ctx->step;
62 switch (step->id) {
63 default:
64 printk(BIOS_ERR,
65 "ERROR - Unknown register set (0x%08x)!\n",
66 step->id);
67 ctx->display_features = REG_SCRIPT_DISPLAY_NOTHING;
68 break;
69
70 case GEN1_I2C_GPIO_EXP_0x20:
71 case GEN1_I2C_GPIO_EXP_0x21:
72 case GEN2_I2C_GPIO_EXP0:
73 case GEN2_I2C_GPIO_EXP1:
74 case GEN2_I2C_GPIO_EXP2:
75 case GEN2_I2C_LED_PWM:
76 case RMU_TEMP_REGS:
77 if (ctx->display_features)
78 printk(BIOS_INFO, "I2C chip 0x%02x: ", step->id);
79 value = (UINT8)step->value;
80 ret_code = i2c_writeb(0, step->id, (UINT8)step->reg, value);
81 ASSERT(ret_code == 2);
82 break;
83 }
84}
85
86const struct reg_script_bus_entry mainboard_reg_script_bus_table = {
87 MAINBOARD_TYPE, reg_read, reg_write
88};
89
90REG_SCRIPT_BUS_ENTRY(mainboard_reg_script_bus_table);