Maxim Polyakov has uploaded this change for review.

View Change

[WIP] ec/kontron/kempld: Add code to GPIOs control

This is based on code from the drivers/gpio/gpio-kempld.c linux driver.
Tested on Kontron mAL10 COMe module with T10-TNI carrierboard [1].

[1] https://review.coreboot.org/c/coreboot/+/39133

Change-Id: Id767aa451fbf2ca1c0dccfc9aa2c024c6f37c1bb
Signed-off-by: Maxim Polyakov <max.senia.poliak@gmail.com>
---
M src/ec/kontron/kempld/Makefile.inc
M src/ec/kontron/kempld/kempld.h
A src/ec/kontron/kempld/kempld_gpio.c
A src/ec/kontron/kempld/kempld_gpio.h
4 files changed, 118 insertions(+), 0 deletions(-)

git pull ssh://review.coreboot.org:29418/coreboot refs/changes/95/47595/1
diff --git a/src/ec/kontron/kempld/Makefile.inc b/src/ec/kontron/kempld/Makefile.inc
index 0d59886..e7bafa3 100644
--- a/src/ec/kontron/kempld/Makefile.inc
+++ b/src/ec/kontron/kempld/Makefile.inc
@@ -2,3 +2,4 @@
ramstage-$(CONFIG_EC_KONTRON_KEMPLD) += early_kempld.c
ramstage-$(CONFIG_EC_KONTRON_KEMPLD) += kempld.c
ramstage-$(CONFIG_EC_KONTRON_KEMPLD) += kempld_i2c.c
+ramstage-$(CONFIG_EC_KONTRON_KEMPLD) += kempld_gpio.c
diff --git a/src/ec/kontron/kempld/kempld.h b/src/ec/kontron/kempld/kempld.h
index 6f624aa..7bd6ba3 100644
--- a/src/ec/kontron/kempld/kempld.h
+++ b/src/ec/kontron/kempld/kempld.h
@@ -13,4 +13,9 @@

void kempld_enable_uart_for_console(void);

+int kempld_gpio_get(unsigned int offset);
+void kempld_gpio_set(unsigned int offset, int value);
+void kempld_gpio_direction_input(unsigned int offset);
+void kempld_gpio_direction_output(unsigned int offset, int value);
+
#endif /* EC_KONTRON_KEMPLD_H */
diff --git a/src/ec/kontron/kempld/kempld_gpio.c b/src/ec/kontron/kempld/kempld_gpio.c
new file mode 100644
index 0000000..b3307ae
--- /dev/null
+++ b/src/ec/kontron/kempld/kempld_gpio.c
@@ -0,0 +1,83 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * Kontron PLD driver definitions
+ *
+ * Copyright (c) 2010-2012 Kontron Europe GmbH
+ * Author: Michael Brunner <michael.brunner@kontron.com>
+ */
+
+#include <stdint.h>
+#include <arch/io.h>
+#include <delay.h>
+#include "chip.h"
+#include "kempld.h"
+#include "kempld_gpio.h"
+#include "kempld_internal.h"
+
+int kempld_gpio_get(unsigned int offset)
+{
+ int status;
+
+ if (kempld_get_mutex(100) < 0)
+ return 0;
+
+ status = kempld_read8((u8)KEMPLD_GPIO_LVL_NUM(offset));
+ status &= KEMPLD_GPIO_MASK(offset);
+
+ kempld_release_mutex();
+
+ return status;
+}
+
+void kempld_gpio_set(unsigned int offset, int value)
+{
+ int status;
+
+ if (kempld_get_mutex(100) < 0)
+ return;
+
+ status = kempld_read8((u8)KEMPLD_GPIO_LVL_NUM(offset));
+ if (value)
+ status |= KEMPLD_GPIO_MASK(offset);
+ else
+ status &= ~KEMPLD_GPIO_MASK(offset);
+ kempld_write8((u8)KEMPLD_GPIO_LVL_NUM(offset), (u8)status);
+
+ kempld_release_mutex();
+}
+
+
+void kempld_gpio_direction_input(unsigned int offset)
+{
+ int status;
+
+ if (kempld_get_mutex(100) < 0)
+ return;
+
+ status = kempld_read8((u8)KEMPLD_GPIO_DIR_NUM(offset));
+ status &= ~KEMPLD_GPIO_MASK(offset);
+ kempld_write8((u8)KEMPLD_GPIO_DIR_NUM(offset), (u8)status);
+
+ kempld_release_mutex();
+}
+
+void kempld_gpio_direction_output(unsigned int offset, int value)
+{
+ int status;
+
+ if (kempld_get_mutex(100) < 0)
+ return;
+
+ status = kempld_read8((u8)KEMPLD_GPIO_LVL_NUM(offset));
+ if (value)
+ status |= KEMPLD_GPIO_MASK(offset);
+ else
+ status &= ~KEMPLD_GPIO_MASK(offset);
+ kempld_write8((u8)KEMPLD_GPIO_LVL_NUM(offset), (u8)status);
+
+ status = kempld_read8((u8)KEMPLD_GPIO_DIR_NUM(offset));
+ status |= KEMPLD_GPIO_MASK(offset);
+ kempld_write8((u8)KEMPLD_GPIO_DIR_NUM(offset), (u8)status);
+
+ kempld_release_mutex();
+}
diff --git a/src/ec/kontron/kempld/kempld_gpio.h b/src/ec/kontron/kempld/kempld_gpio.h
new file mode 100644
index 0000000..b918bd0
--- /dev/null
+++ b/src/ec/kontron/kempld/kempld_gpio.h
@@ -0,0 +1,29 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * Kontron PLD driver definitions
+ *
+ * Copyright (c) 2010-2012 Kontron Europe GmbH
+ * Author: Michael Brunner <michael.brunner@kontron.com>
+ */
+
+#ifndef _KEMPLD_GPIO_H_
+#define _KEMPLD_GPIO_H_
+
+#define KEMPLD_GPIO_MAX_NUM 16
+#define KEMPLD_GPIO_MASK(x) (1 << ((x) % 8))
+#define KEMPLD_GPIO_DIR 0x40
+#define KEMPLD_GPIO_DIR_NUM(x) (0x40 + (x)/8)
+#define KEMPLD_GPIO_LVL 0x42
+#define KEMPLD_GPIO_LVL_NUM(x) (0x42 + (x)/8)
+#define KEMPLD_GPIO_STS 0x44
+#define KEMPLD_GPIO_STS_NUM(x) (0x44 + (x)/8)
+#define KEMPLD_GPIO_EVT_LVL_EDGE 0x46
+#define KEMPLD_GPIO_EVT_LVL_EDGE_NUM(x) (0x46 + (x)/8)
+#define KEMPLD_GPIO_EVT_LOW_HIGH 0x48
+#define KEMPLD_GPIO_EVT_LOW_HIGH_NUM(x) (0x48 + (x)/8)
+#define KEMPLD_GPIO_IEN 0x4A
+#define KEMPLD_GPIO_IEN_NUM(x) (0x4A + (x)/8)
+#define KEMPLD_GPIO_NMIEN 0x4C
+#define KEMPLD_GPIO_NMIEN_NUM(x) (0x4C + (x)/8)
+
+#endif /* _KEMPLD_GPIO_H_ */

To view, visit change 47595. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: coreboot
Gerrit-Branch: master
Gerrit-Change-Id: Id767aa451fbf2ca1c0dccfc9aa2c024c6f37c1bb
Gerrit-Change-Number: 47595
Gerrit-PatchSet: 1
Gerrit-Owner: Maxim Polyakov <max.senia.poliak@gmail.com>
Gerrit-MessageType: newchange