From patchwork Mon Apr 9 09:19:56 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akshu Agrawal X-Patchwork-Id: 10330869 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id E09C86037F for ; Mon, 9 Apr 2018 09:26:54 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D9F2328AAF for ; Mon, 9 Apr 2018 09:26:54 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CCD5F28AC7; Mon, 9 Apr 2018 09:26:54 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.8 required=2.0 tests=BAD_ENC_HEADER,BAYES_00, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F37A128AAF for ; Mon, 9 Apr 2018 09:26:52 +0000 (UTC) Received: from alsa0.perex.cz (localhost [127.0.0.1]) by alsa0.perex.cz (Postfix) with ESMTP id C422B2675DC; Mon, 9 Apr 2018 11:20:44 +0200 (CEST) X-Original-To: alsa-devel@alsa-project.org Delivered-To: alsa-devel@alsa-project.org Received: by alsa0.perex.cz (Postfix, from userid 1000) id 6E1662675C9; Mon, 9 Apr 2018 11:20:40 +0200 (CEST) Received: from NAM02-BL2-obe.outbound.protection.outlook.com (mail-bl2nam02on0056.outbound.protection.outlook.com [104.47.38.56]) by alsa0.perex.cz (Postfix) with ESMTP id 5EA8B266C1C for ; Mon, 9 Apr 2018 11:20:37 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amdcloud.onmicrosoft.com; s=selector1-amd-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=DxmH4k6F2Dnqu5qDi+WnLq11A0pQi494dqfJ2LGqrUY=; b=K+rM5RuJlDmCgxwkTJc21yYseseaMfEbnSZDZP7ewhV8VVzcXyJSi/B88B+pHgWtifnco2ghcnOe1fcpOi1WJAKjZ9l0/MRS7v5wcaSMmqQ1nvPhOf2Ejt5O9gGAx7jZEMD9qLj5Si06SBANEAvLbw0avDIi2tRo4Rw1i035xgw= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Akshu.Agrawal@amd.com; Received: from akshu-HP-EliteBook-745-G2.mshome.net (202.56.249.162) by DM5PR1201MB0187.namprd12.prod.outlook.com (2603:10b6:4:56::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.653.12; Mon, 9 Apr 2018 09:20:31 +0000 From: Akshu Agrawal To: broonie@kernel.org, alsa-devel@alsa-project.org Date: Mon, 9 Apr 2018 17:19:56 +0800 Message-Id: <1523265596-8837-2-git-send-email-akshu.agrawal@amd.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1523265596-8837-1-git-send-email-akshu.agrawal@amd.com> References: <1523265596-8837-1-git-send-email-akshu.agrawal@amd.com> MIME-Version: 1.0 X-Originating-IP: [202.56.249.162] X-ClientProxiedBy: PN1PR0101CA0017.INDPRD01.PROD.OUTLOOK.COM (2603:1096:c00:e::27) To DM5PR1201MB0187.namprd12.prod.outlook.com (2603:10b6:4:56::11) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 57abc666-49f2-4bd2-4f11-08d59dfb263c X-MS-Office365-Filtering-HT: Tenant X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(4534165)(4627221)(201703031133081)(201702281549075)(5600026)(4604075)(48565401081)(2017052603328)(7153060)(7193020); SRVR:DM5PR1201MB0187; X-Microsoft-Exchange-Diagnostics: 1; DM5PR1201MB0187; 3:19lGoMP4ew3sxnyBLHeJ4kinCnEydQQ9b4lcUrI4m4nIae5J5kMEpyrMN5p+YlH+i9QD1Lx7J9LCwXeyIdAHbn/UmeND208Sn74uRBGhAkvs7sCgVwBboDX2HfEyB5MOsEIDZcHIOGlsZOaLigKo/oW/St+3Qd3eTL4K0CgdzpWbOyOm0Kpll4dZ/KKm25dqMykSbDp6uIsoK9Htmm4O75CLs7IsuipUOWggkL/6JBexM1g9Ry3T1m+z16pV3Dln; 25:UzBbvnuCTEagHxZRDRGRzccNyRDGZIcNhYSBEgTlUrOCowGBqhnYo2PICCodWQPJWgqsVcljyz/OMWPl1mTo4YapJ1W0B6orAImmDdR44PanC5O9ZiJMhfwDunI/8WbsVC96egrL9pxjWdBBniLBxa8iLX8VfaJXv4DdLDHTgfVLOIi06ULjIH0LwlS3Di64YW5J7FIDN+AW53uO5pWBSBEYxgnLHhZxaeg5eMMNSujrMEC0GAdZ8BzMjL+/5pSpolvNM5JiTW0b+fECbmooi0HJjbZjcv133gfpweUJpngZNfK0rBxSpGmebEP+Rx0IRCtnBHR3aTmWf+GgYKJt7Q==; 31:S4dsUQMdRt4bNQweXaG1rWwRAz8xXsTYNU8b8zBuIGjUSsIq6RTXXOId1B8gwTjol0h6CbebQm0DM1eJTfxeLhbukyAJj7wa0FauywVO8cnlGYB98b09T6GMnOyNGDpyiJ7CChW9UyIbVE1GrQygkEMjFvOItfJEEW3lBAYtkTUQ3bKcPbc9FDSXNfvnWvm75NbSfdllPBSNmklHY4K8VCjieJvYt+5CxyY+7a4Dz+g= X-MS-TrafficTypeDiagnostic: DM5PR1201MB0187: X-Microsoft-Exchange-Diagnostics: 1; DM5PR1201MB0187; 20:ehGdgFmMsZMSkHf4Tq8GXD2rP79JbwekPJJ0tWb3tptwSar3owSDo3bkltcF6NwaXQPkYYzoylw+ouqT14EFopMPbdPnrDz6ilyn+ob7/cfPix6UwNhkpSsndM5GZEkuFt2T/BUEEW2mlIV59XyO9v1EQvj2GvJ1mj42GUGugaZTHMh+W93+81cEuBV+ls1310gxmc6IMkHUMAsYGq63TPNwyRMdsiYNGvbY2fdJaKX0EvZQaM9krTEUU42EMgoP9F3LLIVN9/itvjAVfd8Fr0/rLYhICbv/qYI0wGOCwZ9nITk7OGRQqBuyW63kIr2Me3bPzJ9RH54t/xitQ/RZUC3SIvkr1r2z+TrTYcgXAgomsgtJQAnnYKXajT3Vz0Nviw28hLVJFF93KnGEfpqxTkeu2NedELEqX/wiz4kjQdMqrxTPXGBI1yrYEIyXKH+lfgWBTdq+Tav+3VCvnZSzb3z6N27iFDqZKBeb4aoHPepC+TmrRmYv+7uSZvW5fEgc; 4:F4QwKxaGongBYfXSP9q11ic8LP348sKS4ADVcMftemzXoKH9HV82nVHNeIWpqYbKFi8Vozw0WIiXKA31ScSeQgPY4x4RJ6FVw3ZoIm48XcGuWzJd2nxS385h1WpaN5Oeos6G0xMWYN3wrgWhBEvZWE0SHQc+smj1MzZQQNt0wBIFmmiu7amYIkBw5gUKNxhy0wIKqPsXkxVRDjXoA5R8tgiIaWXoEGm2/o0CvN8KXd+o9N5cFd6BjmlBkTEqv3G3BP4wODEg/KataxYpvfWLdRzYF1mtzrrMQxLvBApKE2mgs+8PWQldhNqE4uuEj18p X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(767451399110); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(8211001083)(6040522)(2401047)(5005006)(8121501046)(93006095)(93001095)(10201501046)(3231221)(944501327)(52105095)(3002001)(6055026)(6041310)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123564045)(20161123562045)(20161123558120)(20161123560045)(6072148)(201708071742011); SRVR:DM5PR1201MB0187; BCL:0; PCL:0; RULEID:; SRVR:DM5PR1201MB0187; X-Forefront-PRVS: 0637FCE711 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(346002)(39860400002)(366004)(39380400002)(376002)(396003)(199004)(189003)(48376002)(2906002)(50466002)(6486002)(5660300001)(7736002)(305945005)(47776003)(66066001)(6666003)(97736004)(69596002)(36756003)(86362001)(68736007)(105586002)(476003)(106356001)(76176011)(2616005)(956004)(53936002)(6512007)(8676002)(81166006)(81156014)(59450400001)(3846002)(6116002)(26005)(51416003)(52116002)(16526019)(186003)(6506007)(386003)(486006)(53416004)(446003)(11346002)(8936002)(72206003)(16586007)(478600001)(50226002)(4326008)(39060400002)(316002)(25786009); DIR:OUT; SFP:1101; SCL:1; SRVR:DM5PR1201MB0187; H:akshu-HP-EliteBook-745-G2.mshome.net; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; A:1; MX:1; Received-SPF: None (protection.outlook.com: amd.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; DM5PR1201MB0187; 23:N7M7vJ0LFumuB7JKUHSLJXPv6Lbx1Qvjt8vswu9?= =?us-ascii?Q?J+J8dKfxCDDVXM+tSv0I41bCFjmq+Z1NPi0KX7zmdZRSBXGHinGQ9SlcKw8Q?= =?us-ascii?Q?teFoncnfwPHC1gInd4HEIRgjlELCCJYBC2vjrbD8qaSESfMfwCmXq4oYPuC5?= =?us-ascii?Q?MfuUZGo+ovXHsh5MW57znfSh4cQZb0eQp6sCD35IpKZ2lQ15EU6fNfyk7GHc?= =?us-ascii?Q?Zxom7XXrPdLWPvUuDaaaBJFD3GUTw2Cv3YT3g/4pSsT7/bAoXYuJRhbOpVOK?= =?us-ascii?Q?1i6GgGU7N8QhhBllGlgfHzgOm/kdqDorYVyrwEemq9fLWtRiW/kCAFrt9NBt?= =?us-ascii?Q?iB3lhikYl1TaivmT4Gorf2xlewA+b3CkVA4KNLwBwy6virdROHsVDKHC/dAb?= =?us-ascii?Q?q/ciGyKtTHDl8SGvyNWgr51tqRtI7oFBoFRe9UlCWOu3wjk32/2w4ysvqIfV?= =?us-ascii?Q?cH4+F3BJFzGnQxLrEwpn8LVBbHfZaXqnk1+iq0BCiI5w5Y7S/O9akTZxGJDb?= =?us-ascii?Q?dee8y1ewCSVAl6ZiQLD4qkKwHtge1IGyPpdm1g/pIr0mRqWKnlGHgdB0/13n?= =?us-ascii?Q?s0TYNouRKcXkU+XhCw61QR3MKm1OHK5MUChwPqgvhsuT7tzGnt2srJSNEumy?= =?us-ascii?Q?Ndr8ilUpaNd7vMcHvBtMjet5z9Ij7FQYpYVMfgwyCFODRlUHhLRZTnvlH+7S?= =?us-ascii?Q?1z6ej/X8budNAUAbeEPRuKTrNHl2w6Gv6TJV409ez/LyOpZQayhUDhfNtoN0?= =?us-ascii?Q?9EuA5xcd5rxpfpDLBIZTdTEEKIa6tC2bgVnw+2OF4cShGEsoKBSqCmUlhyU6?= =?us-ascii?Q?T99i2Xef89+WK+kLO25UIyNVxWrTHRlFZqqSMj7F53e8qswlt461e7UMwJd5?= =?us-ascii?Q?7zucpLgaHqRWiKQTKBWMmFpcpOALOZ2UvjD7Kkbrc1zzA4Ex/OIfGpUoAsQL?= =?us-ascii?Q?gghWBnZpZT0ZfqtRbNbE7F8fuu5TuSgnPu1OKoiAaDI7JR6oPGtDm5lIpki1?= =?us-ascii?Q?L3gC+qVhE2oLiKZ5p+SkA1k5YaYtf0U1RGQj+IvYQM2AU+Lg7qFTCp07i+pO?= =?us-ascii?Q?Y1HH0bE/KRIlPk6o1/fMzKkpqU0wZVFCcjWPGm7wE1tf2OE6nlI2hrk3bQnt?= =?us-ascii?Q?+QKmix86MEEIER9VK/1MunBsDaTuUlLLSK3EMiQDLgT5qMVcDRK3FLEHxraW?= =?us-ascii?Q?ALwCyPQY6gaY5ObxTiywdqisDQgNo3jQZdObap9brnVEJzbR0YU4NVa2XGzw?= =?us-ascii?Q?w6OJLdyT06DIQDVEQua2Bq+RLuiuvXYsjOkh6jK/z?= X-Microsoft-Antispam-Message-Info: TQLzhmAQLvSG2eEwr+pXWr47N7zx3yMlnfHIJGw3p2l+qe74MhDK4BLYdXUBsQHICilT2Ldd2iZYlSiCr656rT27+A8dh1U/ooon9rWcDEGZ6ZtoowBduGL67++WxuKAVDJ4uCYBLEv5PWR3QpGlX6UsZnEsTbwXMjlapdibw81I5CoXCCovnfeO8o7nAcYY X-Microsoft-Exchange-Diagnostics: 1; DM5PR1201MB0187; 6:6BK/WdZ3gIxKIYdNxKbLjuhf8qirGdo81sbgJ3rxDMj1SSrgS1ANII0y7phhN/AVxCwkt1aOToHdYceY9+GWxhgmW9KBvKTsmssHmIRQtdC1iQwSvhNs2Bhmx5/PjDqpejnGeHTKZMApfCawn4VPz47HW8E3WpqsKoPNWb1d5kz+WIvDrINbQrBe2NujAgUX3arMowsE7AOL98aLuqnpG0YVNikuKt6SclGfFzRHceb0CFRgbc0B0gKJhcYWy1vs3FH60s/Q34kaimSFJg4G5Pw50eaKmjgqcx3yOnP8LWGFfQ+AJ0Stke5FR63CBPfYXnrMavMb3x1W7KfZRfVB/dcJNcabG6V5+UcBL1uLcMlRmF6MkOkoCEjouWuEHMOajk0XMm+Uywb3p45nfOIHwFkzGVMet0wB81FZy6ETt30Ufw67Fa84n0DqlRkR8Ab8VkSJrG8/wRgl/tXyUskvJA==; 5:Lrtl7K2D8f2cjoXUfz9wZvizCh433DgvK+qpKfVu37L3e+gxZ8zB23wnHxNh5MD13ZdTN6aFA/yqj89AOPdUUo1iPbhn44B3tAFL7bHSgVWdP9zT6l12D9ajKUNOtIHa/pq1J2dHmREmtnBqLmbDMkMB7SWAAMUxpN3NqUV7gts=; 24:hlk3CXMkJJuMbi5i3CfO+mehYMKmQKeazNb5JH+kTCuYF+R+36XqfN1ngU1UAlwEbPPBWj3hf/UXx2E8c6oRj6xb5QJ34MvY727vqrZ/I/0= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; DM5PR1201MB0187; 7:EwF6iZmLWYi+xbAuNNytPcGccRIPDqJSxU0B248fbRLVWj0sbtRBzkyWpoWgnkJDyXbPeJGZRM5JbM1inZPkGqrhMnC8c9ey8ToakCCb9M6D35v/10wjem0LrR5rEWovfJd4kbl3JpKkv2KqbCht9RXkbeFoG1s6gTrirqN21oonL/FYQyi3vjoVBtSZnFhmt7+px2DqOpZ/ys71zvmr/tRx/P6EjpN5XqKeDH/xMVbPwf38E3iFoPnfTmNp287K; 20:TbEHj+NiO5/9zHI8jRLEpeo5+pS5JLiG72eKBalevTcgzgtkFjFSX7C29WaGAJ34Fw4SkW2Y8W1+Gr3aRGGOn47yCYcwKf+9K+9pqX5sZCExoZgbXCh9lTGRo6gwjVn17FpDDv9jkSSGaIE+2mbVJXMHmSTsqWc1cwcMeB1yCfl2TA2iNygHHskfYCZFVMNyHMnzBBniMubkKXbACo1wKyHIe/ceMVt8WIwUFAWWefxzbhmExa4IXV+WOU5qFdzP X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Apr 2018 09:20:31.7725 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 57abc666-49f2-4bd2-4f11-08d59dfb263c X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR1201MB0187 Cc: tiwai@suse.de, Alexander.Deucher@amd.com, lgirdwood@gmail.com, djkurtz@chromium.org, akshu.agrawal@amd.com Subject: [alsa-devel] [PATCH v6, 2/2] ASoC: AMD: Enable/Disable auxiliary clock via common clock framework X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: alsa-devel-bounces@alsa-project.org Sender: alsa-devel-bounces@alsa-project.org X-Virus-Scanned: ClamAV using ClamSMTP This enables/disables and sets auxiliary clock at 25Mhz. It uses common clock framework for proper ref counting. This approach will save power in comparison to keeping it always On in firmware. TEST= aplay -vv check register to see clock enabled kill aplay check register to see clock disabled Signed-off-by: Akshu Agrawal Acked-by: Alex Deucher --- V2: Correcting the pin to OSCOUT1 from OSCOUT2 V3: Fix error/warnings from kbuild test V4: Fix build errors for platform which do not support CONFIG_COMMON_CLK V5: Review comments by Dan and Sriram V6: Adding COMMON_CLK to Kconfig, moving clk_get to register, var name changes sound/soc/amd/Kconfig | 2 +- sound/soc/amd/acp-da7219-max98357a.c | 150 +++++++++++++++++++++++++++++++++-- 2 files changed, 146 insertions(+), 6 deletions(-) diff --git a/sound/soc/amd/Kconfig b/sound/soc/amd/Kconfig index 6cbf9cf..8104f8f 100644 --- a/sound/soc/amd/Kconfig +++ b/sound/soc/amd/Kconfig @@ -8,7 +8,7 @@ config SND_SOC_AMD_CZ_DA7219MX98357_MACH select SND_SOC_DA7219 select SND_SOC_MAX98357A select SND_SOC_ADAU7002 - depends on SND_SOC_AMD_ACP && I2C + depends on SND_SOC_AMD_ACP && I2C && COMMON_CLK help This option enables machine driver for DA7219 and MAX9835. diff --git a/sound/soc/amd/acp-da7219-max98357a.c b/sound/soc/amd/acp-da7219-max98357a.c index 1012a80..29847f7 100644 --- a/sound/soc/amd/acp-da7219-max98357a.c +++ b/sound/soc/amd/acp-da7219-max98357a.c @@ -30,21 +30,42 @@ #include #include #include +#include +#include #include #include #include #include #include +#include #include "../codecs/da7219.h" #include "../codecs/da7219-aad.h" -#define CZ_PLAT_CLK 24000000 -#define MCLK_RATE 24576000 +#define CZ_PLAT_CLK 25000000 +#define DA7219_PLL_OUT 24576000 #define DUAL_CHANNEL 2 +/* Clock Driving Strength 2 register */ +#define CLKDRVSTR2 0x28 +/* Clock Control 1 register */ +#define MISCCLKCNTL1 0x40 +/* Auxiliary clock1 enable bit */ +#define OSCCLKENB 2 +/* 25Mhz auxiliary output clock freq bit */ +#define OSCOUT1CLK25MHZ 16 + +struct cz_clock { + const char* acp_clk_name; + struct clk_hw acp_clk_hw; + struct clk_lookup *acp_clk_lookup; + struct clk *acp_clk; + void __iomem *res_base; +}; + static struct snd_soc_jack cz_jack; -struct clk *da7219_dai_clk; +static struct clk *da7219_dai_clk; +static struct clk *acpd7219_clk; static int cz_da7219_init(struct snd_soc_pcm_runtime *rtd) { @@ -64,13 +85,18 @@ static int cz_da7219_init(struct snd_soc_pcm_runtime *rtd) } ret = snd_soc_dai_set_pll(codec_dai, 0, DA7219_SYSCLK_PLL, - CZ_PLAT_CLK, MCLK_RATE); + CZ_PLAT_CLK, DA7219_PLL_OUT); if (ret < 0) { dev_err(rtd->dev, "can't set codec pll: %d\n", ret); return ret; } da7219_dai_clk = clk_get(component->dev, "da7219-dai-clks"); + if (IS_ERR(da7219_dai_clk)) { + dev_err(rtd->dev, "failed to get clock: %ld\n", + PTR_ERR(da7219_dai_clk)); + return PTR_ERR(da7219_dai_clk); + } ret = snd_soc_card_jack_new(card, "Headset Jack", SND_JACK_HEADPHONE | SND_JACK_MICROPHONE | @@ -105,13 +131,20 @@ static int cz_da7219_hw_params(struct snd_pcm_substream *substream, return ret; } + ret = clk_prepare_enable(acpd7219_clk); + if (ret < 0) + dev_err(rtd->dev, "can't enable oscillator clock %d\n", ret); + return ret; } static int cz_da7219_hw_free(struct snd_pcm_substream *substream) { + clk_disable_unprepare(da7219_dai_clk); + clk_disable_unprepare(acpd7219_clk); + return 0; } @@ -244,6 +277,112 @@ static int cz_fe_startup(struct snd_pcm_substream *substream) .num_controls = ARRAY_SIZE(cz_mc_controls), }; +static int acpd7219_clk_enable(struct clk_hw *hw) +{ + u32 reg_val; + struct cz_clock *cz_clock = + container_of(hw, struct cz_clock, acp_clk_hw); + void __iomem *base = cz_clock->res_base; + + reg_val = readl(base + MISCCLKCNTL1); + reg_val &= ~(0x1 << OSCCLKENB); + writel(reg_val, base + MISCCLKCNTL1); + reg_val = readl(base + CLKDRVSTR2); + reg_val |= (0x1 << OSCOUT1CLK25MHZ); + writel(reg_val, base + CLKDRVSTR2); + + return 0; +} + +static void acpd7219_clk_disable(struct clk_hw *hw) +{ + u32 reg_val; + struct cz_clock *cz_clock = + container_of(hw, struct cz_clock, acp_clk_hw); + void __iomem *base = cz_clock->res_base; + + reg_val = readl(base + MISCCLKCNTL1); + reg_val |= (0x1 << OSCCLKENB); + writel(reg_val, base + MISCCLKCNTL1); +} + +static int acpd7219_clk_is_enabled(struct clk_hw *hw) +{ + u32 reg_val; + struct cz_clock *cz_clock = + container_of(hw, struct cz_clock, acp_clk_hw); + void __iomem *base = cz_clock->res_base; + + reg_val = readl(base + MISCCLKCNTL1); + + return !(reg_val & OSCCLKENB); +} + +static const struct clk_ops acpd7219_clk_ops = { + .enable = acpd7219_clk_enable, + .disable = acpd7219_clk_disable, + .is_enabled = acpd7219_clk_is_enabled, +}; + +static int register_acpd7219_clocks(struct platform_device *pdev) +{ + struct clk *acp_clk; + struct clk_lookup *acp_clk_lookup; + struct cz_clock *cz_clock_obj; + struct resource *res; + struct device *dev = &pdev->dev; + static const struct clk_init_data init = { + .name = "acpd7219-clk", + .ops = &acpd7219_clk_ops, + }; + + cz_clock_obj = kzalloc(sizeof(struct cz_clock), GFP_KERNEL); + if (!cz_clock_obj) + return -ENOMEM; + + cz_clock_obj->acp_clk_name = "acpd7219-clk"; + + cz_clock_obj->acp_clk_hw.init = &init; + + acp_clk = devm_clk_register(dev, &cz_clock_obj->acp_clk_hw); + if (IS_ERR(acp_clk)) + { + dev_err(dev, "Failed to register DAI clocks: %ld\n", + PTR_ERR(acp_clk)); + return PTR_ERR(acp_clk); + } + cz_clock_obj->acp_clk = acp_clk; + + acp_clk_lookup = clkdev_create(acp_clk, cz_clock_obj->acp_clk_name, + "%s", dev_name(dev)); + if (!acp_clk_lookup) + dev_warn(dev, "Failed to create DAI clkdev"); + else + cz_clock_obj->acp_clk_lookup = acp_clk_lookup; + + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); + if (!res) { + dev_err(&pdev->dev, "Failed to get misc io resource.\n"); + clkdev_drop(acp_clk_lookup); + return -EINVAL; + } + cz_clock_obj->res_base = devm_ioremap_nocache(&pdev->dev, res->start, + resource_size(res)); + if (!cz_clock_obj->res_base) { + clkdev_drop(acp_clk_lookup); + return -ENOMEM; + } + + acpd7219_clk = devm_clk_get(dev, "acpd7219-clk"); + if (IS_ERR(acpd7219_clk)) { + dev_err(dev, "failed to get acpd7219-clk: %ld\n", + PTR_ERR(acpd7219_clk)); + return PTR_ERR(acpd7219_clk); + } + + return 0; +} + static int cz_probe(struct platform_device *pdev) { int ret; @@ -259,7 +398,8 @@ static int cz_probe(struct platform_device *pdev) cz_card.name, ret); return ret; } - return 0; + + return register_acpd7219_clocks(pdev); } static const struct acpi_device_id cz_audio_acpi_match[] = {