From owner-svn-src-all@freebsd.org Wed Aug 12 17:23:16 2015 Return-Path: Delivered-To: svn-src-all@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 76D1299F9CC; Wed, 12 Aug 2015 17:23:16 +0000 (UTC) (envelope-from ian@FreeBSD.org) Received: from repo.freebsd.org (repo.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 4EE0B63C; Wed, 12 Aug 2015 17:23:16 +0000 (UTC) (envelope-from ian@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.70]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id t7CHNGfZ041784; Wed, 12 Aug 2015 17:23:16 GMT (envelope-from ian@FreeBSD.org) Received: (from ian@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id t7CHNFWm041782; Wed, 12 Aug 2015 17:23:15 GMT (envelope-from ian@FreeBSD.org) Message-Id: <201508121723.t7CHNFWm041782@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: ian set sender to ian@FreeBSD.org using -f From: Ian Lepore Date: Wed, 12 Aug 2015 17:23:15 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r286678 - head/sys/arm/ti X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 12 Aug 2015 17:23:16 -0000 Author: ian Date: Wed Aug 12 17:23:15 2015 New Revision: 286678 URL: https://svnweb.freebsd.org/changeset/base/286678 Log: Add a routine to return the hardware instance/unit number from ti,hwmods, given the hardware name. The ti,hwmods property is used (among other things) to associate an fdt node with a specific instance of some hardware. For example given a device node that contains the property ti,hwmods = "timer3", if you call this passing "timer" as the hwmod string to look for it would return 3. Modified: head/sys/arm/ti/ti_hwmods.c head/sys/arm/ti/ti_hwmods.h Modified: head/sys/arm/ti/ti_hwmods.c ============================================================================== --- head/sys/arm/ti/ti_hwmods.c Wed Aug 12 17:21:41 2015 (r286677) +++ head/sys/arm/ti/ti_hwmods.c Wed Aug 12 17:23:15 2015 (r286678) @@ -168,3 +168,35 @@ int ti_hwmods_contains(device_t dev, con return (result); } + +int +ti_hwmods_get_unit(device_t dev, const char *hwmod) +{ + phandle_t node; + int l, len, hwmodlen, result; + char *name; + char *buf; + + if ((node = ofw_bus_get_node(dev)) == 0) + return (0); + + if ((len = OF_getprop_alloc(node, "ti,hwmods", 1, (void**)&name)) <= 0) + return (0); + + buf = name; + hwmodlen = strlen(hwmod); + result = 0; + while (len > 0) { + if (strncmp(name, hwmod, hwmodlen) == 0) { + result = (int)strtoul(name + hwmodlen, NULL, 10); + break; + } + /* Slide to the next sub-string. */ + l = strlen(name) + 1; + name += l; + len -= l; + } + + free(buf, M_OFWPROP); + return (result); +} Modified: head/sys/arm/ti/ti_hwmods.h ============================================================================== --- head/sys/arm/ti/ti_hwmods.h Wed Aug 12 17:21:41 2015 (r286677) +++ head/sys/arm/ti/ti_hwmods.h Wed Aug 12 17:23:15 2015 (r286678) @@ -31,4 +31,7 @@ clk_ident_t ti_hwmods_get_clock(device_t dev); int ti_hwmods_contains(device_t dev, const char *hwmod); +/* Returns the N from "hwmodN" in the ti,hwmods property; 0 on failure. */ +int ti_hwmods_get_unit(device_t dev, const char *hwmod); + #endif /* _TI_HWMODS_H_ */