blob: 018fc0ad7a88b0c2d04be6447a89e8e8e84d9f0e [file] [log] [blame]
Kyösti Mälkki78093562014-11-11 17:22:23 +02001/*
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älkki78093562014-11-11 17:22:23 +020014 */
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 Reinauere6946c62015-06-19 15:54:00 -070022uintptr_t find_gpio_base(void)
Kyösti Mälkki78093562014-11-11 17:22:23 +020023{
24 u8 pm_index, pm_data;
Stefan Reinauere6946c62015-06-19 15:54:00 -070025 uintptr_t base_addr = 0;
Kyösti Mälkki78093562014-11-11 17:22:23 +020026
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 Reinauere6946c62015-06-19 15:54:00 -070038void configure_gpio(uintptr_t base_addr, u32 gpio, u8 iomux_ftn, u8 setting)
Kyösti Mälkki78093562014-11-11 17:22:23 +020039{
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 Reinauere6946c62015-06-19 15:54:00 -070053u8 read_gpio(uintptr_t base_addr, u32 gpio)
Kyösti Mälkki78093562014-11-11 17:22:23 +020054{
55 u8 *memptr = (u8 *)(base_addr + GPIO_OFFSET + gpio);
56 return (*memptr & GPIO_DATA_IN) ? 1 : 0;
57}
58
59int get_spd_offset(void)
60{
Stefan Reinauere6946c62015-06-19 15:54:00 -070061 uintptr_t base_addr = find_gpio_base();
Kyösti Mälkki78093562014-11-11 17:22:23 +020062 u8 spd_offset = read_gpio(base_addr, GPIO_16);
63 return spd_offset;
64}