2020-04-03 01:22:52 +02:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0-only */
|
|
|
|
/* This file is part of the coreboot project. */
|
2016-05-27 12:04:13 +02:00
|
|
|
|
|
|
|
#include <stdint.h>
|
2019-12-01 17:42:04 +01:00
|
|
|
#include <amdblocks/acpimmio.h>
|
|
|
|
#include <console/console.h>
|
2019-03-03 07:01:05 +01:00
|
|
|
#include <device/mmio.h>
|
2018-10-14 14:52:06 +02:00
|
|
|
#include <FchPlatform.h>
|
2016-05-27 12:04:13 +02:00
|
|
|
#include "gpio_ftns.h"
|
|
|
|
|
2019-12-01 17:42:04 +01:00
|
|
|
static u32 gpio_read_wrapper(u32 gpio)
|
|
|
|
{
|
|
|
|
if (gpio < 0x100)
|
|
|
|
return gpio0_read32(gpio & 0xff);
|
|
|
|
else if (gpio >= 0x100 && gpio < 0x200)
|
|
|
|
return gpio1_read32(gpio & 0xff);
|
|
|
|
else if (gpio >= 0x200 && gpio < 0x300)
|
|
|
|
return gpio2_read32(gpio & 0xff);
|
|
|
|
|
|
|
|
die("Invalid GPIO");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void gpio_write_wrapper(u32 gpio, u32 setting)
|
|
|
|
{
|
|
|
|
if (gpio < 0x100)
|
|
|
|
gpio0_write32(gpio & 0xff, setting);
|
|
|
|
else if (gpio >= 0x100 && gpio < 0x200)
|
|
|
|
gpio1_write32(gpio & 0xff, setting);
|
|
|
|
else if (gpio >= 0x200 && gpio < 0x300)
|
|
|
|
gpio2_write32(gpio & 0xff, setting);
|
|
|
|
}
|
|
|
|
|
|
|
|
void configure_gpio(u8 iomux_gpio, u8 iomux_ftn, u32 gpio, u32 setting)
|
2016-05-27 12:04:13 +02:00
|
|
|
{
|
2018-07-27 15:59:51 +02:00
|
|
|
u32 bdata;
|
2016-05-27 12:04:13 +02:00
|
|
|
|
2019-12-01 17:42:04 +01:00
|
|
|
bdata = gpio_read_wrapper(gpio);
|
2018-07-27 15:59:51 +02:00
|
|
|
/* out the data value to prevent glitches */
|
|
|
|
bdata |= (setting & GPIO_OUTPUT_ENABLE);
|
2019-12-01 17:42:04 +01:00
|
|
|
gpio_write_wrapper(gpio, bdata);
|
2016-05-27 12:04:13 +02:00
|
|
|
|
2018-07-27 15:59:51 +02:00
|
|
|
/* set direction and data value */
|
|
|
|
bdata |= (setting & (GPIO_OUTPUT_ENABLE | GPIO_OUTPUT_VALUE
|
|
|
|
| GPIO_PULL_UP_ENABLE | GPIO_PULL_DOWN_ENABLE));
|
2019-12-01 17:42:04 +01:00
|
|
|
gpio_write_wrapper(gpio, bdata);
|
2018-07-27 15:59:51 +02:00
|
|
|
|
2019-12-01 17:42:04 +01:00
|
|
|
iomux_write8(iomux_gpio, iomux_ftn & 0x3);
|
2016-05-27 12:04:13 +02:00
|
|
|
}
|
2017-01-16 18:58:53 +01:00
|
|
|
|
2018-07-30 12:31:00 +02:00
|
|
|
u8 read_gpio(u32 gpio)
|
|
|
|
{
|
2019-12-01 17:42:04 +01:00
|
|
|
return (gpio_read_wrapper(gpio) & GPIO_PIN_STS) ? 1 : 0;
|
2018-07-30 12:31:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void write_gpio(u32 gpio, u8 value)
|
|
|
|
{
|
2019-12-01 17:42:04 +01:00
|
|
|
u32 status = gpio_read_wrapper(gpio);
|
2018-07-30 12:31:00 +02:00
|
|
|
status &= ~GPIO_OUTPUT_VALUE;
|
|
|
|
status |= (value > 0) ? GPIO_OUTPUT_VALUE : 0;
|
2019-12-01 17:42:04 +01:00
|
|
|
gpio_write_wrapper(gpio, status);
|
2018-07-30 12:31:00 +02:00
|
|
|
}
|
|
|
|
|
2017-01-16 18:58:53 +01:00
|
|
|
int get_spd_offset(void)
|
|
|
|
{
|
|
|
|
u8 index = 0;
|
2019-12-01 17:42:04 +01:00
|
|
|
/*
|
|
|
|
* One SPD file contains all 4 options, determine which index to
|
2017-01-16 18:58:53 +01:00
|
|
|
* read here, then call into the standard routines.
|
|
|
|
*/
|
2019-12-01 17:42:04 +01:00
|
|
|
if (gpio1_read8(0x02) & BIT0)
|
|
|
|
index |= BIT0;
|
|
|
|
if (gpio1_read8(0x06) & BIT0)
|
|
|
|
index |= BIT1;
|
2017-01-16 18:58:53 +01:00
|
|
|
|
|
|
|
return index;
|
|
|
|
}
|