summaryrefslogtreecommitdiffstats
path: root/exynos4412_gpios_data.c
diff options
context:
space:
mode:
authorDenis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>2021-05-17 15:49:52 +0200
committerDenis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>2021-05-17 18:09:31 +0200
commita42d43917edb9e68a61c2ce485f456bd9310986e (patch)
treec91f7514bb677a2bd26d94f0ee73e1b14c64be04 /exynos4412_gpios_data.c
parenta9086ea231b622ebdc36e390bc58ce2f1217a225 (diff)
downloadexynos-gpio-tool-a42d43917edb9e68a61c2ce485f456bd9310986e.tar.gz
exynos-gpio-tool-a42d43917edb9e68a61c2ce485f456bd9310986e.tar.bz2
exynos-gpio-tool-a42d43917edb9e68a61c2ce485f456bd9310986e.zip
Rework GPIO functions to make them even more generic
Signed-off-by: Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>
Diffstat (limited to 'exynos4412_gpios_data.c')
-rw-r--r--exynos4412_gpios_data.c146
1 files changed, 131 insertions, 15 deletions
diff --git a/exynos4412_gpios_data.c b/exynos4412_gpios_data.c
index 02e689d..3e8fede 100644
--- a/exynos4412_gpios_data.c
+++ b/exynos4412_gpios_data.c
@@ -15,6 +15,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
+#include <errno.h>
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
@@ -24,20 +25,91 @@
struct gpio_bank_data gpio_banks_data[] = {
{
+ .name = "gpj0",
+ .nr_gpios = 8,
+ .offset = 0x0240,
+ },
+ {
.name = "gpj1",
- .nr_gpios = 4,
- .con_offset = 0x0260, /* GPJ1CON */
- .dat_offset = 0x0264, /* GPJ1DAT */
- .pud_offset = 0x0268, /* GPJ1PUD */
- .drv_offset = 0x026c, /* GPJ1DRV */
- .con_pdn_offset = 0x0270, /* GPJ1CONPDN */
- .pud_pdn_offset = 0x0274, /* GPJ1PUDPDN */
+ .nr_gpios = 5,
+ .offset = 0x0260,
},
{
/* Sentinel */
},
};
+static int get_dat_value(uint32_t register_value, int gpio_offset)
+{
+ return ((register_value >> (gpio_offset)) & 1);
+}
+
+static int get_con_value(uint32_t register_value, int gpio_offset)
+{
+ return ((register_value >> (gpio_offset * 4)) & 0xf);
+}
+
+static int get_pud_value(uint32_t register_value, int gpio_offset)
+{
+ /* TODO */
+
+ return 0;
+}
+
+static int get_drv_value(uint32_t register_value, int gpio_offset)
+{
+ /* TODO */
+
+ return 0;
+}
+
+static int get_con_pdn_value(uint32_t register_value, int gpio_offset)
+{
+ /* TODO */
+
+ return 0;
+}
+
+static int get_pud_pdn_value(uint32_t register_value, int gpio_offset)
+{
+ /* TODO */
+
+ return 0;
+}
+
+struct gpio_register_data gpio_registers_data[] = {
+ {
+ .name = "con",
+ .get_value = get_con_value,
+ .offset = 0x00,
+ },
+ {
+ .name = "dat",
+ .get_value = get_dat_value,
+ .offset = 0x04,
+ },
+ {
+ .name = "pud",
+ .get_value = get_pud_value,
+ .offset = 0x08,
+ },
+ {
+ .name = "drv",
+ .get_value = get_drv_value,
+ .offset = 0x0c,
+ },
+ {
+ .name = "con-pdn",
+ .get_value = get_con_pdn_value,
+ .offset = 0x10,
+ },
+ {
+ .name = "pud-pdn",
+ .get_value = get_pud_pdn_value,
+ .offset = 0x14,
+ },
+};
+
struct gpio_bank_data *get_gpio_bank_data(char *bank)
{
@@ -56,6 +128,24 @@ struct gpio_bank_data *get_gpio_bank_data(char *bank)
return NULL;
}
+struct gpio_register_data *get_gpio_register_data(char *register_name)
+{
+
+ int i = 0;
+
+ while (1) {
+ if (gpio_registers_data[i].name == NULL)
+ break;
+
+ if (!strcmp(gpio_registers_data[i].name, register_name))
+ return &(gpio_registers_data[i]);
+
+ i++;
+ }
+
+ return NULL;
+}
+
void print_gpio_banks_data(void)
{
int i = 0;
@@ -66,16 +156,42 @@ void print_gpio_banks_data(void)
printf("%s[%d] {\n", gpio_banks_data[i].name,
gpio_banks_data[i].nr_gpios);
- printf("\tcon_offset: %p\n", gpio_banks_data[i].con_offset);
- printf("\tdat_offset: %p\n", gpio_banks_data[i].dat_offset);
- printf("\tpud_offset: %p\n", gpio_banks_data[i].pud_offset);
- printf("\tdrv_offset: %p\n", gpio_banks_data[i].drv_offset);
- printf("\tcon_pdn_offset: %p\n",
- gpio_banks_data[i].con_pdn_offset);
- printf("\tpud_pdn_offset: %p\n",
- gpio_banks_data[i].pud_pdn_offset);
+ printf("\toffset: %p\n", gpio_banks_data[i].offset);
printf("}\n");
i++;
}
}
+
+int decode_gpio_data(int debug, char *bank, uint32_t gpio_offset,
+ char* gpio_register_name, uint32_t *virt_addr)
+{
+ struct gpio_bank_data *gpio_bank_data;
+ struct gpio_register_data *gpio_register_data;
+
+ int result = 0;
+ uint32_t offset;
+ uint32_t *addr;
+ uint32_t register_value;
+
+ gpio_bank_data = get_gpio_bank_data(bank);
+ if (gpio_bank_data == NULL) {
+ errno = EINVAL;
+ return -1;
+ }
+
+ gpio_register_data = get_gpio_register_data(gpio_register_name);
+ if (gpio_register_data == NULL) {
+ errno = EINVAL;
+ return -1;
+ }
+
+ addr = virt_addr + gpio_bank_data->offset + gpio_register_data->offset;
+ register_value = *virt_addr;
+
+ if (debug)
+ printf("%s: %s: offset %p value: 0x%x\n", __func__, bank,
+ addr - virt_addr, register_value);
+
+ return gpio_register_data->get_value(register_value, gpio_offset);
+}