Daisuke Nojiri | 0594914 | 2014-11-21 15:33:26 -0800 | [diff] [blame] | 1 | /* |
Vadim Bendebury | 6fe4e5e | 2014-12-06 10:44:58 -0800 | [diff] [blame] | 2 | * This file is part of the coreboot project. |
Daisuke Nojiri | 0594914 | 2014-11-21 15:33:26 -0800 | [diff] [blame] | 3 | * |
Sourabh Banerjee | 8920865 | 2015-02-19 16:43:26 +0530 | [diff] [blame] | 4 | * Copyright (C) 2014 - 2015 The Linux Foundation. All rights reserved. |
Daisuke Nojiri | 0594914 | 2014-11-21 15:33:26 -0800 | [diff] [blame] | 5 | * |
| 6 | * Redistribution and use in source and binary forms, with or without |
| 7 | * modification, are permitted provided that the following conditions |
| 8 | * are met: |
| 9 | * 1. Redistributions of source code must retain the above copyright |
| 10 | * notice, this list of conditions and the following disclaimer. |
| 11 | * 2. Redistributions in binary form must reproduce the above copyright |
| 12 | * notice, this list of conditions and the following disclaimer in the |
| 13 | * documentation and/or other materials provided with the distribution. |
| 14 | * 3. The name of the author may not be used to endorse or promote products |
| 15 | * derived from this software without specific prior written permission. |
| 16 | * |
| 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND |
| 18 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE |
| 21 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
| 23 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 24 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
| 25 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
| 26 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 27 | * SUCH DAMAGE. |
| 28 | */ |
| 29 | |
| 30 | #include <arch/io.h> |
Sourabh Banerjee | 8920865 | 2015-02-19 16:43:26 +0530 | [diff] [blame] | 31 | #include <soc/iomap.h> |
Vadim Bendebury | 6fe4e5e | 2014-12-06 10:44:58 -0800 | [diff] [blame] | 32 | #include <soc/gsbi.h> |
Sourabh Banerjee | 8920865 | 2015-02-19 16:43:26 +0530 | [diff] [blame] | 33 | #include <console/console.h> |
Daisuke Nojiri | 0594914 | 2014-11-21 15:33:26 -0800 | [diff] [blame] | 34 | |
Sourabh Banerjee | 8920865 | 2015-02-19 16:43:26 +0530 | [diff] [blame] | 35 | static inline void *gsbi_ctl_reg_addr(gsbi_id_t gsbi_id) |
| 36 | { |
| 37 | switch (gsbi_id) { |
| 38 | case GSBI_ID_1: |
| 39 | return GSBI1_CTL_REG; |
| 40 | case GSBI_ID_2: |
| 41 | return GSBI2_CTL_REG; |
| 42 | case GSBI_ID_3: |
| 43 | return GSBI3_CTL_REG; |
| 44 | case GSBI_ID_4: |
| 45 | return GSBI4_CTL_REG; |
| 46 | case GSBI_ID_5: |
| 47 | return GSBI5_CTL_REG; |
| 48 | case GSBI_ID_6: |
| 49 | return GSBI6_CTL_REG; |
| 50 | case GSBI_ID_7: |
| 51 | return GSBI7_CTL_REG; |
| 52 | default: |
| 53 | printk(BIOS_ERR, "Unsupported GSBI%d\n", gsbi_id); |
| 54 | return 0; |
| 55 | } |
| 56 | } |
Daisuke Nojiri | 0594914 | 2014-11-21 15:33:26 -0800 | [diff] [blame] | 57 | |
Daisuke Nojiri | 0594914 | 2014-11-21 15:33:26 -0800 | [diff] [blame] | 58 | gsbi_return_t gsbi_init(gsbi_id_t gsbi_id, gsbi_protocol_t protocol) |
| 59 | { |
Sourabh Banerjee | 8920865 | 2015-02-19 16:43:26 +0530 | [diff] [blame] | 60 | unsigned reg_val; |
| 61 | unsigned m = 1; |
| 62 | unsigned n = 4; |
| 63 | unsigned pre_div = 4; |
| 64 | unsigned src = 3; |
| 65 | unsigned mnctr_mode = 2; |
| 66 | void *gsbi_ctl = gsbi_ctl_reg_addr(gsbi_id); |
Daisuke Nojiri | 0594914 | 2014-11-21 15:33:26 -0800 | [diff] [blame] | 67 | |
Sourabh Banerjee | 8920865 | 2015-02-19 16:43:26 +0530 | [diff] [blame] | 68 | if (!gsbi_ctl) |
| 69 | return GSBI_ID_ERROR; |
Daisuke Nojiri | 0594914 | 2014-11-21 15:33:26 -0800 | [diff] [blame] | 70 | |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame] | 71 | write32(GSBI_HCLK_CTL(gsbi_id), |
| 72 | (1 << GSBI_HCLK_CTL_GATE_ENA) | (1 << GSBI_HCLK_CTL_BRANCH_ENA)); |
Daisuke Nojiri | 0594914 | 2014-11-21 15:33:26 -0800 | [diff] [blame] | 73 | |
Sourabh Banerjee | 8920865 | 2015-02-19 16:43:26 +0530 | [diff] [blame] | 74 | if (gsbi_init_board(gsbi_id)) |
| 75 | return GSBI_UNSUPPORTED; |
| 76 | |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame] | 77 | write32(GSBI_QUP_APSS_NS_REG(gsbi_id), 0); |
| 78 | write32(GSBI_QUP_APSS_MD_REG(gsbi_id), 0); |
Sourabh Banerjee | 8920865 | 2015-02-19 16:43:26 +0530 | [diff] [blame] | 79 | |
| 80 | reg_val = ((m & GSBI_QUP_APPS_M_MASK) << GSBI_QUP_APPS_M_SHFT) | |
| 81 | ((~n & GSBI_QUP_APPS_D_MASK) << GSBI_QUP_APPS_D_SHFT); |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame] | 82 | write32(GSBI_QUP_APSS_MD_REG(gsbi_id), reg_val); |
Sourabh Banerjee | 8920865 | 2015-02-19 16:43:26 +0530 | [diff] [blame] | 83 | |
| 84 | reg_val = (((~(n - m)) & GSBI_QUP_APPS_N_MASK) << |
| 85 | GSBI_QUP_APPS_N_SHFT) | |
| 86 | ((mnctr_mode & GSBI_QUP_APPS_MNCTR_MODE_MSK) << |
| 87 | GSBI_QUP_APPS_MNCTR_MODE_SFT) | |
| 88 | (((pre_div - 1) & GSBI_QUP_APPS_PRE_DIV_MSK) << |
| 89 | GSBI_QUP_APPS_PRE_DIV_SFT) | |
| 90 | (src & GSBI_QUP_APPS_SRC_SEL_MSK); |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame] | 91 | write32(GSBI_QUP_APSS_NS_REG(gsbi_id), reg_val); |
Sourabh Banerjee | 8920865 | 2015-02-19 16:43:26 +0530 | [diff] [blame] | 92 | |
| 93 | reg_val |= (1 << GSBI_QUP_APPS_ROOT_ENA_SFT) | |
| 94 | (1 << GSBI_QUP_APPS_MNCTR_EN_SFT); |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame] | 95 | write32(GSBI_QUP_APSS_NS_REG(gsbi_id), reg_val); |
Sourabh Banerjee | 8920865 | 2015-02-19 16:43:26 +0530 | [diff] [blame] | 96 | |
| 97 | reg_val |= (1 << GSBI_QUP_APPS_BRANCH_ENA_SFT); |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame] | 98 | write32(GSBI_QUP_APSS_NS_REG(gsbi_id), reg_val); |
Daisuke Nojiri | 0594914 | 2014-11-21 15:33:26 -0800 | [diff] [blame] | 99 | |
| 100 | /*Select i2c protocol*/ |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame] | 101 | write32(gsbi_ctl, |
| 102 | ((GSBI_CTL_PROTO_I2C & GSBI_CTL_PROTO_CODE_MSK) << GSBI_CTL_PROTO_CODE_SFT)); |
Daisuke Nojiri | 0594914 | 2014-11-21 15:33:26 -0800 | [diff] [blame] | 103 | |
Sourabh Banerjee | 8920865 | 2015-02-19 16:43:26 +0530 | [diff] [blame] | 104 | return GSBI_SUCCESS; |
Daisuke Nojiri | 0594914 | 2014-11-21 15:33:26 -0800 | [diff] [blame] | 105 | } |