Kyösti Mälkki | 7809356 | 2014-11-11 17:22:23 +0200 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright (C) 2014 Sage Electronic Engineering, LLC |
| 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. |
Kyösti Mälkki | 7809356 | 2014-11-11 17:22:23 +0200 | [diff] [blame] | 14 | */ |
| 15 | |
| 16 | #include <stdint.h> |
| 17 | #include <arch/io.h> |
| 18 | #include "SBPLATFORM.h" |
| 19 | #include <southbridge/amd/cimx/cimx_util.h> |
| 20 | #include "gpio_ftns.h" |
| 21 | |
Stefan Reinauer | e6946c6 | 2015-06-19 15:54:00 -0700 | [diff] [blame] | 22 | uintptr_t find_gpio_base(void) |
Kyösti Mälkki | 7809356 | 2014-11-11 17:22:23 +0200 | [diff] [blame] | 23 | { |
| 24 | u8 pm_index, pm_data; |
Stefan Reinauer | e6946c6 | 2015-06-19 15:54:00 -0700 | [diff] [blame] | 25 | uintptr_t base_addr = 0; |
Kyösti Mälkki | 7809356 | 2014-11-11 17:22:23 +0200 | [diff] [blame] | 26 | |
| 27 | /* Find the ACPImmioAddr base address */ |
| 28 | for ( pm_index = 0x27; pm_index > 0x23; pm_index-- ) { |
| 29 | outb( pm_index, PM_INDEX ); |
| 30 | pm_data = inb( PM_DATA ); |
| 31 | base_addr <<= 8; |
| 32 | base_addr |= (u32)pm_data; |
| 33 | } |
| 34 | base_addr &= 0xFFFFF000; |
| 35 | return (base_addr); |
| 36 | } |
| 37 | |
Stefan Reinauer | e6946c6 | 2015-06-19 15:54:00 -0700 | [diff] [blame] | 38 | void configure_gpio(uintptr_t base_addr, u32 gpio, u8 iomux_ftn, u8 setting) |
Kyösti Mälkki | 7809356 | 2014-11-11 17:22:23 +0200 | [diff] [blame] | 39 | { |
| 40 | u8 bdata; |
| 41 | u8 *memptr; |
| 42 | |
| 43 | memptr = (u8 *)(base_addr + IOMUX_OFFSET + gpio); |
| 44 | *memptr = iomux_ftn; |
| 45 | |
| 46 | memptr = (u8 *)(base_addr + GPIO_OFFSET + gpio); |
| 47 | bdata = *memptr; |
| 48 | bdata &= 0x07; |
| 49 | bdata |= setting; /* set direction and data value */ |
| 50 | *memptr = bdata; |
| 51 | } |
| 52 | |
Stefan Reinauer | e6946c6 | 2015-06-19 15:54:00 -0700 | [diff] [blame] | 53 | u8 read_gpio(uintptr_t base_addr, u32 gpio) |
Kyösti Mälkki | 7809356 | 2014-11-11 17:22:23 +0200 | [diff] [blame] | 54 | { |
| 55 | u8 *memptr = (u8 *)(base_addr + GPIO_OFFSET + gpio); |
| 56 | return (*memptr & GPIO_DATA_IN) ? 1 : 0; |
| 57 | } |
| 58 | |
| 59 | int get_spd_offset(void) |
| 60 | { |
Stefan Reinauer | e6946c6 | 2015-06-19 15:54:00 -0700 | [diff] [blame] | 61 | uintptr_t base_addr = find_gpio_base(); |
Kyösti Mälkki | 7809356 | 2014-11-11 17:22:23 +0200 | [diff] [blame] | 62 | u8 spd_offset = read_gpio(base_addr, GPIO_16); |
| 63 | return spd_offset; |
| 64 | } |