<p>Marc Jones has uploaded this change for <strong>review</strong>.</p><p><a href="https://review.coreboot.org/21684">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">amd/stoneyridge: Refactor GPIO functions<br><br>Refactor the GPIO functions to use GPIO numbers. This is more consitent with<br>other GPIO code in coreboot.<br><br>BUG=b:66462235<br>BRANCH=none<br>TEST=Build and boot Kahlee<br><br>Change-Id: I6d6af7f6a0ed9ba1230342e1ca024535c4f34d47<br>Signed-off-by: Marc Jones <marcj303@gmail.com><br>---<br>M src/mainboard/google/kahlee/chromeos.c<br>M src/soc/amd/stoneyridge/gpio.c<br>M src/soc/amd/stoneyridge/include/soc/gpio.h<br>3 files changed, 123 insertions(+), 102 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://review.coreboot.org:29418/coreboot refs/changes/84/21684/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">diff --git a/src/mainboard/google/kahlee/chromeos.c b/src/mainboard/google/kahlee/chromeos.c<br>index 156614b..a8b1f34 100644<br>--- a/src/mainboard/google/kahlee/chromeos.c<br>+++ b/src/mainboard/google/kahlee/chromeos.c<br>@@ -17,7 +17,6 @@<br> <br> #include <vendorcode/google/chromeos/chromeos.h><br> #include <boot/coreboot_tables.h><br>-#include <console/console.h><br> #include <gpio.h><br> <br> /* SPI Write protect */<br>diff --git a/src/soc/amd/stoneyridge/gpio.c b/src/soc/amd/stoneyridge/gpio.c<br>index 7e19d99..86655fc 100644<br>--- a/src/soc/amd/stoneyridge/gpio.c<br>+++ b/src/soc/amd/stoneyridge/gpio.c<br>@@ -16,26 +16,40 @@<br> */<br> <br> #include <arch/io.h><br>+#include <console/console.h><br> #include <gpio.h><br> #include <soc/gpio.h><br> <br>-/* The following functions must be implemented by SoC/board code. */<br>+static uintptr_t gpio_get_address(gpio_t gpio_num)<br>+{<br>+ uintptr_t gpio_address;<br>+<br>+ if (gpio_num < 64)<br>+ gpio_address = GPIO_BANK0_CONTROL(gpio_num);<br>+ else if (gpio_num < 128)<br>+ gpio_address = GPIO_BANK1_CONTROL(gpio_num);<br>+ else<br>+ gpio_address = GPIO_BANK2_CONTROL(gpio_num);<br>+<br>+ return gpio_address;<br>+}<br> <br> int gpio_get(gpio_t gpio_num)<br> {<br> uint32_t reg;<br>+ uintptr_t gpio_address = gpio_get_address(gpio_num);<br> <br>- reg = read32((void *)(uintptr_t)gpio_num);<br>+ reg = read32((void *)gpio_address);<br> <br> return !!(reg & GPIO_PIN_STS);<br> }<br> <br>-<br> void gpio_set(gpio_t gpio_num, int value)<br> {<br> uint32_t reg;<br>+ uintptr_t gpio_address = gpio_get_address(gpio_num);<br> <br>- reg = read32((void *)(uintptr_t)gpio_num);<br>+ reg = read32((void *)gpio_address);<br> reg &= ~GPIO_OUTPUT_MASK;<br> reg |= !!value << GPIO_OUTPUT_SHIFT;<br> write32((void *)(uintptr_t)gpio_num, reg);<br>@@ -44,8 +58,9 @@<br> void gpio_input_pulldown(gpio_t gpio_num)<br> {<br> uint32_t reg;<br>+ uintptr_t gpio_address = gpio_get_address(gpio_num);<br> <br>- reg = read32((void *)(uintptr_t)gpio_num);<br>+ reg = read32((void *)gpio_address);<br> reg &= ~GPIO_PULLUP_ENABLE;<br> reg |= GPIO_PULLDOWN_ENABLE;<br> write32((void *)(uintptr_t)gpio_num, reg);<br>@@ -54,8 +69,9 @@<br> void gpio_input_pullup(gpio_t gpio_num)<br> {<br> uint32_t reg;<br>+ uintptr_t gpio_address = gpio_get_address(gpio_num);<br> <br>- reg = read32((void *)(uintptr_t)gpio_num);<br>+ reg = read32((void *)gpio_address);<br> reg &= ~GPIO_PULLDOWN_ENABLE;<br> reg |= GPIO_PULLUP_ENABLE;<br> write32((void *)(uintptr_t)gpio_num, reg);<br>@@ -64,8 +80,9 @@<br> void gpio_input(gpio_t gpio_num)<br> {<br> uint32_t reg;<br>+ uintptr_t gpio_address = gpio_get_address(gpio_num);<br> <br>- reg = read32((void *)(uintptr_t)gpio_num);<br>+ reg = read32((void *)gpio_address);<br> reg &= ~GPIO_OUTPUT_ENABLE;<br> write32((void *)(uintptr_t)gpio_num, reg);<br> }<br>@@ -73,8 +90,9 @@<br> void gpio_output(gpio_t gpio_num, int value)<br> {<br> uint32_t reg;<br>+ uintptr_t gpio_address = gpio_get_address(gpio_num);<br> <br>- reg = read32((void *)(uintptr_t)gpio_num);<br>+ reg = read32((void *)gpio_address);<br> reg |= GPIO_OUTPUT_ENABLE;<br> write32((void *)(uintptr_t)gpio_num, reg);<br> }<br>diff --git a/src/soc/amd/stoneyridge/include/soc/gpio.h b/src/soc/amd/stoneyridge/include/soc/gpio.h<br>index c5b7c8a..f5c84ef 100644<br>--- a/src/soc/amd/stoneyridge/include/soc/gpio.h<br>+++ b/src/soc/amd/stoneyridge/include/soc/gpio.h<br>@@ -29,103 +29,107 @@<br> #define GPIO_OUTPUT_ENABLE (1 << 23)<br> <br> /* GPIO_0 - GPIO_62 */<br>-#define GPIO_BANK0_CONTROL (AMD_SB_ACPI_MMIO_ADDR + 0x1500)<br>-#define GPIO_0 (GPIO_BANK0_CONTROL + 0x00)<br>-#define GPIO_1 (GPIO_BANK0_CONTROL + 0x04)<br>-#define GPIO_2 (GPIO_BANK0_CONTROL + 0x08)<br>-#define GPIO_3 (GPIO_BANK0_CONTROL + 0x0c)<br>-#define GPIO_4 (GPIO_BANK0_CONTROL + 0x10)<br>-#define GPIO_5 (GPIO_BANK0_CONTROL + 0x14)<br>-#define GPIO_6 (GPIO_BANK0_CONTROL + 0x18)<br>-#define GPIO_7 (GPIO_BANK0_CONTROL + 0x1c)<br>-#define GPIO_8 (GPIO_BANK0_CONTROL + 0x20)<br>-#define GPIO_9 (GPIO_BANK0_CONTROL + 0x24)<br>-#define GPIO_10 (GPIO_BANK0_CONTROL + 0x28)<br>-#define GPIO_11 (GPIO_BANK0_CONTROL + 0x2c)<br>-#define GPIO_12 (GPIO_BANK0_CONTROL + 0x30)<br>-#define GPIO_13 (GPIO_BANK0_CONTROL + 0x34)<br>-#define GPIO_14 (GPIO_BANK0_CONTROL + 0x38)<br>-#define GPIO_15 (GPIO_BANK0_CONTROL + 0x3c)<br>-#define GPIO_16 (GPIO_BANK0_CONTROL + 0x40)<br>-#define GPIO_17 (GPIO_BANK0_CONTROL + 0x44)<br>-#define GPIO_18 (GPIO_BANK0_CONTROL + 0x48)<br>-#define GPIO_19 (GPIO_BANK0_CONTROL + 0x4c)<br>-#define GPIO_20 (GPIO_BANK0_CONTROL + 0x50)<br>-#define GPIO_21 (GPIO_BANK0_CONTROL + 0x54)<br>-#define GPIO_22 (GPIO_BANK0_CONTROL + 0x58)<br>-#define GPIO_23 (GPIO_BANK0_CONTROL + 0x5c)<br>-#define GPIO_24 (GPIO_BANK0_CONTROL + 0x60)<br>-#define GPIO_25 (GPIO_BANK0_CONTROL + 0x64)<br>-#define GPIO_26 (GPIO_BANK0_CONTROL + 0x68)<br>-#define GPIO_39 (GPIO_BANK0_CONTROL + 0x9c)<br>-#define GPIO_42 (GPIO_BANK0_CONTROL + 0xa8)<br>+#define GPIO_BANK0_CONTROL(gpio) \<br>+ (AMD_SB_ACPI_MMIO_ADDR + 0x1500 + (gpio * 4))<br>+#define GPIO_0 0<br>+#define GPIO_1 1<br>+#define GPIO_2 2<br>+#define GPIO_3 3<br>+#define GPIO_4 4<br>+#define GPIO_5 5<br>+#define GPIO_6 6<br>+#define GPIO_7 7<br>+#define GPIO_8 8<br>+#define GPIO_9 9<br>+#define GPIO_10 10<br>+#define GPIO_11 11<br>+#define GPIO_12 12<br>+#define GPIO_13 13<br>+#define GPIO_14 14<br>+#define GPIO_15 15<br>+#define GPIO_16 16<br>+#define GPIO_17 17<br>+#define GPIO_18 18<br>+#define GPIO_19 19<br>+#define GPIO_20 20<br>+#define GPIO_21 21<br>+#define GPIO_22 22<br>+#define GPIO_23 23<br>+#define GPIO_24 24<br>+#define GPIO_25 25<br>+#define GPIO_26 26<br>+#define GPIO_39 39<br>+#define GPIO_42 42<br> <br> /* GPIO_64 - GPIO_127 */<br>-#define GPIO_BANK1_CONTROL (AMD_SB_ACPI_MMIO_ADDR + 0x1600)<br>-#define GPIO_64 (GPIO_BANK1_CONTROL + 0x00)<br>-#define GPIO_65 (GPIO_BANK1_CONTROL + 0x04)<br>-#define GPIO_66 (GPIO_BANK1_CONTROL + 0x08)<br>-#define GPIO_67 (GPIO_BANK1_CONTROL + 0x0c)<br>-#define GPIO_68 (GPIO_BANK1_CONTROL + 0x10)<br>-#define GPIO_69 (GPIO_BANK1_CONTROL + 0x14)<br>-#define GPIO_70 (GPIO_BANK1_CONTROL + 0x18)<br>-#define GPIO_71 (GPIO_BANK1_CONTROL + 0x1c)<br>-#define GPIO_72 (GPIO_BANK1_CONTROL + 0x20)<br>-#define GPIO_74 (GPIO_BANK1_CONTROL + 0x28)<br>-#define GPIO_75 (GPIO_BANK1_CONTROL + 0x2c)<br>-#define GPIO_76 (GPIO_BANK1_CONTROL + 0x30)<br>-#define GPIO_84 (GPIO_BANK1_CONTROL + 0x50)<br>-#define GPIO_85 (GPIO_BANK1_CONTROL + 0x54)<br>-#define GPIO_86 (GPIO_BANK1_CONTROL + 0x58)<br>-#define GPIO_87 (GPIO_BANK1_CONTROL + 0x5c)<br>-#define GPIO_88 (GPIO_BANK1_CONTROL + 0x60)<br>-#define GPIO_89 (GPIO_BANK1_CONTROL + 0x64)<br>-#define GPIO_90 (GPIO_BANK1_CONTROL + 0x68)<br>-#define GPIO_91 (GPIO_BANK1_CONTROL + 0x6c)<br>-#define GPIO_92 (GPIO_BANK1_CONTROL + 0x70)<br>-#define GPIO_93 (GPIO_BANK1_CONTROL + 0x74)<br>-#define GPIO_95 (GPIO_BANK1_CONTROL + 0x7c)<br>-#define GPIO_96 (GPIO_BANK1_CONTROL + 0x80)<br>-#define GPIO_97 (GPIO_BANK1_CONTROL + 0x84)<br>-#define GPIO_98 (GPIO_BANK1_CONTROL + 0x88)<br>-#define GPIO_99 (GPIO_BANK1_CONTROL + 0x8c)<br>-#define GPIO_100 (GPIO_BANK1_CONTROL + 0x90)<br>-#define GPIO_101 (GPIO_BANK1_CONTROL + 0x94)<br>-#define GPIO_102 (GPIO_BANK1_CONTROL + 0x98)<br>-#define GPIO_113 (GPIO_BANK1_CONTROL + 0xc4)<br>-#define GPIO_114 (GPIO_BANK1_CONTROL + 0xc8)<br>-#define GPIO_115 (GPIO_BANK1_CONTROL + 0xcc)<br>-#define GPIO_116 (GPIO_BANK1_CONTROL + 0xd0)<br>-#define GPIO_117 (GPIO_BANK1_CONTROL + 0xd4)<br>-#define GPIO_118 (GPIO_BANK1_CONTROL + 0xd8)<br>-#define GPIO_119 (GPIO_BANK1_CONTROL + 0xdc)<br>-#define GPIO_120 (GPIO_BANK1_CONTROL + 0xe0)<br>-#define GPIO_121 (GPIO_BANK1_CONTROL + 0xe4)<br>-#define GPIO_122 (GPIO_BANK1_CONTROL + 0xe8)<br>-#define GPIO_126 (GPIO_BANK1_CONTROL + 0xf8)<br>+#define GPIO_BANK1_CONTROL(gpio) \<br>+ (AMD_SB_ACPI_MMIO_ADDR + 0x1600 + ((gpio - 64) * 4))<br>+#define GPIO_64 64<br>+#define GPIO_65 65<br>+#define GPIO_66 66<br>+#define GPIO_67 67<br>+#define GPIO_68 68<br>+#define GPIO_69 69<br>+#define GPIO_70 70<br>+#define GPIO_71 71<br>+#define GPIO_72 72<br>+#define GPIO_74 74<br>+#define GPIO_75 75<br>+#define GPIO_76 76<br>+#define GPIO_84 84<br>+#define GPIO_85 85<br>+#define GPIO_86 86<br>+#define GPIO_87 87<br>+#define GPIO_88 88<br>+#define GPIO_89 89<br>+#define GPIO_90 90<br>+#define GPIO_91 91<br>+#define GPIO_92 92<br>+#define GPIO_93 93<br>+#define GPIO_95 95<br>+#define GPIO_96 96<br>+#define GPIO_97 97<br>+#define GPIO_98 98<br>+#define GPIO_99 99<br>+#define GPIO_100 100<br>+#define GPIO_101 101<br>+#define GPIO_102 102<br>+#define GPIO_113 113<br>+#define GPIO_114 114<br>+#define GPIO_115 115<br>+#define GPIO_116 116<br>+#define GPIO_117 117<br>+#define GPIO_118 118<br>+#define GPIO_119 119<br>+#define GPIO_120 120<br>+#define GPIO_121 121<br>+#define GPIO_122 122<br>+#define GPIO_126 126<br> <br> /* GPIO_128 - GPIO_183 */<br>-#define GPIO_BANK2_CONTROL (AMD_SB_ACPI_MMIO_ADDR + 0x1700)<br>-#define GPIO_129 (GPIO_BANK2_CONTROL + 0x04)<br>-#define GPIO_130 (GPIO_BANK2_CONTROL + 0x08)<br>-#define GPIO_131 (GPIO_BANK2_CONTROL + 0x0c)<br>-#define GPIO_132 (GPIO_BANK2_CONTROL + 0x10)<br>-#define GPIO_133 (GPIO_BANK2_CONTROL + 0x14)<br>-#define GPIO_134 (GPIO_BANK2_CONTROL + 0x18)<br>-#define GPIO_135 (GPIO_BANK2_CONTROL + 0x1c)<br>-#define GPIO_136 (GPIO_BANK2_CONTROL + 0x20)<br>-#define GPIO_137 (GPIO_BANK2_CONTROL + 0x24)<br>-#define GPIO_138 (GPIO_BANK2_CONTROL + 0x28)<br>-#define GPIO_139 (GPIO_BANK2_CONTROL + 0x2c)<br>-#define GPIO_140 (GPIO_BANK2_CONTROL + 0x30)<br>-#define GPIO_141 (GPIO_BANK2_CONTROL + 0x34)<br>-#define GPIO_142 (GPIO_BANK2_CONTROL + 0x38)<br>-#define GPIO_143 (GPIO_BANK2_CONTROL + 0x3c)<br>-#define GPIO_144 (GPIO_BANK2_CONTROL + 0x40)<br>-#define GPIO_145 (GPIO_BANK2_CONTROL + 0x44)<br>-#define GPIO_146 (GPIO_BANK2_CONTROL + 0x48)<br>-#define GPIO_147 (GPIO_BANK2_CONTROL + 0x4c)<br>-#define GPIO_148 (GPIO_BANK2_CONTROL + 0x50)<br>+#define GPIO_BANK2_CONTROL(gpio) \<br>+ (AMD_SB_ACPI_MMIO_ADDR + 0x1700 + ((gpio - 128) * 4))<br>+/* GPIO_128 Reserved */<br>+#define GPIO_129 129<br>+#define GPIO_130 130<br>+#define GPIO_131 131<br>+#define GPIO_132 132<br>+#define GPIO_133 133<br>+#define GPIO_134 134<br>+#define GPIO_135 135<br>+#define GPIO_136 136<br>+#define GPIO_137 137<br>+#define GPIO_138 138<br>+#define GPIO_139 139<br>+#define GPIO_140 140<br>+#define GPIO_141 141<br>+#define GPIO_142 142<br>+#define GPIO_143 143<br>+#define GPIO_144 144<br>+#define GPIO_145 145<br>+#define GPIO_146 146<br>+#define GPIO_147 147<br>+#define GPIO_148 148<br> <br> typedef uint32_t gpio_t;<br> <br></pre><p>To view, visit <a href="https://review.coreboot.org/21684">change 21684</a>. To unsubscribe, visit <a href="https://review.coreboot.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://review.coreboot.org/21684"/><meta itemprop="name" content="View Change"/></div></div>
<div style="display:none"> Gerrit-Project: coreboot </div>
<div style="display:none"> Gerrit-Branch: master </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>
<div style="display:none"> Gerrit-Change-Id: I6d6af7f6a0ed9ba1230342e1ca024535c4f34d47 </div>
<div style="display:none"> Gerrit-Change-Number: 21684 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: Marc Jones <marc@marcjonesconsulting.com> </div>