From owner-svn-src-head@freebsd.org Sun Jan 24 11:03:36 2016 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id B67D07F1F; Sun, 24 Jan 2016 11:03:36 +0000 (UTC) (envelope-from mmel@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::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 91CB28D9; Sun, 24 Jan 2016 11:03:36 +0000 (UTC) (envelope-from mmel@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id u0OB3ZGw021312; Sun, 24 Jan 2016 11:03:35 GMT (envelope-from mmel@FreeBSD.org) Received: (from mmel@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u0OB3Zqo021307; Sun, 24 Jan 2016 11:03:35 GMT (envelope-from mmel@FreeBSD.org) Message-Id: <201601241103.u0OB3Zqo021307@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: mmel set sender to mmel@FreeBSD.org using -f From: Michal Meloun Date: Sun, 24 Jan 2016 11:03:35 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r294661 - in head/sys: conf dev/extres/hwreset 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.20 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: Sun, 24 Jan 2016 11:03:36 -0000 Author: mmel Date: Sun Jan 24 11:03:35 2016 New Revision: 294661 URL: https://svnweb.freebsd.org/changeset/base/294661 Log: Add reset framework, a second part of new 'extended resources' family of support frameworks (i.e. regulators/phy/tsensors/fuses...). It provides simple unified consumers interface for manipulations with on-chip resets. Reviewed by: ian, imp (paritaly) Added: head/sys/dev/extres/hwreset/ head/sys/dev/extres/hwreset/hwreset.c (contents, props changed) head/sys/dev/extres/hwreset/hwreset.h (contents, props changed) head/sys/dev/extres/hwreset/hwreset_if.m (contents, props changed) Modified: head/sys/conf/files Modified: head/sys/conf/files ============================================================================== --- head/sys/conf/files Sun Jan 24 11:00:38 2016 (r294660) +++ head/sys/conf/files Sun Jan 24 11:03:35 2016 (r294661) @@ -1417,6 +1417,8 @@ dev/extres/clk/clk_div.c optional ext_re dev/extres/clk/clk_fixed.c optional ext_resources clk dev/extres/clk/clk_gate.c optional ext_resources clk dev/extres/clk/clk_mux.c optional ext_resources clk +dev/extres/hwreset/hwreset.c optional ext_resources hwreset +dev/extres/hwreset/hwreset_if.m optional ext_resources hwreset dev/fatm/if_fatm.c optional fatm pci dev/fb/fbd.c optional fbd | vt dev/fb/fb_if.m standard Added: head/sys/dev/extres/hwreset/hwreset.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/sys/dev/extres/hwreset/hwreset.c Sun Jan 24 11:03:35 2016 (r294661) @@ -0,0 +1,186 @@ +/*- + * Copyright 2016 Michal Meloun + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ +#include "opt_platform.h" +#include +#include +#include +#include +#include +#include + +#ifdef FDT +#include +#include +#endif + +#include + +#include "hwreset_if.h" + +struct hwreset { + device_t consumer_dev; /* consumer device*/ + device_t provider_dev; /* provider device*/ + int rst_id; /* reset id */ +}; + +MALLOC_DEFINE(M_HWRESET, "hwreset", "Reset framework"); + +int +hwreset_assert(hwreset_t rst) +{ + + return (HWRESET_ASSERT(rst->provider_dev, rst->rst_id, true)); +} + +int +hwreset_deassert(hwreset_t rst) +{ + + return (HWRESET_ASSERT(rst->provider_dev, rst->rst_id, false)); +} + +int +hwreset_is_asserted(hwreset_t rst, bool *value) +{ + + return (HWRESET_IS_ASSERTED(rst->provider_dev, rst->rst_id, value)); +} + +void +hwreset_release(hwreset_t rst) +{ + free(rst, M_HWRESET); +} + +int +hwreset_get_by_id(device_t consumer_dev, device_t provider_dev, intptr_t id, + hwreset_t *rst_out) +{ + hwreset_t rst; + + /* Create handle */ + rst = malloc(sizeof(struct hwreset), M_HWRESET, + M_WAITOK | M_ZERO); + rst->consumer_dev = consumer_dev; + rst->provider_dev = provider_dev; + rst->rst_id = id; + *rst_out = rst; + return (0); +} + +#ifdef FDT +int +hwreset_default_ofw_map(device_t provider_dev, phandle_t xref, int ncells, + pcell_t *cells, intptr_t *id) +{ + if (ncells == 0) + *id = 1; + else if (ncells == 1) + *id = cells[0]; + else + return (ERANGE); + + return (0); +} + +int +hwreset_get_by_ofw_idx(device_t consumer_dev, int idx, hwreset_t *rst) +{ + phandle_t cnode, xnode; + pcell_t *cells; + device_t rstdev; + int ncells, rv; + intptr_t id; + + cnode = ofw_bus_get_node(consumer_dev); + if (cnode <= 0) { + device_printf(consumer_dev, + "%s called on not ofw based device\n", __func__); + return (ENXIO); + } + + rv = ofw_bus_parse_xref_list_alloc(cnode, "resets", "#reset-cells", + idx, &xnode, &ncells, &cells); + if (rv != 0) + return (rv); + + /* Tranlate provider to device */ + rstdev = OF_device_from_xref(xnode); + if (rstdev == NULL) { + free(cells, M_OFWPROP); + return (ENODEV); + } + /* Map reset to number */ + rv = HWRESET_MAP(rstdev, xnode, ncells, cells, &id); + free(cells, M_OFWPROP); + if (rv != 0) + return (rv); + + return (hwreset_get_by_id(consumer_dev, rstdev, id, rst)); +} + +int +hwreset_get_by_ofw_name(device_t consumer_dev, char *name, hwreset_t *rst) +{ + int rv, idx; + phandle_t cnode; + + cnode = ofw_bus_get_node(consumer_dev); + if (cnode <= 0) { + device_printf(consumer_dev, + "%s called on not ofw based device\n", __func__); + return (ENXIO); + } + rv = ofw_bus_find_string_index(cnode, "reset-names", name, &idx); + if (rv != 0) + return (rv); + return (hwreset_get_by_ofw_idx(consumer_dev, idx, rst)); +} + +void +hwreset_register_ofw_provider(device_t provider_dev) +{ + phandle_t xref, node; + + node = ofw_bus_get_node(provider_dev); + if (node <= 0) + panic("%s called on not ofw based device.\n", __func__); + + xref = OF_xref_from_node(node); + OF_device_register_xref(xref, provider_dev); +} + +void +hwreset_unregister_ofw_provider(device_t provider_dev) +{ + phandle_t xref; + + xref = OF_xref_from_device(provider_dev); + OF_device_register_xref(xref, NULL); +} +#endif Added: head/sys/dev/extres/hwreset/hwreset.h ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/sys/dev/extres/hwreset/hwreset.h Sun Jan 24 11:03:35 2016 (r294661) @@ -0,0 +1,67 @@ +/*- + * Copyright 2016 Michal Meloun + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef DEV_EXTRES_HWRESET_HWRESET_H +#define DEV_EXTRES_HWRESET_HWRESET_H + +#include "opt_platform.h" +#include +#ifdef FDT +#include +#endif + +typedef struct hwreset *hwreset_t; + +/* + * Provider interface + */ +#ifdef FDT +int hwreset_default_ofw_map(device_t provider_dev, phandle_t xref, int ncells, + pcell_t *cells, intptr_t *id); +void hwreset_register_ofw_provider(device_t provider_dev); +void hwreset_unregister_ofw_provider(device_t provider_dev); +#endif + +/* + * Consumer interface + */ +int hwreset_get_by_id(device_t consumer_dev, device_t provider_dev, intptr_t id, + hwreset_t *rst); +void hwreset_release(hwreset_t rst); + +int hwreset_assert(hwreset_t rst); +int hwreset_deassert(hwreset_t rst); +int hwreset_is_asserted(hwreset_t rst, bool *value); + +#ifdef FDT +int hwreset_get_by_ofw_name(device_t consumer_dev, char *name, hwreset_t *rst); +int hwreset_get_by_ofw_idx(device_t consumer_dev, int idx, hwreset_t *rst); +#endif + + + +#endif /* DEV_EXTRES_HWRESET_HWRESET_H */ Added: head/sys/dev/extres/hwreset/hwreset_if.m ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/sys/dev/extres/hwreset/hwreset_if.m Sun Jan 24 11:03:35 2016 (r294661) @@ -0,0 +1,72 @@ +#- +# Copyright 2016 Michal Meloun +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# +# $FreeBSD$ +# + +#ifdef FDT +#include +#include +#endif + +INTERFACE hwreset; + +#ifdef FDT +HEADER { +int hwreset_default_ofw_map(device_t , phandle_t, int, pcell_t *, intptr_t *); +} + +# +# map fdt property cells to reset id +# Returns 0 on success or a standard errno value. +# +METHOD int map { + device_t provider_dev; + phandle_t xref; + int ncells; + pcell_t *cells; + intptr_t *id; +} DEFAULT hwreset_default_ofw_map; +#endif + +# +# Assert/deassert given reset. +# Returns 0 on success or a standard errno value. +# +METHOD int assert { + device_t provider_dev; + intptr_t id; + bool value; +}; + +# +# Get actual status of given reset. +# Returns 0 on success or a standard errno value. +# +METHOD int is_asserted { + device_t provider_dev; + intptr_t id; + bool *value; +};