Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp3289384imm; Tue, 4 Sep 2018 20:00:17 -0700 (PDT) X-Google-Smtp-Source: ANB0VdbxcnsndurG+PLhwrk07F6aoivgHiunfjmZv6dUNSSMywcjlZmQ1YV2qbh7dUszUoJiWs1z X-Received: by 2002:a17:902:4001:: with SMTP id b1-v6mr5147178pld.312.1536116417203; Tue, 04 Sep 2018 20:00:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536116417; cv=none; d=google.com; s=arc-20160816; b=qT06fecQkw8vBAHVhUpgi7C+jSTq2YlKqz3BFiTUqewaXsBLmYFNeUA/eRNtcopMyV lQwVNYESiTQlmdGhvDeKQTkXwGdE/ij+4qWe+sEKMMwzC536sVrJOSIU6kJj5XhtJeNK +ObMHf+oyKWmujxW6cCOYCH/S0vQKixRdiXv1qrS5ribHSxMRbQQjVgiy/p8emPNQFVc u1SP4L0RoA9qR/CMfV73nRFr9hlFYdphEFbtZ3LVWdrpkuj9jZMj/CgKFOzENVyU0y9K wg5EbVWYv8qQSnOpRW8cOASHOrf41RsHQGxh94VRmRJmxRdPdkysoarllNeeNbl1EHuk FzQg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:content-transfer-encoding :content-language:accept-language:references:message-id:date :thread-index:thread-topic:subject:cc:to:from; bh=1rCwNHvkPoFEq8YykjGZD9q7XUfFGgkJzYDBNb/WEdY=; b=lGAeZeANHRKtsOUNIOJbJJf/KPcIqv4DLc+nXqCsCatOeeW62CrSk1cV12md+BtrYa EbrUaGLXiYfuTB04riwYlYW6GpraY5V4JrJv1YpwkvRuVFOBDnaoCWkgSAtwhL5v/Gwf SlNosJ9bpIqIarjxhyx5RxjnvGjr9k6fTRucx/VhueBlM16EbwJGzLdih+U6CJrodqoI 02TA36PWrqP4NkN7lIksig6bO0O2Qd9SjVyP5EvyiHqG3YHPsey8qYxta5+Qp51thFmK jqcIE24c6aKYDS36cljgqOYgliZe0PEWXt7DDgNE5/ogYy/Cce+gN6Wt4kK2r/TQMSCG mF1g== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q10-v6si647748pge.674.2018.09.04.19.59.48; Tue, 04 Sep 2018 20:00:17 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726440AbeIEHZ6 convert rfc822-to-8bit (ORCPT + 99 others); Wed, 5 Sep 2018 03:25:58 -0400 Received: from mx01.hxt-semitech.com ([223.203.96.7]:53064 "EHLO barracuda.hxt-semitech.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725908AbeIEHZ6 (ORCPT ); Wed, 5 Sep 2018 03:25:58 -0400 X-ASG-Debug-ID: 1536116274-093b7e636b126900001-xx1T2L Received: from HXTBJIDCEMVIW01.hxtcorp.net ([10.128.0.14]) by barracuda.hxt-semitech.com with ESMTP id U8Fb2bYYR6ttDRBv (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NO); Wed, 05 Sep 2018 10:57:54 +0800 (CST) X-Barracuda-Envelope-From: dongsheng.wang@hxt-semitech.com Received: from HXTBJIDCEMVIW02.hxtcorp.net (10.128.0.15) by HXTBJIDCEMVIW01.hxtcorp.net (10.128.0.14) with Microsoft SMTP Server (TLS) id 15.0.1395.4; Wed, 5 Sep 2018 10:57:59 +0800 Received: from HXTBJIDCEMVIW02.hxtcorp.net ([fe80::3e:f4ff:7927:a6f6]) by HXTBJIDCEMVIW02.hxtcorp.net ([fe80::3e:f4ff:7927:a6f6%12]) with mapi id 15.00.1395.000; Wed, 5 Sep 2018 10:57:59 +0800 From: "Wang, Dongsheng" To: Ran Wang , Leo Li , Rob Herring , Mark Rutland CC: "devicetree@vger.kernel.org" , "linuxppc-dev@lists.ozlabs.org" , "linux-kernel@vger.kernel.org" , "linux-arm-kernel@lists.infradead.org" Subject: Re: [PATCH 3/3] soc: fsl: add RCPM driver Thread-Topic: [PATCH 3/3] soc: fsl: add RCPM driver X-ASG-Orig-Subj: Re: [PATCH 3/3] soc: fsl: add RCPM driver Thread-Index: AQHUQN6q4zr6XBl1OE6inyBTrUDhTQ== Date: Wed, 5 Sep 2018 02:57:58 +0000 Message-ID: References: <20180831035219.31619-1-ran.wang_1@nxp.com> <20180831035219.31619-3-ran.wang_1@nxp.com> Accept-Language: zh-CN, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-transport-fromentityheader: Hosted x-originating-ip: [10.64.6.85] Content-Type: text/plain; charset="iso-2022-jp" Content-Transfer-Encoding: 8BIT MIME-Version: 1.0 X-Barracuda-Connect: UNKNOWN[10.128.0.14] X-Barracuda-Start-Time: 1536116274 X-Barracuda-Encrypted: ECDHE-RSA-AES256-SHA384 X-Barracuda-URL: https://192.168.50.101:443/cgi-mod/mark.cgi X-Virus-Scanned: by bsmtpd at hxt-semitech.com X-Barracuda-BRTS-Status: 1 X-Barracuda-Bayes: INNOCENT GLOBAL 0.5000 1.0000 0.0100 X-Barracuda-Spam-Score: 0.51 X-Barracuda-Spam-Status: No, SCORE=0.51 using global scores of TAG_LEVEL=1000.0 QUARANTINE_LEVEL=1000.0 KILL_LEVEL=9.0 tests=BSF_RULE7568M, ISO2022JP_CHARSET X-Barracuda-Spam-Report: Code version 3.2, rules version 3.2.3.56899 Rule breakdown below pts rule name description ---- ---------------------- -------------------------------------------------- -0.00 ISO2022JP_CHARSET ISO-2022-JP message 0.50 BSF_RULE7568M Custom Rule 7568M Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Please change your comments style. On 2018/8/31 11:56, Ran Wang wrote: > The NXP's QorIQ Processors based on ARM Core have RCPM module (Run > Control and Power Management), which performs all device-level > tasks associated with power management such as wakeup source control. > > This driver depends on FSL platform PM driver framework which help to > isolate user and PM service provider (such as RCPM driver). > > Signed-off-by: Chenhui Zhao > Signed-off-by: Ying Zhang > Signed-off-by: Ran Wang > --- > drivers/soc/fsl/Kconfig | 6 ++ > drivers/soc/fsl/Makefile | 1 + > drivers/soc/fsl/ls-rcpm.c | 153 +++++++++++++++++++++++++++++++++++++++++++++ > 3 files changed, 160 insertions(+), 0 deletions(-) > create mode 100644 drivers/soc/fsl/ls-rcpm.c > > diff --git a/drivers/soc/fsl/Kconfig b/drivers/soc/fsl/Kconfig > index 6517412..882330d 100644 > --- a/drivers/soc/fsl/Kconfig > +++ b/drivers/soc/fsl/Kconfig > @@ -30,3 +30,9 @@ config FSL_PLAT_PM > have to know the implement details of wakeup function it require. > Besides, it is also easy for service side to upgrade its logic when > design changed and remain user side unchanged. > + > +config LS_RCPM > + bool "Freescale RCPM support" > + depends on (FSL_PLAT_PM) > + help > + This feature is to enable specified wakeup source for system sleep. > diff --git a/drivers/soc/fsl/Makefile b/drivers/soc/fsl/Makefile > index 8f9db23..43ff71a 100644 > --- a/drivers/soc/fsl/Makefile > +++ b/drivers/soc/fsl/Makefile > @@ -7,3 +7,4 @@ obj-$(CONFIG_QUICC_ENGINE) += qe/ > obj-$(CONFIG_CPM) += qe/ > obj-$(CONFIG_FSL_GUTS) += guts.o > obj-$(CONFIG_FSL_PLAT_PM) += plat_pm.o > +obj-$(CONFIG_LS_RCPM) += ls-rcpm.o > diff --git a/drivers/soc/fsl/ls-rcpm.c b/drivers/soc/fsl/ls-rcpm.c > new file mode 100644 > index 0000000..b0feb88 > --- /dev/null > +++ b/drivers/soc/fsl/ls-rcpm.c > @@ -0,0 +1,153 @@ > +// SPDX-License-Identifier: GPL-2.0 > +// > +// plat_pm.c - Freescale Layerscape RCPM driver > +// > +// Copyright 2018 NXP > +// > +// Author: Ran Wang , > + > +#include > +#include > +#include > +#include > +#include > +#include > + > +#define MAX_COMPATIBLE_NUM 10 > + > +struct rcpm_t { > + struct device *dev; > + void __iomem *ippdexpcr_addr; > + bool big_endian; /* Big/Little endian of RCPM module */ > +}; > + > +// rcpm_handle - Configure RCPM reg according to wake up source request > +// @user_dev: pointer to user's device struct > +// @flag: to enable(true) or disable(false) wakeup source > +// @handle_priv: pointer to struct rcpm_t instance > +// > +// Return 0 on success other negative errno > +static int rcpm_handle(struct device *user_dev, bool flag, void *handle_priv) > +{ > + struct rcpm_t *rcpm; > + bool big_endian; > + const char *dev_compatible_array[MAX_COMPATIBLE_NUM]; > + void __iomem *ippdexpcr_addr; > + u32 ippdexpcr; > + u32 set_bit; > + int ret, num, i; > + > + rcpm = handle_priv; > + big_endian = rcpm->big_endian; > + ippdexpcr_addr = rcpm->ippdexpcr_addr; > + > + num = device_property_read_string_array(user_dev, "compatible", > + dev_compatible_array, MAX_COMPATIBLE_NUM); > + if (num < 0) > + return num; > + > + for (i = 0; i < num; i++) { > + if (!device_property_present(rcpm->dev, > + dev_compatible_array[i])) > + continue; > + else { Remove this else. > + ret = device_property_read_u32(rcpm->dev, > + dev_compatible_array[i], &set_bit); > + if (ret) > + return ret; > + > + if (!device_property_present(rcpm->dev, > + dev_compatible_array[i])) This has been checked. Continue ? or return ENODEV? > + return -ENODEV; > + else { Remove this else. > + ret = device_property_read_u32(rcpm->dev, > + dev_compatible_array[i], &set_bit); > + if (ret) > + return ret; > + > + if (big_endian) > + ippdexpcr = ioread32be(ippdexpcr_addr); > + else > + ippdexpcr = ioread32(ippdexpcr_addr); > + > + if (flag) > + ippdexpcr |= set_bit; > + else > + ippdexpcr &= ~set_bit; > + > + if (big_endian) { > + iowrite32be(ippdexpcr, ippdexpcr_addr); > + ippdexpcr = ioread32be(ippdexpcr_addr); > + } else if (x) { .... .... } else { } > + iowrite32(ippdexpcr, ippdexpcr_addr); > + > + return 0; > + } > + } > + } > + > + return -ENODEV; > +} > + > +static int ls_rcpm_probe(struct platform_device *pdev) > +{ > + struct resource *r; > + struct rcpm_t *rcpm; > + > + r = platform_get_resource(pdev, IORESOURCE_MEM, 0); > + if (!r) > + return -ENODEV; > + > + rcpm = kmalloc(sizeof(*rcpm), GFP_KERNEL); kzalloc is better. > + if (!rcpm) > + return -ENOMEM; > + > + rcpm->big_endian = device_property_read_bool(&pdev->dev, "big-endian"); > + > + rcpm->ippdexpcr_addr = devm_ioremap_resource(&pdev->dev, r); > + if (IS_ERR(rcpm->ippdexpcr_addr)) > + return PTR_ERR(rcpm->ippdexpcr_addr); > + > + rcpm->dev = &pdev->dev; > + platform_set_drvdata(pdev, rcpm); > + > + return register_fsl_platform_wakeup_source(rcpm_handle, rcpm); > +} > + > +static int ls_rcpm_remove(struct platform_device *pdev) > +{ > + struct rcpm_t *rcpm; Not need a table. Cheers, -Dongsheng > + > + rcpm = platform_get_drvdata(pdev); > + deregister_fsl_platform_wakeup_source(rcpm); > + kfree(rcpm); > + > + return 0; > +} > + > +static const struct of_device_id ls_rcpm_of_match[] = { > + { .compatible = "fsl,qoriq-rcpm-2.1", }, > + {} > +}; > +MODULE_DEVICE_TABLE(of, ls_rcpm_of_match); > + > +static struct platform_driver ls_rcpm_driver = { > + .driver = { > + .name = "ls-rcpm", > + .of_match_table = ls_rcpm_of_match, > + }, > + .probe = ls_rcpm_probe, > + .remove = ls_rcpm_remove, > +}; > + > +static int __init ls_rcpm_init(void) > +{ > + return platform_driver_register(&ls_rcpm_driver); > +} > +subsys_initcall(ls_rcpm_init); > + > +static void __exit ls_rcpm_exit(void) > +{ > + platform_driver_unregister(&ls_rcpm_driver); > +} > +module_exit(ls_rcpm_exit);