From owner-svn-src-head@FreeBSD.ORG Sat Sep 13 19:59:17 2014 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 2CE52610; Sat, 13 Sep 2014 19:59:17 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 1283A1CC; Sat, 13 Sep 2014 19:59:17 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.9/8.14.9) with ESMTP id s8DJxGb2013875; Sat, 13 Sep 2014 19:59:16 GMT (envelope-from ian@FreeBSD.org) Received: (from ian@localhost) by svn.freebsd.org (8.14.9/8.14.9/Submit) id s8DJxGND013873; Sat, 13 Sep 2014 19:59:16 GMT (envelope-from ian@FreeBSD.org) Message-Id: <201409131959.s8DJxGND013873@svn.freebsd.org> X-Authentication-Warning: svn.freebsd.org: ian set sender to ian@FreeBSD.org using -f From: Ian Lepore Date: Sat, 13 Sep 2014 19:59:16 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r271548 - head/sys/arm/at91 X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 13 Sep 2014 19:59:17 -0000 Author: ian Date: Sat Sep 13 19:59:16 2014 New Revision: 271548 URL: http://svnweb.freebsd.org/changeset/base/271548 Log: Convert the at91_pinctrl driver to use the new fdt_pinctrl interface. Modified: head/sys/arm/at91/at91_pinctrl.c head/sys/arm/at91/files.at91 Modified: head/sys/arm/at91/at91_pinctrl.c ============================================================================== --- head/sys/arm/at91/at91_pinctrl.c Sat Sep 13 19:37:11 2014 (r271547) +++ head/sys/arm/at91/at91_pinctrl.c Sat Sep 13 19:59:16 2014 (r271548) @@ -40,6 +40,7 @@ __FBSDID("$FreeBSD$"); #include #include +#include #include #include #include @@ -250,6 +251,8 @@ at91_pinctrl_attach(device_t dev) device_set_ivars(cdev, di); } + fdt_pinctrl_register(dev, "atmel,pins"); + return (bus_generic_attach(dev)); } @@ -370,93 +373,70 @@ pinctrl_print_child(device_t bus, device const char *periphs[] = {"gpio", "periph A", "periph B", "periph C", "periph D", "periph E" }; -static void -pinctrl_walk_tree(device_t bus, phandle_t node) +struct pincfg { + uint32_t unit; + uint32_t pin; + uint32_t periph; + uint32_t flags; +}; + +static int +pinctrl_configure_pins(device_t bus, phandle_t cfgxref) { struct pinctrl_softc *sc; - char status[10]; + struct pincfg *cfg, *cfgdata; char name[32]; - phandle_t pinctrl[32], pins[32 * 4], scratch; - ssize_t len, npins; - int i, j; + phandle_t node; + ssize_t npins; + int i; sc = device_get_softc(bus); - for (node = OF_child(node); node > 0; node = OF_peer(node)) { - pinctrl_walk_tree(bus, node); - memset(status, 0, sizeof(status)); - memset(name, 0, sizeof(name)); - OF_getprop(node, "status", status, sizeof(status)); - OF_getprop(node, "name", name, sizeof(name)); - if (strcmp(status, "okay") != 0) { -// printf("pinctrl: skipping node %s status %s\n", name, -// status); - continue; - } - len = OF_getencprop(node, "pinctrl-0", pinctrl, sizeof(pinctrl)); - if (len <= 0) { -// printf("pinctrl: skipping node %s no pinctrl-0\n", -// name, status); - continue; - } - len /= sizeof(phandle_t); - printf("pinctrl: Found active node %s\n", name); - for (i = 0; i < len; i++) { - scratch = OF_node_from_xref(pinctrl[i]); - npins = OF_getencprop(scratch, "atmel,pins", pins, - sizeof(pins)); - if (npins <= 0) { - printf("We're doing it wrong %s\n", name); - continue; - } - memset(name, 0, sizeof(name)); - OF_getprop(scratch, "name", name, sizeof(name)); - npins /= (4 * 4); - printf("----> need to cope with %d more pins for %s\n", - npins, name); - for (j = 0; j < npins; j++) { - uint32_t unit = pins[j * 4]; - uint32_t pin = pins[j * 4 + 1]; - uint32_t periph = pins[j * 4 + 2]; - uint32_t flags = pins[j * 4 + 3]; - uint32_t pio; - - pio = (0xfffffff & sc->ranges[0].bus) + - 0x200 * unit; - printf("P%c%d %s %#x\n", unit + 'A', pin, - periphs[periph], flags); - switch (periph) { - case 0: - at91_pio_use_gpio(pio, 1u << pin); - at91_pio_gpio_pullup(pio, 1u << pin, - !!(flags & 1)); - at91_pio_gpio_high_z(pio, 1u << pin, - !!(flags & 2)); - at91_pio_gpio_set_deglitch(pio, - 1u << pin, !!(flags & 4)); -// at91_pio_gpio_pulldown(pio, 1u << pin, -// !!(flags & 8)); -// at91_pio_gpio_dis_schmidt(pio, -// 1u << pin, !!(flags & 16)); - break; - case 1: - at91_pio_use_periph_a(pio, 1u << pin, - flags); - break; - case 2: - at91_pio_use_periph_b(pio, 1u << pin, - flags); - break; - } - } + node = OF_node_from_xref(cfgxref); + memset(name, 0, sizeof(name)); + OF_getprop(node, "name", name, sizeof(name)); + npins = OF_getencprop_alloc(node, "atmel,pins", sizeof(*cfgdata), + (void **)&cfgdata); + if (npins < 0) { + printf("We're doing it wrong %s\n", name); + return (ENXIO); + } + if (npins == 0) + return (0); + for (i = 0, cfg = cfgdata; i < npins; i++, cfg++) { + uint32_t pio; + pio = (0xfffffff & sc->ranges[0].bus) + 0x200 * cfg->unit; + printf("P%c%d %s %#x\n", cfg->unit + 'A', cfg->pin, + periphs[cfg->periph], cfg->flags); + switch (cfg->periph) { + case 0: + at91_pio_use_gpio(pio, 1u << cfg->pin); + at91_pio_gpio_pullup(pio, 1u << cfg->pin, + !!(cfg->flags & 1)); + at91_pio_gpio_high_z(pio, 1u << cfg->pin, + !!(cfg->flags & 2)); + at91_pio_gpio_set_deglitch(pio, + 1u << cfg->pin, !!(cfg->flags & 4)); +// at91_pio_gpio_pulldown(pio, 1u << cfg->pin, +// !!(cfg->flags & 8)); +// at91_pio_gpio_dis_schmidt(pio, +// 1u << cfg->pin, !!(cfg->flags & 16)); + break; + case 1: + at91_pio_use_periph_a(pio, 1u << cfg->pin, cfg->flags); + break; + case 2: + at91_pio_use_periph_b(pio, 1u << cfg->pin, cfg->flags); + break; } } + free(cfgdata, M_OFWPROP); + return (0); } static void pinctrl_new_pass(device_t bus) { struct pinctrl_softc *sc; - phandle_t node; sc = device_get_softc(bus); @@ -466,10 +446,7 @@ pinctrl_new_pass(device_t bus) return; sc->done_pinmux++; - node = OF_peer(0); - if (node == -1) - return; - pinctrl_walk_tree(bus, node); + fdt_pinctrl_configure_tree(bus); } static device_method_t at91_pinctrl_methods[] = { @@ -496,6 +473,8 @@ static device_method_t at91_pinctrl_meth DEVMETHOD(ofw_bus_get_node, ofw_bus_gen_get_node), DEVMETHOD(ofw_bus_get_type, ofw_bus_gen_get_type), + /* fdt_pintrl interface */ + DEVMETHOD(fdt_pinctrl_configure,pinctrl_configure_pins), DEVMETHOD_END }; Modified: head/sys/arm/at91/files.at91 ============================================================================== --- head/sys/arm/at91/files.at91 Sat Sep 13 19:37:11 2014 (r271547) +++ head/sys/arm/at91/files.at91 Sat Sep 13 19:59:16 2014 (r271548) @@ -10,7 +10,7 @@ arm/at91/at91_smc.c standard arm/at91/at91_cfata.c optional at91_cfata arm/at91/at91_common.c optional fdt arm/at91/at91_mci.c optional at91_mci -arm/at91/at91_pinctrl.c optional fdt +arm/at91/at91_pinctrl.c optional fdt fdt_pinctrl arm/at91/at91_pit.c optional at91sam9 arm/at91/at91_reset.S optional at91sam9 arm/at91/at91_rst.c optional at91sam9