Received: by 2002:a25:e7d8:0:0:0:0:0 with SMTP id e207csp1428418ybh; Fri, 13 Mar 2020 00:50:50 -0700 (PDT) X-Google-Smtp-Source: ADFU+vuKgzkg0g7wDQfgvMjD7nIz6J+huDcTmEKlq3FVdz/c1vUVkFtNpkGIPRZ7U2BR/b8q8u9i X-Received: by 2002:aca:4e47:: with SMTP id c68mr6058035oib.16.1584085850379; Fri, 13 Mar 2020 00:50:50 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1584085850; cv=pass; d=google.com; s=arc-20160816; b=uuln22/nmcd9Tw5/RMVeZLYtTB54B/SR9gLT1V3l+CBcUpyjvaxp4qaIchByZgQbo0 ScSuV+zql4Kgx/JNktwob1C1K/8oxuL6TiRIfeZQ3kg9sZIBAmNUo9KpYFvQVWuLjPN1 m4gAO5a+YNmBZGJTr9VI2o7pdd17hXXV4hHH3BmcNuIJGsLBEgSX++ZWtphTmHbyOETk YAf6mVfdF1JIdUMFyYbNP3P+dq+lJuHwGg2ANO+KuwGQioTxmO2lKx1+9Gz2YKq5YuG0 JOsYpIs6xgtDgGk1P43cDiIHPJ4/9cP6xFQi/CZJWPX0CM2DJu24XzbFS5ISP8i3sHdV FVvQ== ARC-Message-Signature: i=2; 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:in-reply-to:references:message-id :date:thread-index:thread-topic:subject:cc:to:from:dkim-signature; bh=OYRjk7xIK0yv1tj8YXANcUvjtHeYdp5QImFTkzKPn/Q=; b=kyk6Vgv8YEUFis/3FWoep8k5lEYLCmu3xgtBTB9R/tXfEn8aco+Rf63UtWqFJygFtI mIL8DZzWhqq41xTH2q0/BA39gv5lQp6NZehTeP/1Wtb0bSW/SHs8NXx3r3cQycHISTXk MlYsjb51Xdgi6qJpR/iN6xcj/UwqXEMHjqAa2GbvCmxanic6pBIuwGlGnYJ4sD/Z2AmY C6FsXDG6BtK7mVcVWIlokh1LT1AdmXMB3QwD/wyBG76ovRKupCj8r8nAKVNfKATAAx/D lppzi8IoMXIZd1zcApmAz0WiWzH9oxzBcCHxyUX54nlkzrh77rJmOj8grcQBHZN4JIcc J9Qg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@nxp.com header.s=selector2 header.b=mN0fs1Vj; arc=pass (i=1 spf=pass spfdomain=nxp.com dkim=pass dkdomain=nxp.com dmarc=pass fromdomain=nxp.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; 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 h23si24900otk.294.2020.03.13.00.50.37; Fri, 13 Mar 2020 00:50:50 -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=selector2 header.b=mN0fs1Vj; arc=pass (i=1 spf=pass spfdomain=nxp.com dkim=pass dkdomain=nxp.com dmarc=pass fromdomain=nxp.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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=nxp.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726377AbgCMHuG (ORCPT + 99 others); Fri, 13 Mar 2020 03:50:06 -0400 Received: from mail-am6eur05on2085.outbound.protection.outlook.com ([40.107.22.85]:46368 "EHLO EUR05-AM6-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726216AbgCMHuG (ORCPT ); Fri, 13 Mar 2020 03:50:06 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=aNveq3kR5ZjRbn1tNv1s8GHMry8tRxf7Wm/3iASwqDLuluXcdUSfCMNeewH5tnP1Ag90UpSNR5p43I8rAXUZQ8c46odKQTQ812u2sIbMIh/MhR596ER8j+R+j9n+8uzyoHcGcieS1AP/AZSsfq0LtOkqFPFOMJH/Cz+91IdbKjcuAYYgpRrEigbroeWM1acWZFjOQHqQ9I8OJDPTf6+uGwmDN44KFSRcj7oQ7m3Tv/3kUG6u3GQofH9AzfwtWkWgCuaKQ00ouzPL3tIhzsgK7WCChAC+PNqkh171v+/c1xK39ivovCYILGJKhfUNzaFFn/559Wg7RWB5x4YnCU2eXA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=OYRjk7xIK0yv1tj8YXANcUvjtHeYdp5QImFTkzKPn/Q=; b=YRzD1Pdu2rTpAsF5hgNgjHt3VO3UPtEOQSAagISJOJtF2PPjj1tfSRB6U09RZCQBtf9UfbMmtYAIyFWcb/Lc6LSlpJQIfi/7gcp6B9o7x0diAfV+nrd26ps9blaSUnx/1l1gcMlSbhMpycoxPKXE6V9n/piC7ZefSOsVXNpWNQTz5VelcBhyNKH488bonJt6uWZYvFl/HekMWG24o+wmePTZYxJ2nKQIdxulRUd6lIz/Ilq2/ZR7yY4jk8QVyasLcyMNbSTYzViAxOYi2gXqF1kqC2dhpS6hBn4EGCRGmzpPMbdO8KplrexkHEKqkPUfeOzV2p5rADdjdXdJT9hPuQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=OYRjk7xIK0yv1tj8YXANcUvjtHeYdp5QImFTkzKPn/Q=; b=mN0fs1VjJiqn/SgB0o4q87cKUkZaxfPQvMsG7WqErj5cWGB4NT0AXzERGthZXdoZOkKdCwauX0s+9HU8DeY9iIQgqDweQVPkyIl0EmUFCKqnxeagBozyYyF24+y1CMHH4bgfrXOTz//AjrzkQmZjrkKpNz5H27sINb3XTChlimE= Received: from AM0PR04MB4481.eurprd04.prod.outlook.com (52.135.147.15) by AM0PR04MB6002.eurprd04.prod.outlook.com (20.178.114.33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2793.20; Fri, 13 Mar 2020 07:47:26 +0000 Received: from AM0PR04MB4481.eurprd04.prod.outlook.com ([fe80::548f:4941:d4eb:4c11]) by AM0PR04MB4481.eurprd04.prod.outlook.com ([fe80::548f:4941:d4eb:4c11%6]) with mapi id 15.20.2793.018; Fri, 13 Mar 2020 07:47:26 +0000 From: Peng Fan To: Abel Vesa , Rob Herring , Shawn Guo , Sascha Hauer , Fabio Estevam , Mike Turquette , Stephen Boyd , Lee Jones , Anson Huang , Leonard Crestez , Jacky Bai CC: dl-linux-imx , "devicetree@vger.kernel.org" , "linux-arm-kernel@lists.infradead.org" , Linux Kernel Mailing List , "linux-clk@vger.kernel.org" , Abel Vesa Subject: RE: [RFC 04/11] clk: imx: Add gate shared for i.MX8MP audiomix Thread-Topic: [RFC 04/11] clk: imx: Add gate shared for i.MX8MP audiomix Thread-Index: AQHV8TqlpdEwDmBs0U+iFgh60sh+aKhGNI2w Date: Fri, 13 Mar 2020 07:47:26 +0000 Message-ID: References: <1583226206-19758-1-git-send-email-abel.vesa@nxp.com> <1583226206-19758-5-git-send-email-abel.vesa@nxp.com> In-Reply-To: <1583226206-19758-5-git-send-email-abel.vesa@nxp.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: spf=none (sender IP is ) smtp.mailfrom=peng.fan@nxp.com; x-originating-ip: [119.31.174.68] x-ms-publictraffictype: Email x-ms-office365-filtering-ht: Tenant x-ms-office365-filtering-correlation-id: 5e604eb9-e424-40cd-2768-08d7c722c646 x-ms-traffictypediagnostic: AM0PR04MB6002:|AM0PR04MB6002: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:5236; x-forefront-prvs: 034119E4F6 x-forefront-antispam-report: SFV:NSPM;SFS:(10009020)(4636009)(366004)(39860400002)(376002)(136003)(396003)(346002)(199004)(76116006)(66556008)(66446008)(9686003)(7696005)(66476007)(66946007)(86362001)(64756008)(55016002)(33656002)(71200400001)(478600001)(4326008)(316002)(5660300002)(110136005)(54906003)(6506007)(6636002)(44832011)(52536014)(8676002)(81166006)(8936002)(26005)(2906002)(81156014)(186003)(7416002)(921003)(1121003);DIR:OUT;SFP:1101;SCL:1;SRVR:AM0PR04MB6002;H:AM0PR04MB4481.eurprd04.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;A:1; received-spf: None (protection.outlook.com: nxp.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: yaG+pDZAMEcQ8D1HFrMIYh+B6+fobrcmV6gnMcpur9MCZWEdQFY6bVPMd4lPkvnTnkswChKTiT3hmCX5KCNWef3AqEllrZ/wWsqp3sEzivYN1bLayJFVf+ixMR2xl5CTvXC3ft95R/hwmtg8g6EI/RprasVLroAHPpLzQRwGeEx1N2sJTDfRZLMsxRpB5Hx6Ixt1GPn7F0yoQfWT1qy7tNSKYRU++479/Y2WVyB0gOZes/lHYF+d87ltQMsmdioERtWGHPaX4tFBbREWuJw75WyjDfk091b6O6H7WQ7MUCMtLdE1NkGU12XoisaU6OJxivs4Qw/GgqcHw95wLR8RHxLUF0M29Mv0aWlXGYfRfutYKl6yr4P9VHbxd+8tjPQY8U2MsTgFARKPjEjjzsyM1T6qasEUwuKg9RFfMrICm7MA073Qkx665IQLLHoOXTgipYDCrBeeoA8bAhp2Tae8GlYRJb9z8qJ4eq0/29tsjpWAJQp30rDECSj3qoMufPHO x-ms-exchange-antispam-messagedata: WTqjGsi0eKl22pr6otW+uoq8f0WnXcwL4CvNJrRYvswdFxmXn6pon10eyJNTS6ilxWRsKC2kldZy3hnktVMiFKZFNRce78H+8ZkIqWjmqCKWXyX0kIIuA1jc8zPZpmv7KnH/AE/89OjxBLsM+RErJw== Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 5e604eb9-e424-40cd-2768-08d7c722c646 X-MS-Exchange-CrossTenant-originalarrivaltime: 13 Mar 2020 07:47:26.3517 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: xYKC/OfQ7LkFDv+Jl7+wwnunDKuKAUSFn3go7gR1jmFLLCi3/BzA5SXqd+qLgIIdg47rXZ2EP1+H7ZB1IjQyXA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR04MB6002 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org > Subject: [RFC 04/11] clk: imx: Add gate shared for i.MX8MP audiomix >=20 > The newer i.MX platform use some gates that have a shared control bit > between them. Could the existing clk_hw_register_gate2 handle your case? Thanks, Peng. >=20 > Signed-off-by: Abel Vesa > --- > drivers/clk/imx/Makefile | 2 +- > drivers/clk/imx/clk-gate-shared.c | 111 > ++++++++++++++++++++++++++++++++++++++ > drivers/clk/imx/clk.h | 4 ++ > 3 files changed, 116 insertions(+), 1 deletion(-) create mode 100644 > drivers/clk/imx/clk-gate-shared.c >=20 > diff --git a/drivers/clk/imx/Makefile b/drivers/clk/imx/Makefile index > 928f874c..799a8ef 100644 > --- a/drivers/clk/imx/Makefile > +++ b/drivers/clk/imx/Makefile > @@ -27,7 +27,7 @@ obj-$(CONFIG_MXC_CLK_SCU) +=3D \ >=20 > obj-$(CONFIG_CLK_IMX8MM) +=3D clk-imx8mm.o > obj-$(CONFIG_CLK_IMX8MN) +=3D clk-imx8mn.o > -obj-$(CONFIG_CLK_IMX8MP) +=3D clk-imx8mp.o > +obj-$(CONFIG_CLK_IMX8MP) +=3D clk-imx8mp.o clk-gate-shared.o > obj-$(CONFIG_CLK_IMX8MQ) +=3D clk-imx8mq.o > obj-$(CONFIG_CLK_IMX8QXP) +=3D clk-imx8qxp.o clk-imx8qxp-lpcg.o >=20 > diff --git a/drivers/clk/imx/clk-gate-shared.c > b/drivers/clk/imx/clk-gate-shared.c > new file mode 100644 > index 00000000..961a0e3 > --- /dev/null > +++ b/drivers/clk/imx/clk-gate-shared.c > @@ -0,0 +1,111 @@ > +// SPDX-License-Identifier: GPL-2.0 > +/* > + * Copyright 2019 NXP. > + */ > + > +#include > +#include > +#include > +#include > +#include "clk.h" > + > +/** > + * struct clk_gate_shared - i.MX specific gate clock having the gate > +flag > + * shared with other gate clocks > + */ > +struct clk_gate_shared { > + struct clk_gate gate; > + spinlock_t *lock; > + unsigned int *share_count; > +}; > + > +static int clk_gate_shared_enable(struct clk_hw *hw) { > + struct clk_gate *gate =3D to_clk_gate(hw); > + struct clk_gate_shared *shgate =3D container_of(gate, > + struct clk_gate_shared, gate); > + unsigned long flags =3D 0; > + int ret =3D 0; > + > + spin_lock_irqsave(shgate->lock, flags); > + > + if (shgate->share_count && (*shgate->share_count)++ > 0) > + goto out; > + > + ret =3D clk_gate_ops.enable(hw); > +out: > + spin_unlock_irqrestore(shgate->lock, flags); > + > + return ret; > +} > + > +static void clk_gate_shared_disable(struct clk_hw *hw) { > + struct clk_gate *gate =3D to_clk_gate(hw); > + struct clk_gate_shared *shgate =3D container_of(gate, > + struct clk_gate_shared, gate); > + unsigned long flags =3D 0; > + > + spin_lock_irqsave(shgate->lock, flags); > + > + if (shgate->share_count) { > + if (WARN_ON(*shgate->share_count =3D=3D 0)) > + goto out; > + else if (--(*shgate->share_count) > 0) > + goto out; > + } > + > + clk_gate_ops.disable(hw); > +out: > + spin_unlock_irqrestore(shgate->lock, flags); } > + > +static int clk_gate_shared_is_enabled(struct clk_hw *hw) { > + return clk_gate_ops.is_enabled(hw); > +} > + > +static const struct clk_ops clk_gate_shared_ops =3D { > + .enable =3D clk_gate_shared_enable, > + .disable =3D clk_gate_shared_disable, > + .is_enabled =3D clk_gate_shared_is_enabled, }; > + > +struct clk_hw *imx_dev_clk_hw_gate_shared(struct device *dev, const char > *name, > + const char *parent, void __iomem *reg, > + u8 shift, unsigned int *share_count) { > + struct clk_gate_shared *shgate; > + struct clk_gate *gate; > + struct clk_hw *hw; > + struct clk_init_data init; > + int ret; > + > + shgate =3D kzalloc(sizeof(*shgate), GFP_KERNEL); > + if (!shgate) > + return ERR_PTR(-ENOMEM); > + gate =3D &shgate->gate; > + > + init.name =3D name; > + init.ops =3D &clk_gate_shared_ops; > + init.flags =3D CLK_OPS_PARENT_ENABLE; > + init.parent_names =3D parent ? &parent : NULL; > + init.num_parents =3D parent ? 1 : 0; > + > + gate->reg =3D reg; > + gate->bit_idx =3D shift; > + gate->lock =3D NULL; > + gate->hw.init =3D &init; > + shgate->lock =3D &imx_ccm_lock; > + shgate->share_count =3D share_count; > + > + hw =3D &gate->hw; > + > + ret =3D clk_hw_register(NULL, hw); > + if (ret) { > + kfree(shgate); > + return ERR_PTR(ret); > + } > + > + return hw; > +} > diff --git a/drivers/clk/imx/clk.h b/drivers/clk/imx/clk.h index > f074dd8..51d6c26 100644 > --- a/drivers/clk/imx/clk.h > +++ b/drivers/clk/imx/clk.h > @@ -151,6 +151,10 @@ struct clk_hw *imx_clk_hw_sscg_pll(const char > *name, > void __iomem *base, > unsigned long flags); >=20 > +struct clk_hw *imx_dev_clk_hw_gate_shared(struct device *dev, const char > *name, > + const char *parent, void __iomem *reg, > + u8 shift, unsigned int *share_count); > + > enum imx_pllv3_type { > IMX_PLLV3_GENERIC, > IMX_PLLV3_SYS, > -- > 2.7.4