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 warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | */ |
| 15 | |
| 16 | #ifndef _GALILEO_REG_ACCESS_H_ |
| 17 | #define _GALILEO_REG_ACCESS_H_ |
| 18 | |
| 19 | #include <fsp/util.h> |
| 20 | #include <reg_script.h> |
| 21 | #include <soc/IntelQNCConfig.h> |
| 22 | #include <soc/QuarkNcSocId.h> |
| 23 | #include <soc/reg_access.h> |
| 24 | |
| 25 | enum { |
| 26 | MAINBOARD_TYPE = REG_SCRIPT_TYPE_MAINBOARD_BASE, |
| 27 | /* Add additional mainboard access types here*/ |
| 28 | }; |
| 29 | |
| 30 | enum { |
| 31 | GEN1_I2C_GPIO_EXP_0x20 = 0x20, /* Cypress CY8C9540A */ |
| 32 | GEN1_I2C_GPIO_EXP_0x21 = 0x21, /* Cypress CY8C9540A */ |
| 33 | |
| 34 | GEN2_I2C_GPIO_EXP0 = 0x25, /* NXP PCAL9535A */ |
| 35 | GEN2_I2C_GPIO_EXP1 = 0x26, /* NXP PCAL9535A */ |
| 36 | GEN2_I2C_GPIO_EXP2 = 0x27, /* NXP PCAL9535A */ |
| 37 | GEN2_I2C_LED_PWM = 0x47, /* NXP PCAL9685 */ |
| 38 | }; |
| 39 | |
| 40 | /* Cypress CY8C9548A registers */ |
| 41 | #define GEN1_GPIO_EXP_INPUT0 0x00 |
| 42 | #define GEN1_GPIO_EXP_INPUT1 0x01 |
| 43 | #define GEN1_GPIO_EXP_INPUT2 0x02 |
| 44 | #define GEN1_GPIO_EXP_INPUT3 0x03 |
| 45 | #define GEN1_GPIO_EXP_INPUT4 0x04 |
| 46 | #define GEN1_GPIO_EXP_INPUT5 0x05 |
| 47 | #define GEN1_GPIO_EXP_OUTPUT0 0x08 |
| 48 | #define GEN1_GPIO_EXP_OUTPUT1 0x09 |
| 49 | #define GEN1_GPIO_EXP_OUTPUT2 0x0a |
| 50 | #define GEN1_GPIO_EXP_OUTPUT3 0x0b |
| 51 | #define GEN1_GPIO_EXP_OUTPUT4 0x0c |
| 52 | #define GEN1_GPIO_EXP_OUTPUT5 0x0d |
| 53 | #define GEN1_GPIO_EXP_PORT_SELECT 0x18 |
| 54 | #define GEN1_GPIO_EXP_PORT_DIR 0x1c |
| 55 | |
| 56 | /* NXP PCAL9535A registers */ |
| 57 | #define GEN2_GPIO_EXP_INPUT0 0x00 |
| 58 | #define GEN2_GPIO_EXP_INPUT1 0x01 |
| 59 | #define GEN2_GPIO_EXP_OUTPUT0 0x02 |
| 60 | #define GEN2_GPIO_EXP_OUTPUT1 0x03 |
| 61 | #define GEN2_GPIO_EXP_POLARITY0 0x04 |
| 62 | #define GEN2_GPIO_EXP_POLARITY1 0x05 |
| 63 | #define GEN2_GPIO_EXP_CONFIG0 0x06 |
| 64 | #define GEN2_GPIO_EXP_CONFIG1 0x07 |
| 65 | #define GEN2_GPIO_EXP_INPUT_LATCH0 0x44 |
| 66 | #define GEN2_GPIO_EXP_INPUT_LATCH1 0x45 |
| 67 | #define GEN2_GPIO_EXP_PULL_UP_DOWN_EN0 0x46 |
| 68 | #define GEN2_GPIO_EXP_PULL_UP_DOWN_EN1 0x47 |
| 69 | #define GEN2_GPIO_EXP_PULL_UP_DOWN_SEL0 0x46 |
| 70 | #define GEN2_GPIO_EXP_PULL_UP_DOWN_SEL1 0x47 |
| 71 | |
| 72 | #define MAINBOARD_ACCESS(cmd_, reg_, size_, mask_, value_, timeout_, reg_set_) \ |
| 73 | _REG_SCRIPT_ENCODE_RAW(REG_SCRIPT_COMMAND_##cmd_, MAINBOARD_TYPE, \ |
| 74 | size_, reg_, mask_, value_, timeout_, reg_set_) |
| 75 | |
| 76 | /* I2C chip register access macros */ |
| 77 | #define REG_I2C_ACCESS(cmd_, reg_, mask_, value_, timeout_, slave_addr_) \ |
| 78 | MAINBOARD_ACCESS(cmd_, reg_, REG_SCRIPT_SIZE_8, mask_, value_, \ |
| 79 | timeout_, slave_addr_) |
| 80 | #define REG_I2C_READ(slave_addr_, reg_) \ |
| 81 | REG_I2C_ACCESS(READ, reg_, 0, 0, 0, slave_addr_) |
| 82 | #define REG_I2C_WRITE(slave_addr_, reg_, value_) \ |
| 83 | REG_I2C_ACCESS(WRITE, reg_, 0, value_, 0, slave_addr_) |
| 84 | #define REG_I2C_AND(slave_addr_, reg_, value_) \ |
| 85 | REG_I2C_RMW(slave_addr_, reg_, value_, 0) |
| 86 | #define REG_I2C_RMW(slave_addr_, reg_, mask_, value_) \ |
| 87 | REG_I2C_ACCESS(RMW, reg_, mask_, value_, 0, slave_addr_) |
| 88 | #define REG_I2C_RXW(slave_addr_, reg_, mask_, value_) \ |
| 89 | REG_I2C_ACCESS(RXW, reg_, mask_, value_, 0, slave_addr_) |
| 90 | #define REG_I2C_OR(slave_addr_, reg_, value_) \ |
| 91 | REG_I2C_RMW(slave_addr_, reg_, 0xff, value_) |
| 92 | #define REG_I2C_POLL(slave_addr_, reg_, mask_, value_, timeout_) \ |
| 93 | REG_I2C_ACCESS(POLL, reg_, mask_, value_, timeout_, slave_addr_) |
| 94 | #define REG_I2C_XOR(slave_addr_, reg_, value_) \ |
| 95 | REG_I2C_RXW(slave_addr_, reg_, 0xff, value_) |
| 96 | |
| 97 | #endif /* _GALILEO_REG_ACCESS_H_ */ |