From patchwork Sun Sep 20 04:29:57 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Scott Wood X-Patchwork-Id: 7225411 Return-Path: X-Original-To: patchwork-linux-pm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 8B598BEEC1 for ; Sun, 20 Sep 2015 04:30:39 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 747C12073C for ; Sun, 20 Sep 2015 04:30:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 419412075A for ; Sun, 20 Sep 2015 04:30:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751931AbbITEab (ORCPT ); Sun, 20 Sep 2015 00:30:31 -0400 Received: from mail-by2on0103.outbound.protection.outlook.com ([207.46.100.103]:40384 "EHLO na01-by2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751578AbbITEa1 (ORCPT ); Sun, 20 Sep 2015 00:30:27 -0400 Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=scottwood@freescale.com; Received: from snotra.am.freescale.net (192.88.168.49) by BLUPR03MB1473.namprd03.prod.outlook.com (10.163.81.158) with Microsoft SMTP Server (TLS) id 15.1.274.16; Sun, 20 Sep 2015 04:30:13 +0000 From: Scott Wood To: Michael Turquette , Stephen Boyd , "Rafael J. Wysocki" , Viresh Kumar , Russell King CC: , , , , "Tang Yuantian" , Scott Wood Subject: [PATCH v3 5/5] cpufreq: qoriq: Don't look at clock implementation details Date: Sat, 19 Sep 2015 23:29:57 -0500 Message-ID: <1442723397-26329-6-git-send-email-scottwood@freescale.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1442723397-26329-1-git-send-email-scottwood@freescale.com> References: <1442723397-26329-1-git-send-email-scottwood@freescale.com> MIME-Version: 1.0 X-Originating-IP: [192.88.168.49] X-ClientProxiedBy: SN1PR07CA0011.namprd07.prod.outlook.com (25.162.170.149) To BLUPR03MB1473.namprd03.prod.outlook.com (25.163.81.158) X-Microsoft-Exchange-Diagnostics: 1; BLUPR03MB1473; 2:4PivIMpQIDg8OOwl9nqbNJNSctkitAIAtAAOa7hl10uN2uvIqD3Cwh+SmGhdaj+HXiefS50fvCtxWmVyFIopaOebfJcZ8OlzyMkecvr8Xz7vMzs2Q/MK9zSv02bmziKfuBt0u40K5Bgqy+glav7mz01kpIbyeGYuvu3MssNZNpQ=; 3:evpMHDpaNlBc0prWGBtXtieoCdRseqBH7xG8v+pnVQwK0wjo9knQ5jXI4dHTZCWYGEjguvlwktIj/VuAzuT3/vgAaHpTrovHRksuOLhGz2XXgbgo0ttBslrss+LsH4+v5Rfr5KTBLBsaOeKf6x+y3g==; 25:3eVB4tgCnBfq0zvTqQcgdpSMAbrYOE9qF9G9r8LmJtjSHlPCmes0lGzbwh6IDUhUPk6zZb671YuhMMvyagG+9Opvr7zND+laK7yXGrboYYgmY69X6VnkzLH0oqNYxPL5IUXlbepbFeUv0Ao7+WendoyVvaQ3UqujoL1IYnUeaEU44fNpDT+YOMMVGs6lXJIXRCpOlOPJjUUSAQhmjTjqWaOrR8arLLq93vh93LpUGrT7kj93mhJDEM0JTw/1w2DppxKM+1OkMDwGZALpsB0HwQ== X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:BLUPR03MB1473; X-Microsoft-Exchange-Diagnostics: 1; BLUPR03MB1473; 20:L9njWDt1KdAETeIIj2F84DFF42FMik2KpacFcjTGXYV8xu+cNiXA04Tya+FS+q3KckhPxJjsQhJ49zIQ8Z3MMWa8hA5bBUxk3qKP5NPe1dAu8BhAdhJLJbRTlIsPsuIWxppO+F6J+I6NeoghVHzK0axQS16K4bLCqsDtCq3bG5CItnBB6sVyzmExDHxooH+/l44R4LIQee9w18DLASbOkW3/5K0+7VDDsr9HHARHESgENOdYm6f5sTPy18xL6lxWl2X/aWQS3511+hKyTVnPwZTq8cTOdpiVy13r1mJT9IO9w7ZSnHpPzEQZA0K+zKKUBvLq+BeLAuyaietHurOCi4S3Thcgn7CMwDWKm3nCfO/GF+RKpljvLd6mPZOVA6oC3GqDs6X4wCol2TrX8jQjfQQysPbTprucol9zD7LtnKbKdrwwMHtZYfoYKYWQN6DbItvyDeobpujGjPqOdmPoGQpNYkcfdEtTV8sLSbUbQQi3VLTVDOLO8a6TYPb6ZlAX; 4:ObXLVdUxvQeI1rVAAyGnKYl+oFQ595v7c8rXPVm25Uz6CmmdhMXV0oyoFxVt5ZUYcBwccqWZ+LTDXdSfr8DBEYmkBIMq2SjXDhOILBxVom7borh5U9jzUuN+lSXODDQmIPqCQRDq7eQnztEZE9SOmB2yqwr4XdWgvqlEBlH9MCI3M3v5weccs4TI89gAXXEshZweqEq0IU0q7okWFUGDOapU18BkLeLx8N+MWKcC6qmsf0Xs2FLu+VFMN1JgO0wJtRHp3V6w4zLpSd31sL5/y1ayum4nxM+fARrcTpAn9FWyzXcAlvnc4uuHhDuqOxzXve3d29RLjpo9/O6lJOl+9w== X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(601004)(8121501046)(5005006)(520078)(3002001); SRVR:BLUPR03MB1473; BCL:0; PCL:0; RULEID:; SRVR:BLUPR03MB1473; X-Forefront-PRVS: 0705EB1700 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(6009001)(199003)(189002)(229853001)(76176999)(107886002)(5003940100001)(97736004)(81156007)(50986999)(66066001)(5001860100001)(5004730100002)(5007970100001)(4001540100001)(5001830100001)(87976001)(5001770100001)(5001960100002)(36756003)(86362001)(42186005)(64706001)(189998001)(77156002)(47776003)(62966003)(92566002)(46102003)(122386002)(40100003)(77096005)(68736005)(33646002)(50226001)(106356001)(2950100001)(105586002)(48376002)(19580405001)(50466002)(101416001)(19580395003)(21314002)(4001430100001); DIR:OUT; SFP:1102; SCL:1; SRVR:BLUPR03MB1473; H:snotra.am.freescale.net; FPR:; SPF:None; PTR:InfoNoRecords; A:1; MX:1; LANG:en; Received-SPF: None (protection.outlook.com: freescale.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; BLUPR03MB1473; 23:KYHT8kbYJlgOBnYaYutEazHK9k3N1O1LBbTZ0nlhH?= =?us-ascii?Q?LhoKxNaRtv2naE7Aal/u4tVcpIVZ28owtLLi8vvpolSzBbAcVigVBHmck3rt?= =?us-ascii?Q?Md1qFRptZVg1p5/2umt38vQWhzIdEnzpcde+xUJ3vHahtNHRpLDUG6z2rWPQ?= =?us-ascii?Q?ldS6aux7zO2UZfuGm5HDkgG1lZYJhnQKwmup2/kH+IywNJeUp5McvxCPpNXo?= =?us-ascii?Q?TxX0ZSoX/umanG8hfsqa4JjGWAyNiRct001X8PQmrQ+cvvTX1EZRHieQDHFF?= =?us-ascii?Q?I0Pg+vgmbyvw5ye7ni4nNaM/U+z7f5u6j7Iret2mqGlbHn2H7FL9ttZcoB0h?= =?us-ascii?Q?LlIQMeE8tcYuEQTB2WkY1U8dBlmZdMMYZJt+615B+rbNPZIRtvQDkKgNRaCc?= =?us-ascii?Q?mUe7G/nAhVrLqm1u8jyeOdSClp1IWdxh70fRr+v/6vF2rdgrsQaDntoucOES?= =?us-ascii?Q?2vNLyxEiRfCz2w5BtgAEyo6qWlJmqDaJcxEfBX9Y/dTGpZJj54KmETunIWTU?= =?us-ascii?Q?D4aNYW5Uoi1mAXGhvl0zwpIax8GZRQwrzfKaTNSH8seMRUD07k3Pq6KKQPFF?= =?us-ascii?Q?t6fXKBPzAVWoqZ9mrRd2V0e7p2hP5UxzrF76IxJJarO5QUhDoCRxLg2PZ4hq?= =?us-ascii?Q?ClUaBS7FKAq467Cqov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SLKeOsmPk6nqnE8GoJZ/htuElm7wGYFZP5/bGkPSbEihhAx4XgRdRD1Yr9g76zBBjxMTT8w== X-OriginatorOrg: freescale.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Sep 2015 04:30:13.6738 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: BLUPR03MB1473 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Get the CPU clock's potential parent clocks from the clock interface itself, rather than manually parsing the clocks property to find a phandle, looking at the clock-names property of that, and assuming that those are valid parent clocks for the cpu clock. This is necessary now that the clocks are generated based on the clock driver's knowledge of the chip rather than a fragile device-tree description of the mux options. We can now rely on the clock driver to ensure that the mux only exposes options that are valid. The cpufreq driver was currently being overly conservative in some cases -- for example, the "min_cpufreq = get_bus_freq()" restriction only applies to chips with erratum A-004510, and whether the freq_mask used on p5020 is needed depends on the actual frequencies of the PLLs (FWIW, p5040 has a similar limitation but its .freq_mask was zero) -- and the frequency mask mechanism made assumptions about particular parent clock indices that are no longer valid. Signed-off-by: Scott Wood Acked-by: Viresh Kumar Signed-off-by: Scott Wood --- v3: was patch 1/5 and patch 4/5, plus blacklist e6500 and changes to clk api usage drivers/cpufreq/qoriq-cpufreq.c | 137 ++++++++++++---------------------------- 1 file changed, 40 insertions(+), 97 deletions(-) diff --git a/drivers/cpufreq/qoriq-cpufreq.c b/drivers/cpufreq/qoriq-cpufreq.c index 358f075..4f53fa2 100644 --- a/drivers/cpufreq/qoriq-cpufreq.c +++ b/drivers/cpufreq/qoriq-cpufreq.c @@ -35,53 +35,20 @@ struct cpu_data { struct cpufreq_frequency_table *table; }; +/* + * Don't use cpufreq on this SoC -- used when the SoC would have otherwise + * matched a more generic compatible. + */ +#define SOC_BLACKLIST 1 + /** * struct soc_data - SoC specific data - * @freq_mask: mask the disallowed frequencies - * @flag: unique flags + * @flags: SOC_xxx */ struct soc_data { - u32 freq_mask[4]; - u32 flag; -}; - -#define FREQ_MASK 1 -/* see hardware specification for the allowed frqeuencies */ -static const struct soc_data sdata[] = { - { /* used by p2041 and p3041 */ - .freq_mask = {0x8, 0x8, 0x2, 0x2}, - .flag = FREQ_MASK, - }, - { /* used by p5020 */ - .freq_mask = {0x8, 0x2}, - .flag = FREQ_MASK, - }, - { /* used by p4080, p5040 */ - .freq_mask = {0}, - .flag = 0, - }, + u32 flags; }; -/* - * the minimum allowed core frequency, in Hz - * for chassis v1.0, >= platform frequency - * for chassis v2.0, >= platform frequency / 2 - */ -static u32 min_cpufreq; -static const u32 *fmask; - -#if defined(CONFIG_ARM) -static int get_cpu_physical_id(int cpu) -{ - return topology_core_id(cpu); -} -#else -static int get_cpu_physical_id(int cpu) -{ - return get_hard_smp_processor_id(cpu); -} -#endif - static u32 get_bus_freq(void) { struct device_node *soc; @@ -99,9 +66,10 @@ static u32 get_bus_freq(void) return sysfreq; } -static struct device_node *cpu_to_clk_node(int cpu) +static struct clk *cpu_to_clk(int cpu) { - struct device_node *np, *clk_np; + struct device_node *np; + struct clk *clk; if (!cpu_present(cpu)) return NULL; @@ -110,37 +78,28 @@ static struct device_node *cpu_to_clk_node(int cpu) if (!np) return NULL; - clk_np = of_parse_phandle(np, "clocks", 0); - if (!clk_np) - return NULL; - + clk = of_clk_get(np, 0); of_node_put(np); - - return clk_np; + return clk; } /* traverse cpu nodes to get cpu mask of sharing clock wire */ static void set_affected_cpus(struct cpufreq_policy *policy) { - struct device_node *np, *clk_np; struct cpumask *dstp = policy->cpus; + struct clk *clk; int i; - np = cpu_to_clk_node(policy->cpu); - if (!np) - return; - for_each_present_cpu(i) { - clk_np = cpu_to_clk_node(i); - if (!clk_np) + clk = cpu_to_clk(i); + if (IS_ERR(clk)) { + pr_err("%s: no clock for cpu %d\n", __func__, i); continue; + } - if (clk_np == np) + if (clk_is_match(policy->clk, clk)) cpumask_set_cpu(i, dstp); - - of_node_put(clk_np); } - of_node_put(np); } /* reduce the duplicated frequencies in frequency table */ @@ -198,7 +157,7 @@ static int qoriq_cpufreq_cpu_init(struct cpufreq_policy *policy) { struct device_node *np, *pnode; int i, count, ret; - u32 freq, mask; + u32 freq; struct clk *clk; struct cpufreq_frequency_table *table; struct cpu_data *data; @@ -219,17 +178,12 @@ static int qoriq_cpufreq_cpu_init(struct cpufreq_policy *policy) goto err_nomem2; } - pnode = of_parse_phandle(np, "clocks", 0); - if (!pnode) { - pr_err("%s: could not get clock information\n", __func__); - goto err_nomem2; - } + count = clk_get_num_parents(policy->clk); - count = of_property_count_strings(pnode, "clock-names"); data->pclk = kcalloc(count, sizeof(struct clk *), GFP_KERNEL); if (!data->pclk) { pr_err("%s: no memory\n", __func__); - goto err_node; + goto err_nomem2; } table = kcalloc(count + 1, sizeof(*table), GFP_KERNEL); @@ -238,23 +192,11 @@ static int qoriq_cpufreq_cpu_init(struct cpufreq_policy *policy) goto err_pclk; } - if (fmask) - mask = fmask[get_cpu_physical_id(cpu)]; - else - mask = 0x0; - for (i = 0; i < count; i++) { - clk = of_clk_get(pnode, i); + clk = clk_get_parent_by_index(policy->clk, i); data->pclk[i] = clk; freq = clk_get_rate(clk); - /* - * the clock is valid if its frequency is not masked - * and large than minimum allowed frequency. - */ - if (freq < min_cpufreq || (mask & (1 << i))) - table[i].frequency = CPUFREQ_ENTRY_INVALID; - else - table[i].frequency = freq / 1000; + table[i].frequency = freq / 1000; table[i].driver_data = i; } freq_table_redup(table, count); @@ -288,10 +230,7 @@ err_nomem1: kfree(table); err_pclk: kfree(data->pclk); -err_node: - of_node_put(pnode); err_nomem2: - policy->driver_data = NULL; kfree(data); err_np: of_node_put(np); @@ -332,12 +271,20 @@ static struct cpufreq_driver qoriq_cpufreq_driver = { .attr = cpufreq_generic_attr, }; +static const struct soc_data blacklist = { + .flags = SOC_BLACKLIST, +}; + static const struct of_device_id node_matches[] __initconst = { - { .compatible = "fsl,p2041-clockgen", .data = &sdata[0], }, - { .compatible = "fsl,p3041-clockgen", .data = &sdata[0], }, - { .compatible = "fsl,p5020-clockgen", .data = &sdata[1], }, - { .compatible = "fsl,p4080-clockgen", .data = &sdata[2], }, - { .compatible = "fsl,p5040-clockgen", .data = &sdata[2], }, + /* e6500 cannot use cpufreq due to erratum A-008083 */ + { .compatible = "fsl,b4420-clockgen", &blacklist }, + { .compatible = "fsl,b4860-clockgen", &blacklist }, + { .compatible = "fsl,t2080-clockgen", &blacklist }, + { .compatible = "fsl,t4240-clockgen", &blacklist }, + + { .compatible = "fsl,ls1021a-clockgen", }, + { .compatible = "fsl,p4080-clockgen", }, + { .compatible = "fsl,qoriq-clockgen-1.0", }, { .compatible = "fsl,qoriq-clockgen-2.0", }, {} }; @@ -355,16 +302,12 @@ static int __init qoriq_cpufreq_init(void) match = of_match_node(node_matches, np); data = match->data; - if (data) { - if (data->flag) - fmask = data->freq_mask; - min_cpufreq = get_bus_freq(); - } else { - min_cpufreq = get_bus_freq() / 2; - } of_node_put(np); + if (data && data->flags & SOC_BLACKLIST) + return -ENODEV; + ret = cpufreq_register_driver(&qoriq_cpufreq_driver); if (!ret) pr_info("Freescale QorIQ CPU frequency scaling driver\n");