Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp3496363imm; Sun, 16 Sep 2018 20:24:37 -0700 (PDT) X-Google-Smtp-Source: ANB0VdbC2LY2w9fn7OrkAi51yYtTnekhUPUISjFQbsNzXL/eYklJkxuJKo7GA9Xg3NEd9eJ1fBiS X-Received: by 2002:a63:7353:: with SMTP id d19-v6mr21479092pgn.281.1537154677567; Sun, 16 Sep 2018 20:24:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537154677; cv=none; d=google.com; s=arc-20160816; b=ZM2bKnDnH6G9co+Zv/8qzWJlI8f4DjFPr8Gem0eh4rzuA8N97idEIfr0gPQlqBYCVY rKzGEUDpW1cDA58YBuXpFOE0NPnW63cX6d0TjmYXwabV4VElgpj2a+8dJ7gN/X0AArX3 0ZeziUmBEEF2LLxS5LAlXhIE70P/KdgtsJrzYk4RGvda+VpSXZ7tKInIvkPY58gCIU7e arqzyOY1ICgreQ0lsK7abHzx4ApLzvGnAuvinJ7zR1NBmUL6GBttz9JmdJpwz8UftHGQ ChGQKBODKn8cBXXJKGt/EU4Afn6Hff8QPucv6Dq2/lbbg7kpl+xSJ+ecnpg/OQF5gS2w 2pWg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:spamdiagnosticmetadata :spamdiagnosticoutput:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=97geI/AuB6OnrCBGjd8BpSO33JEu8pMzQlu6iTEhETI=; b=j3SQeLHHEZshihAjCQeReB6+QtCiZCqUDZhDXyrmecEGbxGGqWIpr7oRzTsmn9wdIw 5kePRAzeEtMKU9c9lCOUu64eLZYGQTVRbvz/hO0PpbPkaT0fNTl9TzENdUQnmzC8hgjf GukWVMBPKWqGQAHc4J9Re+Zq06LTErdGYKkvS8pFL4SqFJTnI3925uwK+pGseHPyG5nq UNf5+qB5B3HYDRdcFae7WBq5lSIcnrNWyNRUEb7Fvi7Fpz9ccVLN1Q7mpvB5mSirE2yH P5wJVE8aU5zdRj+6bvO99TxaD8Qe7HFhesWy9PzrszThoYkamB1SY9XXGr8u5EOfCnQW Mm5w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nxp.com header.s=selector1 header.b="dSC3T/tM"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=nxp.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j9-v6si14126891plk.153.2018.09.16.20.24.22; Sun, 16 Sep 2018 20:24:37 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-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=@nxp.com header.s=selector1 header.b="dSC3T/tM"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=nxp.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730433AbeIQIsl (ORCPT + 99 others); Mon, 17 Sep 2018 04:48:41 -0400 Received: from mail-ve1eur01on0074.outbound.protection.outlook.com ([104.47.1.74]:61156 "EHLO EUR01-VE1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1729632AbeIQIsk (ORCPT ); Mon, 17 Sep 2018 04:48:40 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=97geI/AuB6OnrCBGjd8BpSO33JEu8pMzQlu6iTEhETI=; b=dSC3T/tMTjejV4oii5sTACQIGujqC9oBV60EOQsDpmxGR3LQgxKXnSXBkS7G6l9govIzbFZVmT3bYdSJz7FE9vpWHKyTxk2cViFmLmg1uiorGbbpwAbISvPhN8/WXgCg/+LWvkH+MdhwS8wOe7de0Ti24HDenXb/bAB1kjhfPp0= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=anson.huang@nxp.com; Received: from anson-OptiPlex-790.ap.freescale.net (119.31.174.66) by AM0PR0402MB3906.eurprd04.prod.outlook.com (2603:10a6:208:f::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1143.18; Mon, 17 Sep 2018 03:23:09 +0000 From: Anson Huang To: shawnguo@kernel.org, s.hauer@pengutronix.de, kernel@pengutronix.de, fabio.estevam@nxp.com, robh+dt@kernel.org, mark.rutland@arm.com, rjw@rjwysocki.net, viresh.kumar@linaro.org, linux-arm-kernel@lists.infradead.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org Cc: Linux-imx@nxp.com Subject: [PATCH V2 2/2] cpufreq: imx6q: read OCOTP through nvmem for imx6ul/imx6ull Date: Mon, 17 Sep 2018 11:17:44 +0800 Message-Id: <1537154264-23252-2-git-send-email-Anson.Huang@nxp.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1537154264-23252-1-git-send-email-Anson.Huang@nxp.com> References: <1537154264-23252-1-git-send-email-Anson.Huang@nxp.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [119.31.174.66] X-ClientProxiedBy: HK0PR01CA0018.apcprd01.prod.exchangelabs.com (2603:1096:203:92::30) To AM0PR0402MB3906.eurprd04.prod.outlook.com (2603:10a6:208:f::26) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: b2544852-6e9d-4ecf-7533-08d61c4ce70b X-MS-Office365-Filtering-HT: Tenant X-Microsoft-Antispam: BCL:0;PCL:0;RULEID:(7020095)(4652040)(8989137)(4534165)(4627221)(201703031133081)(201702281549075)(8990107)(5600074)(711020)(4618075)(2017052603328)(7153060)(7193020);SRVR:AM0PR0402MB3906; X-Microsoft-Exchange-Diagnostics: 1;AM0PR0402MB3906;3:GpRzxfvojLnYLuWj5BjUMTJV+d2X8B1GcbUsaCVgowmI3X9tges0XG7Lnx+06kKR5IwWr7EypdUHQHj6dOM4Jw7Q7g69cl+UrobuRcC3jnvU/70Fz1aOS4bGjXA0voFCndkazFT+tFZCfYqCYe+pCP7dWyz7LA6VkYzNNyPBfuPpjSJg2dn8LAwyZ7NsprCPwVfZdu2asqhy+Z/IRjICHhjpIVFmAmNxBNVjd3Hvj9vYMiTcCp+HhraIIi/equtu;25:rpchA5cmTNBr0JFXvWyuU+splP3StOahZriMD+mG4zGwCQ73Im7/S5tOHx+KLbqjs2Iyzyl9DaZnc5eOLkHp8kyLhaWnWyK0cAvnBXSoYcnRz3bu9FsMHg9TM/SS9C7RHePNrIPhXvNqsDSofAODuvd8kVx5/Ra025n0IEdYWX/6AUv4Qewhr4V2A5npITu+u/Ggc4xdoiLwoMn2MzGAVNFLpqK8mnjvOkz7czB9RK8clmu7PHgotzUhZqLwfOAgluKwJ8hEe7KhFe0vtKkIGf8UH+c56WYdHPsbHLRA9c2ZN5bMUJIxmAq6fstroEsqa+R2AvUH7bpTujyPm11QgA==;31:euJZQc1sPzpIcAd2ylxo/ajV1cmdIorkAcJ9SuCQPHPMMkTN0l1kDw3IJLtB95vAAFMOPy0QbWtlKv6qE6f5DE6dJerjW1dVniSejCml6dQasiE2TJ+81wlglg1o2xl42RZP/QrQxqAO6njhIX9KUhmwpCNnn0z0P26YcbVQxrrlV/F8MlqCPqeW34eneim3iJgqsGey933X5iTw5wpH1jxqd72+6QYoNY9PygEOdpY= X-MS-TrafficTypeDiagnostic: AM0PR0402MB3906: X-Microsoft-Exchange-Diagnostics: 1;AM0PR0402MB3906;20:UYzjOFeK64Ndxtv3/e67vk1DfswnSdBrvMHclsiRTuK80h2j2g7M+UB/Uyz7DohWdPffCfqgHvoBU91ofkxHqvBZSWaDkoACJgNVglyI6e709aN1rRqK60pOyC24sD+0uLLgAO8NJIXIkK2gfWrUK3+LRZ6xWxTbV/N23vWGgqNEJ0ejZdKNB2G4x4ci8Ta9GXwmJnqzEwUu1pXZnl8XSCLa9Xi6QPcogk1cy9c9dE0FOL1kPKk5+s48xCn/LOGNjsjh2CxaLEnFufC9MmHlCfYycMTvZCTuYsoXWo3/zrLXVkv/GKFlyFjMbKmosDNN9cY+M9ViXC/qD5XxxL/csM8lzNPhrrZzwzY/JiORLVLuEl5n6SBnXkUyF3Ezj0n3TkA2ImNNkP+F2m0KMfPe5IX352wyN3N52CKlSXOxhS50siumH2jU14PtMbtL8yebonGo01+Yce4J2b/wJeU9KgIbOz+5qiBfiwXI96n2+ncn3I5mN2qWTF5pjBFvRgES;4:o6SH0qP7C3oaKgi6EiTL9BpexQBnX3ihRNeHSg7bs9r38AD+kZMfLqQx2z3b9x3w1lpQwXlhpQgHpR8JnYCjTWIvhmww2tPvuoryyJLUHK7gtrAsj4NrDLjgMyfiKJ60CX985OF1yuGU5vGx5XRSciHSXt5apolpmh3fAAgoNNeOMywauXXdbBNAiBRHKUjzwWeEFsnrFSMUgd/0AlkgtCzCLGyc1l8uLEjGpuhlWRPxNcUuDJS8CQhm6wA71cY47FHqT4N3QBcswqAlCI6ptYjxpJ8NgbcE482SumOAuTCUQK77YGZQGJZbTLYw9+o1 X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(185117386973197); X-MS-Exchange-SenderADCheck: 1 X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(8211001083)(6040522)(2401047)(8121501046)(5005006)(3002001)(10201501046)(93006095)(93001095)(3231355)(944501410)(52105095)(6055026)(149027)(150027)(6041310)(20161123564045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123560045)(20161123562045)(20161123558120)(201708071742011)(7699050);SRVR:AM0PR0402MB3906;BCL:0;PCL:0;RULEID:;SRVR:AM0PR0402MB3906; X-Forefront-PRVS: 0798146F16 X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10009020)(136003)(396003)(346002)(366004)(39860400002)(376002)(199004)(189003)(956004)(11346002)(186003)(3846002)(5660300001)(6506007)(486006)(16586007)(386003)(2616005)(316002)(36756003)(6116002)(52116002)(476003)(76176011)(114624004)(16526019)(48376002)(51416003)(446003)(6512007)(47776003)(2906002)(106356001)(7416002)(50226002)(25786009)(68736007)(50466002)(105586002)(81166006)(81156014)(6666003)(7736002)(305945005)(8676002)(4326008)(8936002)(86362001)(97736004)(66066001)(26005)(53936002)(478600001)(6486002)(921003)(32563001)(1121003);DIR:OUT;SFP:1101;SCL:1;SRVR:AM0PR0402MB3906;H:anson-OptiPlex-790.ap.freescale.net;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;A:1;MX:1; Received-SPF: None (protection.outlook.com: nxp.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1;AM0PR0402MB3906;23:i5TPL258B6Bx/ZzWajHadOHOkjsI+GINL+txylQ?= =?us-ascii?Q?cs3R8kW3G9rTc56PNmHQIJHeLt0ar8jntces9YSyBcHPrrxWLyCD5/rnHf40?= =?us-ascii?Q?odDKm58xSVzVuPbxJuS7hTwN7IzUJkN5/qlxteveE84WOAXJGjagmq9tYKDK?= =?us-ascii?Q?N/s9a0V5MCdPP1Fhoe9C5UnCqZJ61RM5RiQc4lufKwMmR46YvnCkculWvYPf?= =?us-ascii?Q?jm8rnuKDGGZZJe0D3uG28ljiLLeKKFM/EBym7zbWgaqXrKFww9pOaXntfYls?= =?us-ascii?Q?MMqTIOUab7r1rx26o3tCm0qIowT5MLg2+Jm4XfK3h0WKCPARcXsy0GD6Jbhu?= =?us-ascii?Q?zKWj58gvAKs0Ur91xZ1ax+ooNeNvqWV+gT0+WdrAcY0WBSPsOg2TO7nehdo4?= =?us-ascii?Q?fk5ezy8YuSiK4QMmYm3JxlLBnegcT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1DcaUeqxXV8FMqV/P5vtQ4bDZE856sOyr/Gv83ViCClnua0fQOB2Egz3x4euoLmeAsLFfwq0IIYJuVwYHmrkeRI0mD7sPIe6s3a7DE5c/Nl5Nymjs3RcGBoGmf37oja8XyOy0anzaTNbQWRDWcD7rC9OKOP3qzfYbMyWiPbOUg6Q71E+fKuCf7KG/v296ypnbMBsgO6SM/1P8VatKz SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Sep 2018 03:23:09.9664 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: b2544852-6e9d-4ecf-7533-08d61c4ce70b X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR0402MB3906 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On i.MX6UL/i.MX6ULL, accessing OCOTP directly is wrong because the ocotp clock needs to be enabled first. Add support for reading OCOTP through the nvmem API, and keep the old method there to support old dtb. Signed-off-by: Anson Huang --- changes since V1: add old dtb support. drivers/cpufreq/imx6q-cpufreq.c | 52 +++++++++++++++++++++++++++-------------- 1 file changed, 35 insertions(+), 17 deletions(-) diff --git a/drivers/cpufreq/imx6q-cpufreq.c b/drivers/cpufreq/imx6q-cpufreq.c index b2ff423..518386c4 100644 --- a/drivers/cpufreq/imx6q-cpufreq.c +++ b/drivers/cpufreq/imx6q-cpufreq.c @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -290,20 +291,32 @@ static void imx6q_opp_check_speed_grading(struct device *dev) #define OCOTP_CFG3_6ULL_SPEED_792MHZ 0x2 #define OCOTP_CFG3_6ULL_SPEED_900MHZ 0x3 -static void imx6ul_opp_check_speed_grading(struct device *dev) +static int imx6ul_opp_check_speed_grading(struct device *dev) { - struct device_node *np; - void __iomem *base; u32 val; + int ret = 0; - np = of_find_compatible_node(NULL, NULL, "fsl,imx6ul-ocotp"); - if (!np) - return; + if (of_find_property(dev->of_node, "nvmem-cells", NULL)) { + ret = nvmem_cell_read_u32(dev, "speed_grade", &val); + if (ret) + return ret; + } else { + struct device_node *np; + void __iomem *base; + + np = of_find_compatible_node(NULL, NULL, "fsl,imx6ul-ocotp"); + if (!np) + return -ENOENT; + + base = of_iomap(np, 0); + if (!base) { + dev_err(dev, "failed to map ocotp\n"); + of_node_put(np); + return -EFAULT; + } - base = of_iomap(np, 0); - if (!base) { - dev_err(dev, "failed to map ocotp\n"); - goto put_node; + val = readl_relaxed(base + OCOTP_CFG3); + iounmap(base); } /* @@ -314,7 +327,6 @@ static void imx6ul_opp_check_speed_grading(struct device *dev) * 2b'11: 900000000Hz on i.MX6ULL only; * We need to set the max speed of ARM according to fuse map. */ - val = readl_relaxed(base + OCOTP_CFG3); val >>= OCOTP_CFG3_SPEED_SHIFT; val &= 0x3; @@ -334,9 +346,7 @@ static void imx6ul_opp_check_speed_grading(struct device *dev) dev_warn(dev, "failed to disable 900MHz OPP\n"); } - iounmap(base); -put_node: - of_node_put(np); + return ret; } static int imx6q_cpufreq_probe(struct platform_device *pdev) @@ -394,10 +404,18 @@ static int imx6q_cpufreq_probe(struct platform_device *pdev) } if (of_machine_is_compatible("fsl,imx6ul") || - of_machine_is_compatible("fsl,imx6ull")) - imx6ul_opp_check_speed_grading(cpu_dev); - else + of_machine_is_compatible("fsl,imx6ull")) { + ret = imx6ul_opp_check_speed_grading(cpu_dev); + if (ret == -EPROBE_DEFER) + return ret; + if (ret) { + dev_err(cpu_dev, "failed to read ocotp: %d\n", + ret); + return ret; + } + } else { imx6q_opp_check_speed_grading(cpu_dev); + } /* Because we have added the OPPs here, we must free them */ free_opp = true; -- 2.7.4