From patchwork Thu Jun 6 16:30:41 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Grygorii Strashko X-Patchwork-Id: 165996 Delivered-To: patch@linaro.org Received: by 2002:a92:9e1a:0:0:0:0:0 with SMTP id q26csp9012730ili; Thu, 6 Jun 2019 09:31:41 -0700 (PDT) X-Google-Smtp-Source: APXvYqzz7h7M2RoRkX2hW1cWPiR96dB8XYEwuS8T4xg0kY0pWLKwq36Zr9pWGztsvKRh36bvT9fF X-Received: by 2002:a17:902:9897:: with SMTP id s23mr47602120plp.139.1559838700930; Thu, 06 Jun 2019 09:31:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559838700; cv=none; d=google.com; s=arc-20160816; b=hQvABeOFAeYCowcDZu+vg0DM+boGyCERoTetP0gtZV7NfJCMpAWYSEcoOze+VYLI6H HwEwf12ezVYsUBxear4yUqBUQYRTP7wYhvezA9vfdwyBRf8k6xFqWyWcAXqtdoY0NWra 6+EeSb38karRUI1B5bA1Jv3yCTpwsmsVu0O7+gMvLOOQpQkkQVoFDbGieudcoHsm12eZ /HiPLu+FexJK+6PZboFa1pl06ZQ8f3PtOyPVMvfdi+o1n82UZbgxnusl29+pRP1RlRQQ nmPuXdVbx24Si7ROxEaDQmuKF2lTNvvhbTTamb1SAXydAkqDnjbaG07OfB3N9H85/74y 2rfA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=MwfT++VN1Q8SFfYZPQ1nyXL9tf0XJigqffqFWo4XOL0=; b=d587IkA2vTrrrWhZ5mXD+BXYNgS4dycLr6eeQcfFha9kBeGupG10c509zS9hvrH7F1 /UOX2lmkGKIDr/HRUL8IVqOWEPlO7Mvxlb+T2UlSRnGBz8u5eHg+9+MiQ7IFndWXnDFd ftazOtZvgjrrmKoFSk4+CLLyFlsBWFHlZzOcaHofdCKz9Kkopb3Ym80MkQZtqBGmCbY+ nimEupBZ1zV89MvmHKgmoqFaswZ5l9NVImfd8rlf6CmLrme7FdoVbT+qLGAy7InEfC4X STcAYxIz1k9G/NbCldCkuGC/z/aMFypYogoFu39Rn7Kk+JcbDFp24fVwnsNk4I44oskK iGLg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b="Z9/3hJEm"; spf=pass (google.com: best guess record for domain of netdev-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=netdev-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r185si2336198pgr.10.2019.06.06.09.31.40; Thu, 06 Jun 2019 09:31:40 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of netdev-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b="Z9/3hJEm"; spf=pass (google.com: best guess record for domain of netdev-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=netdev-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729755AbfFFQbk (ORCPT + 9 others); Thu, 6 Jun 2019 12:31:40 -0400 Received: from lelv0143.ext.ti.com ([198.47.23.248]:54192 "EHLO lelv0143.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729745AbfFFQbi (ORCPT ); Thu, 6 Jun 2019 12:31:38 -0400 Received: from lelv0265.itg.ti.com ([10.180.67.224]) by lelv0143.ext.ti.com (8.15.2/8.15.2) with ESMTP id x56GVM6I064604; Thu, 6 Jun 2019 11:31:22 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1559838682; bh=MwfT++VN1Q8SFfYZPQ1nyXL9tf0XJigqffqFWo4XOL0=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=Z9/3hJEm8B4Z+HEUtpsuIegHlSbxlBan5DN8vKeq7fPGVZ5XXeIpxVhT4Ima9GFsB IcVCiSoSHvB7L41vKuFTptGEiEtF3oOxHUdQrk6ZLmIE3ox8JZxxqBB1nGjrAsMRXJ XuTTGlg9clZku7C4l7LPOV55ZsLmH8LgMQfYR8c8= Received: from DFLE112.ent.ti.com (dfle112.ent.ti.com [10.64.6.33]) by lelv0265.itg.ti.com (8.15.2/8.15.2) with ESMTPS id x56GVMMa006861 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Thu, 6 Jun 2019 11:31:22 -0500 Received: from DFLE102.ent.ti.com (10.64.6.23) by DFLE112.ent.ti.com (10.64.6.33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1713.5; Thu, 6 Jun 2019 11:31:21 -0500 Received: from fllv0040.itg.ti.com (10.64.41.20) by DFLE102.ent.ti.com (10.64.6.23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1713.5 via Frontend Transport; Thu, 6 Jun 2019 11:31:21 -0500 Received: from localhost (ileax41-snat.itg.ti.com [10.172.224.153]) by fllv0040.itg.ti.com (8.15.2/8.15.2) with ESMTP id x56GVKsY055672; Thu, 6 Jun 2019 11:31:21 -0500 From: Grygorii Strashko To: "David S. Miller" , Santosh Shilimkar , Richard Cochran , Rob Herring CC: Sekhar Nori , Murali Karicheri , Wingman Kwok , , , , , Grygorii Strashko Subject: [PATCH net-next v2 04/10] net: ethernet: ti: cpts: add support for ext rftclk selection Date: Thu, 6 Jun 2019 19:30:41 +0300 Message-ID: <20190606163047.31199-5-grygorii.strashko@ti.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190606163047.31199-1-grygorii.strashko@ti.com> References: <20190606163047.31199-1-grygorii.strashko@ti.com> MIME-Version: 1.0 X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Some CPTS instances, which can be found on KeyStone 2 1G Ethernet Switch Subsystems, can control an external multiplexer that selects one of up to 32 clocks as time sync reference (RFTCLK) clock. This feature can be configured through CPTS_RFTCLK_SEL register (offset: x08) in CPTS module and can be represented as multiplexer clock. Hence, introduce support for optional cpts-refclk-mux clock, which, once defined will allow to select required CPTS RFTCLK by using assigned-clock-parents DT property in board files. Signed-off-by: Grygorii Strashko Acked-by: Richard Cochran --- drivers/net/ethernet/ti/cpts.c | 79 +++++++++++++++++++++++++++++++++- drivers/net/ethernet/ti/cpts.h | 2 +- 2 files changed, 79 insertions(+), 2 deletions(-) -- 2.17.1 diff --git a/drivers/net/ethernet/ti/cpts.c b/drivers/net/ethernet/ti/cpts.c index 0e79f9743c19..61136428e2c0 100644 --- a/drivers/net/ethernet/ti/cpts.c +++ b/drivers/net/ethernet/ti/cpts.c @@ -5,6 +5,7 @@ * Copyright (C) 2012 Richard Cochran * */ +#include #include #include #include @@ -532,6 +533,82 @@ static void cpts_calc_mult_shift(struct cpts *cpts) freq, cpts->cc.mult, cpts->cc.shift, (ns - NSEC_PER_SEC)); } +static int cpts_of_mux_clk_setup(struct cpts *cpts, struct device_node *node) +{ + struct device_node *refclk_np; + const char **parent_names; + unsigned int num_parents; + struct clk_hw *clk_hw; + int ret = -EINVAL; + u32 *mux_table; + + refclk_np = of_get_child_by_name(node, "cpts-refclk-mux"); + if (!refclk_np) + /* refclk selection supported not for all SoCs */ + return 0; + + num_parents = of_clk_get_parent_count(refclk_np); + if (num_parents < 1) { + dev_err(cpts->dev, "mux-clock %s must have parents\n", + refclk_np->name); + goto mux_fail; + } + + parent_names = devm_kzalloc(cpts->dev, (sizeof(char *) * num_parents), + GFP_KERNEL); + + mux_table = devm_kzalloc(cpts->dev, sizeof(*mux_table) * num_parents, + GFP_KERNEL); + if (!mux_table || !parent_names) { + ret = -ENOMEM; + goto mux_fail; + } + + of_clk_parent_fill(refclk_np, parent_names, num_parents); + + ret = of_property_read_variable_u32_array(refclk_np, "ti,mux-tbl", + mux_table, + num_parents, num_parents); + if (ret < 0) + goto mux_fail; + + clk_hw = clk_hw_register_mux_table(cpts->dev, refclk_np->name, + parent_names, num_parents, + 0, + &cpts->reg->rftclk_sel, 0, 0x1F, + 0, mux_table, NULL); + if (IS_ERR(clk_hw)) { + ret = PTR_ERR(clk_hw); + goto mux_fail; + } + + ret = devm_add_action_or_reset(cpts->dev, + (void(*)(void *))clk_hw_unregister_mux, + clk_hw); + if (ret) { + dev_err(cpts->dev, "add clkmux unreg action %d", ret); + goto mux_fail; + } + + ret = of_clk_add_hw_provider(refclk_np, of_clk_hw_simple_get, clk_hw); + if (ret) + goto mux_fail; + + ret = devm_add_action_or_reset(cpts->dev, + (void(*)(void *))of_clk_del_provider, + refclk_np); + if (ret) { + dev_err(cpts->dev, "add clkmux provider unreg action %d", ret); + goto mux_fail; + } + + return ret; + +mux_fail: + of_node_put(refclk_np); + return ret; +} + static int cpts_of_parse(struct cpts *cpts, struct device_node *node) { int ret = -EINVAL; @@ -547,7 +624,7 @@ static int cpts_of_parse(struct cpts *cpts, struct device_node *node) (!cpts->cc.mult && cpts->cc.shift)) goto of_error; - return 0; + return cpts_of_mux_clk_setup(cpts, node); of_error: dev_err(cpts->dev, "CPTS: Missing property in the DT.\n"); diff --git a/drivers/net/ethernet/ti/cpts.h b/drivers/net/ethernet/ti/cpts.h index 024aab6af12f..bb997c11ee15 100644 --- a/drivers/net/ethernet/ti/cpts.h +++ b/drivers/net/ethernet/ti/cpts.h @@ -24,7 +24,7 @@ struct cpsw_cpts { u32 idver; /* Identification and version */ u32 control; /* Time sync control */ - u32 res1; + u32 rftclk_sel; /* Reference Clock Select Register */ u32 ts_push; /* Time stamp event push */ u32 ts_load_val; /* Time stamp load value */ u32 ts_load_en; /* Time stamp load enable */