From patchwork Sat Feb 6 18:44:21 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: sdharia@codeaurora.org X-Patchwork-Id: 8243061 Return-Path: X-Original-To: patchwork-linux-arm-msm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id CF7739F8AA for ; Sat, 6 Feb 2016 18:46:47 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id C801820211 for ; Sat, 6 Feb 2016 18:46:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id BC27C2017D for ; Sat, 6 Feb 2016 18:46:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753028AbcBFSpH (ORCPT ); Sat, 6 Feb 2016 13:45:07 -0500 Received: from smtp.codeaurora.org ([198.145.29.96]:60440 "EHLO smtp.codeaurora.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753010AbcBFSpD (ORCPT ); Sat, 6 Feb 2016 13:45:03 -0500 Received: from smtp.codeaurora.org (localhost [127.0.0.1]) by smtp.codeaurora.org (Postfix) with ESMTP id 56B13604A2; Sat, 6 Feb 2016 18:45:02 +0000 (UTC) Received: by smtp.codeaurora.org (Postfix, from userid 1000) id 5134360537; Sat, 6 Feb 2016 18:45:02 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Spam-Level: X-Spam-Status: No, score=-7.3 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 Received: from sdharia-lnx.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: sdharia@smtp.codeaurora.org) by smtp.codeaurora.org (Postfix) with ESMTPSA id BB2A960445; Sat, 6 Feb 2016 18:44:58 +0000 (UTC) From: Sagar Dharia To: gregkh@linuxfoundation.org, bp@suse.de, poeschel@lemonage.de, sdharia@codeaurora.org, treding@nvidia.com, broonie@kernel.org, gong.chen@linux.intel.com, andreas.noever@gmail.com, alan@linux.intel.com, mathieu.poirier@linaro.org, daniel@ffwll.ch, oded.gabbay@amd.com, jkosina@suse.cz, sharon.dvir1@mail.huji.ac.il, joe@perches.com, davem@davemloft.net, james.hogan@imgtec.com, michael.opdenacker@free-electrons.com, daniel.thompson@linaro.org, robh+dt@kernel.org, pawel.moll@arm.com, mark.rutland@arm.com, ijc+devicetree@hellion.org.uk, galak@codeaurora.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Cc: kheitke@audience.com, mlocke@codeaurora.org, agross@codeaurora.org, linux-arm-msm@vger.kernel.org Subject: [PATCH V4 2/6] of/slimbus: OF helper for SLIMbus Date: Sat, 6 Feb 2016 11:44:21 -0700 Message-Id: <1454784265-5194-3-git-send-email-sdharia@codeaurora.org> X-Mailer: git-send-email 1.8.2.1 In-Reply-To: <1454784265-5194-1-git-send-email-sdharia@codeaurora.org> References: <1454784265-5194-1-git-send-email-sdharia@codeaurora.org> X-Virus-Scanned: ClamAV using ClamSMTP Sender: linux-arm-msm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP OF helper routine scans the SLIMbus DeviceTree, allocates resources, and creates slim_devices according to the hierarchy. Signed-off-by: Sagar Dharia --- Documentation/devicetree/bindings/slimbus/bus.txt | 54 ++++++++++++++++ drivers/slimbus/slim-core.c | 75 +++++++++++++++++++++++ 2 files changed, 129 insertions(+) create mode 100644 Documentation/devicetree/bindings/slimbus/bus.txt diff --git a/Documentation/devicetree/bindings/slimbus/bus.txt b/Documentation/devicetree/bindings/slimbus/bus.txt new file mode 100644 index 0000000..71c769d --- /dev/null +++ b/Documentation/devicetree/bindings/slimbus/bus.txt @@ -0,0 +1,54 @@ +SLIM(Serial Low Power Interchip Media Bus) bus + +SLIMbus is a 2-wire bus, and is used to communicate with peripheral +components like audio-codec. + +Controller is a normal device using binding for whatever bus it is +on (e.g. platform bus). +Required property for SLIMbus controller node: +- compatible - name of SLIMbus controller following generic names + recommended practice. +- #address-cells - should be 4 (number of cells required to define + 4 fields of the enumeration address for the SLIMbus + slave device) +- #size-cells - should be 0 + +No other properties are required in the SLIMbus controller bus node. + +Child nodes: +Every SLIMbus controller node can contain zero or more child nodes +representing slave devices on the bus. Every SLIMbus slave device is +uniquely determined by the enumeration address containing 4 fields: +Manufacturer ID, Product code, Device index, and Instance value for +the device. + +Required property for SLIMbus child node: +- reg - enumeration address fields of the device + +Optional: +- compatible - Slave devices can use compatible field to have a name. + If this field is missing, name of the device will be + determined using slave's enumeration address. + (e.g. in the example below, slave's name will be: + 0x217:0x60:0x1:0x0) + Note that the property is listed as optional since the + devices are discoverable when they are functional. + However, the device may need additional non-standard + way to power it up so that it can start functioning. + In that case, compatible property will be + needed for the corresponding driver to probe and + perform the required procedure to make it functional. + +SLIMbus example for Qualcomm's slimbus manager component: + + slim@28080000 { + compatible = "qcom,slim-msm"; + reg = <0x28080000 0x2000>, + interrupts = <0 33 0>; + clocks = <&lcc SLIMBUS_SRC>, <&lcc AUDIO_SLIMBUS_CLK>; + clock-names = "iface_clk", "core_clk"; + + codec_slave@0217.0060.01.00 { + reg = <0x217 0x60 0x1 0x0>; + }; + }; diff --git a/drivers/slimbus/slim-core.c b/drivers/slimbus/slim-core.c index 5b9fefa..4c2c646 100644 --- a/drivers/slimbus/slim-core.c +++ b/drivers/slimbus/slim-core.c @@ -18,6 +18,7 @@ #include #include #include +#include static DEFINE_MUTEX(slim_lock); static DEFINE_IDR(ctrl_idr); @@ -279,6 +280,79 @@ static LIST_HEAD(board_list); static LIST_HEAD(slim_ctrl_list); static DEFINE_MUTEX(board_lock); +#if IS_ENABLED(CONFIG_OF) +/* OF helpers for SLIMbus */ +static void of_register_slim_devices(struct slim_controller *ctrl) +{ + struct device_node *node; + struct slim_boardinfo *temp, *binfo = NULL; + int n = 0; + + if (!ctrl->dev.of_node) + return; + + for_each_child_of_node(ctrl->dev.of_node, node) { + int ret; + u32 ea[4]; + struct slim_device *slim; + char *name; + + ret = of_property_read_u32_array(node, "reg", ea, 4); + if (ret) { + dev_err(&ctrl->dev, "of_slim: E-addr err:%d\n", ret); + continue; + } + name = kcalloc(SLIMBUS_NAME_SIZE, sizeof(char), GFP_KERNEL); + if (!name) + goto of_slim_err; + + slim = kzalloc(sizeof(struct slim_device), GFP_KERNEL); + if (!slim) { + kfree(name); + goto of_slim_err; + } + slim->e_addr.manf_id = (u16)ea[0]; + slim->e_addr.prod_code = (u16)ea[1]; + slim->e_addr.dev_index = (u8)ea[2]; + slim->e_addr.instance = (u8)ea[3]; + + ret = of_modalias_node(node, name, SLIMBUS_NAME_SIZE); + if (ret < 0) { + /* use device address for name, if not specified */ + snprintf(name, SLIMBUS_NAME_SIZE, "0x%x:0x%x:0x%x:0x%x", + slim->e_addr.manf_id, slim->e_addr.prod_code, + slim->e_addr.dev_index, slim->e_addr.instance); + } + + temp = krealloc(binfo, (n + 1) * sizeof(struct slim_boardinfo), + GFP_KERNEL); + if (!temp) { + kfree(name); + kfree(slim); + goto of_slim_err; + } + binfo = temp; + slim->dev.of_node = of_node_get(node); + slim->name = name; + binfo[n].bus_num = ctrl->nr; + binfo[n].slim_slave = slim; + n++; + } + slim_register_board_info(binfo, n); + return; + +of_slim_err: + n--; + while (n >= 0) { + kfree(binfo[n].slim_slave->name); + kfree(binfo[n].slim_slave); + } + kfree(binfo); +} +#else +static void of_register_slim_devices(struct slim_controller *ctrl) { } +#endif + /* If controller is not present, only add to boards list */ static void slim_match_ctrl_to_boardinfo(struct slim_controller *ctrl, struct slim_boardinfo *bi) @@ -328,6 +402,7 @@ static void slim_ctrl_add_boarddevs(struct slim_controller *ctrl) { struct sbi_boardinfo *bi; + of_register_slim_devices(ctrl); mutex_lock(&board_lock); list_add_tail(&ctrl->list, &slim_ctrl_list); list_for_each_entry(bi, &board_list, list)