Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/arch/arm/samsung XU4 i2c, gpio & pinctrl changes



details:   https://anonhg.NetBSD.org/src/rev/4fa7b29ea80d
branches:  trunk
changeset: 812726:4fa7b29ea80d
user:      marty <marty%NetBSD.org@localhost>
date:      Wed Dec 30 04:30:27 2015 +0000

description:
XU4 i2c, gpio & pinctrl changes

modify exynos_gpio.c to support the new pinctrl model.
set up the new pinctrl model in exynos_pinctrl.c

Flesh out exynos_i2c.c and set it up to use the new pinctrl model.  NOTE:
exynos_i2c.c is still incomplete.  I need to figure out what to set the
prescaler and scaler to.

diffstat:

 sys/arch/arm/samsung/exynos_combiner.c |    6 +-
 sys/arch/arm/samsung/exynos_gpio.c     |   65 +++++---
 sys/arch/arm/samsung/exynos_i2c.c      |  253 ++++++++++++++++++--------------
 sys/arch/arm/samsung/exynos_pinctrl.c  |   54 ++++++-
 sys/arch/arm/samsung/exynos_var.h      |   27 +++-
 5 files changed, 256 insertions(+), 149 deletions(-)

diffs (truncated from 711 to 300 lines):

diff -r 9094ba219734 -r 4fa7b29ea80d sys/arch/arm/samsung/exynos_combiner.c
--- a/sys/arch/arm/samsung/exynos_combiner.c    Wed Dec 30 04:23:39 2015 +0000
+++ b/sys/arch/arm/samsung/exynos_combiner.c    Wed Dec 30 04:30:27 2015 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: exynos_combiner.c,v 1.3 2015/12/24 21:20:17 marty Exp $ */
+/*     $NetBSD: exynos_combiner.c,v 1.4 2015/12/30 04:30:27 marty Exp $ */
 
 /*-
 * Copyright (c) 2015 The NetBSD Foundation, Inc.
@@ -34,7 +34,7 @@
 #include "gpio.h"
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(1, "$NetBSD: exynos_combiner.c,v 1.3 2015/12/24 21:20:17 marty Exp $");
+__KERNEL_RCSID(1, "$NetBSD: exynos_combiner.c,v 1.4 2015/12/30 04:30:27 marty Exp $");
 
 #include <sys/param.h>
 #include <sys/bus.h>
@@ -197,7 +197,7 @@
 
        kmem_free(interrupts, len);
 
-       snprintf(buf, buflen, "LIC irq %d", irq);
+       snprintf(buf, buflen, "combiner irq %d", irq);
 
        return true;
 }
diff -r 9094ba219734 -r 4fa7b29ea80d sys/arch/arm/samsung/exynos_gpio.c
--- a/sys/arch/arm/samsung/exynos_gpio.c        Wed Dec 30 04:23:39 2015 +0000
+++ b/sys/arch/arm/samsung/exynos_gpio.c        Wed Dec 30 04:30:27 2015 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: exynos_gpio.c,v 1.21 2015/12/27 12:42:14 jmcneill Exp $ */
+/*     $NetBSD: exynos_gpio.c,v 1.22 2015/12/30 04:30:27 marty Exp $ */
 
 /*-
 * Copyright (c) 2014 The NetBSD Foundation, Inc.
@@ -34,7 +34,7 @@
 #include "gpio.h"
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(1, "$NetBSD: exynos_gpio.c,v 1.21 2015/12/27 12:42:14 jmcneill Exp $");
+__KERNEL_RCSID(1, "$NetBSD: exynos_gpio.c,v 1.22 2015/12/30 04:30:27 marty Exp $");
 
 #include <sys/param.h>
 #include <sys/bus.h>
@@ -53,16 +53,6 @@
 
 #include <dev/fdt/fdtvar.h>
 
-struct exynos_gpio_pin_cfg {
-       uint32_t cfg;
-       uint32_t pud;
-       uint32_t drv;
-       uint32_t conpwd;
-       uint32_t pudpwd;
-};
-
-struct exynos_gpio_softc;
-
 struct exynos_gpio_bank {
        const char              bank_name[6];
        device_t                bank_dev;
@@ -80,12 +70,6 @@
        struct exynos_gpio_bank * bank_next;
 };
 
-struct exynos_gpio_softc {
-       device_t                sc_dev;
-       bus_space_tag_t         sc_bst;
-       bus_space_handle_t      sc_bsh;
-};
-
 struct exynos_gpio_pin {
        struct exynos_gpio_softc *pin_sc;
        int                       pin_no;
@@ -144,7 +128,7 @@
        GPIO_GRP(5, MUXD, 0x00E0, gpb4, 2),
        GPIO_GRP(5, MUXD, 0x0100, gph0, 4),
 
-       GPIO_GRP(5, MUXE, 0x0000, gpz0, 7),
+       GPIO_GRP(5, MUXE, 0x0000, gpz, 7),
 
 };
 
@@ -159,7 +143,6 @@
 
 static int exynos_gpio_fdt_read(device_t, void *, bool);
 static void exynos_gpio_fdt_write(device_t, void *, int, bool);
-static struct exynos_gpio_bank *exynos_gpio_bank_lookup(const char *);
 static int exynos_gpio_cfprint(void *, const char *);
 
 struct fdtbus_gpio_controller_func exynos_gpio_funcs = {
@@ -279,7 +262,27 @@
        exynos_gpio_update_cfg_regs(bank, &ncfg);
 }
 
-void
+void exynos_gpio_pin_ctl_read(const struct exynos_gpio_bank *bank,
+                             struct exynos_gpio_pin_cfg *cfg)
+{
+       cfg->cfg = GPIO_READ(bank, EXYNOS_GPIO_CON);
+       cfg->pud = GPIO_READ(bank, EXYNOS_GPIO_PUD);
+       cfg->drv = GPIO_READ(bank, EXYNOS_GPIO_DRV);
+       cfg->conpwd = GPIO_READ(bank, EXYNOS_GPIO_CONPWD);
+       cfg->pudpwd = GPIO_READ(bank, EXYNOS_GPIO_PUDPWD);
+}
+
+void exynos_gpio_pin_ctl_write(const struct exynos_gpio_bank *bank,
+                              const struct exynos_gpio_pin_cfg *cfg)
+{
+               GPIO_WRITE(bank, EXYNOS_GPIO_CON, cfg->cfg);
+               GPIO_WRITE(bank, EXYNOS_GPIO_PUD, cfg->pud);
+               GPIO_WRITE(bank, EXYNOS_GPIO_DRV, cfg->drv);
+               GPIO_WRITE(bank, EXYNOS_GPIO_CONPWD, cfg->conpwd);
+               GPIO_WRITE(bank, EXYNOS_GPIO_PUDPWD, cfg->pudpwd);
+}
+
+struct exynos_gpio_softc *
 exynos_gpio_bank_config(struct exynos_pinctrl_softc * parent,
                        const struct fdt_attach_args *faa, int node)
 {
@@ -294,13 +297,14 @@
        if (bank == NULL) {
                aprint_error_dev(parent->sc_dev, "no bank found for %s\n",
                    result);
-               return;
+               return NULL;
        }
        
        sc->sc_dev = parent->sc_dev;
        sc->sc_bst = &armv7_generic_bs_tag;
        sc->sc_bsh = parent->sc_bsh;
-       
+       sc->sc_bank = bank;
+
        gc_tag = &bank->bank_gc;
        gc_tag->gp_cookie = bank;
        gc_tag->gp_pin_read  = exynos_gpio_pin_read;
@@ -327,14 +331,23 @@
 
        fdtbus_register_gpio_controller(bank->bank_dev, node,
                                        &exynos_gpio_funcs);
+       return sc;
 }
 
-static struct exynos_gpio_bank *
+/*
+ * This function is a bit funky.  Given a string that may look like
+ * 'gpAN' or 'gpAN-P' it is meant to find a match to the part before
+ * the '-', or the four character string if the dash is not present.
+ */
+struct exynos_gpio_bank *
 exynos_gpio_bank_lookup(const char *name)
 {
+       struct exynos_gpio_bank *bank;
+
        for (u_int n = 0; n < __arraycount(exynos5_banks); n++) {
-               struct exynos_gpio_bank *bank = &exynos_gpio_banks[n];
-               if (strncmp(bank->bank_name, name, strlen(name)) == 0) {
+               bank = &exynos_gpio_banks[n];
+               if (!strncmp(bank->bank_name, name,
+                            strlen(bank->bank_name))) {
                        return bank;
                }
        }
diff -r 9094ba219734 -r 4fa7b29ea80d sys/arch/arm/samsung/exynos_i2c.c
--- a/sys/arch/arm/samsung/exynos_i2c.c Wed Dec 30 04:23:39 2015 +0000
+++ b/sys/arch/arm/samsung/exynos_i2c.c Wed Dec 30 04:30:27 2015 +0000
@@ -1,12 +1,9 @@
-/*     $NetBSD: exynos_i2c.c,v 1.8 2015/12/24 21:30:05 marty Exp $ */
+/*     $NetBSD: exynos_i2c.c,v 1.9 2015/12/30 04:30:27 marty Exp $ */
 
 /*
- * Copyright (c) 2014 The NetBSD Foundation, Inc.
+ * Copyright (c) 2015 Jared D. McNeill <jmcneill%invisible.ca@localhost>
  * All rights reserved.
  *
- * This code is derived from software contributed to The NetBSD Foundation
- * by Reinoud Zandijk.
- *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
  * are met:
@@ -34,16 +31,18 @@
 #include "opt_arm_debug.h"
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: exynos_i2c.c,v 1.8 2015/12/24 21:30:05 marty Exp $");
+__KERNEL_RCSID(0, "$NetBSD: exynos_i2c.c,v 1.9 2015/12/30 04:30:27 marty Exp $");
 
 #include <sys/param.h>
 #include <sys/bus.h>
 #include <sys/device.h>
 #include <sys/intr.h>
 #include <sys/systm.h>
+#include <sys/kernel.h>
 #include <sys/kmem.h>
 
 #include <arm/samsung/exynos_reg.h>
+#include <arm/samsung/exynos_var.h>
 #include <arm/samsung/exynos_intr.h>
 
 #include <sys/gpio.h>
@@ -59,19 +58,18 @@
        bus_space_tag_t         sc_bst;
        bus_space_handle_t      sc_bsh;
        void *                  sc_ih;
-       u_int                   sc_port;
+       struct clk *            sc_clk;
 
-       struct fdtbus_gpio_pin  *sc_sda;
-       struct fdtbus_gpio_pin  *sc_scl;
+       struct fdtbus_pinctrl_pin  *sc_sda;
+       struct fdtbus_pinctrl_pin  *sc_scl;
        bool                    sc_sda_is_output;
+
        struct i2c_controller   sc_ic;
        kmutex_t                sc_lock;
        kcondvar_t              sc_cv;
        device_t                sc_i2cdev;
 };
 
-static u_int i2c_port;
-
 static int     exynos_i2c_intr(void *);
 
 static int     exynos_i2c_acquire_bus(void *, int);
@@ -83,22 +81,46 @@
 static int     exynos_i2c_read_byte(void *, uint8_t *, int);
 static int     exynos_i2c_write_byte(void *, uint8_t , int);
 
-static bool exynos_i2c_attach_i2cbus(struct exynos_i2c_softc *,
-                                    struct i2c_controller *);
+static int     exynos_i2c_wait(struct exynos_i2c_softc *, int);
+
 
 static int exynos_i2c_match(device_t, cfdata_t, void *);
 static void exynos_i2c_attach(device_t, device_t, void *);
 
+static i2c_tag_t exynos_i2c_get_tag(device_t);
+
+struct fdtbus_i2c_controller_func exynos_i2c_funcs = {
+       .get_tag = exynos_i2c_get_tag
+};
+
 CFATTACH_DECL_NEW(exynos_i2c, sizeof(struct exynos_i2c_softc),
     exynos_i2c_match, exynos_i2c_attach, NULL, NULL);
 
 #define I2C_WRITE(sc, reg, val) \
-    bus_space_write_4((sc)->sc_bst, (sc)->sc_bsh, (reg), (val))
+    bus_space_write_1((sc)->sc_bst, (sc)->sc_bsh, (reg), (val))
 #define I2C_READ(sc, reg) \
-    bus_space_read_4((sc)->sc_bst, (sc)->sc_bsh, (reg))
+    bus_space_read_1((sc)->sc_bst, (sc)->sc_bsh, (reg))
+
+#define IICCON  0x00
+#define IICSTAT 0x04
+#define IICADD  0x08
+#define IICDS   0x0C
 
-#define IICON 0
-#define IRQPEND (1<<4)
+#define ACKENABLE  (1<<7)
+#define TXPRESCALE (1<<6)
+#define INTENABLE  (1<<5)
+#define IRQPEND    (1<<4)
+#define PRESCALE   (0x0f)
+
+#define MODESELECT  (3<<6)
+#define BUSYSTART   (1<<5)
+#define BUSENABLE   (1<<4)
+#define ARBITRATION (1<<3)
+#define SLAVESTATUS (1<<2)
+#define ZEROSTATUS  (1<<1)
+#define LASTBIT     (1<<0)
+
+#define READBIT     (1<<7)
 
 static int
 exynos_i2c_match(device_t self, cfdata_t cf, void *aux)
@@ -126,7 +148,7 @@
        int i2c_handle;
        int len;
        int handle;
-       int func /*, pud, drv */;
+       int func, pud, drv;
 
        if (fdtbus_get_reg(phandle, 0, &addr, &size) != 0) {
                aprint_error(": couldn't get registers\n");
@@ -143,7 +165,6 @@
                return;
        }
 
-       sc->sc_port = i2c_port++;
        mutex_init(&sc->sc_lock, MUTEX_DEFAULT, IPL_VM);
        cv_init(&sc->sc_cv, device_xname(self));
        aprint_normal(" @ 0x%08x\n", (uint)addr);
@@ -184,11 +205,18 @@
        } else
                func = be32toh(handle);



Home | Main Index | Thread Index | Old Index