Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id B7BF2C352A1 for ; Wed, 7 Dec 2022 13:18:36 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id DF2C98564B; Wed, 7 Dec 2022 14:17:53 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=quarantine dis=none) header.from=microchip.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=microchip.com header.i=@microchip.com header.b="aX1yyvn3"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 27AF38513E; Wed, 7 Dec 2022 14:17:16 +0100 (CET) Received: from esa.microchip.iphmx.com (esa.microchip.iphmx.com [68.232.154.123]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 368FE85431 for ; Wed, 7 Dec 2022 14:17:09 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=quarantine dis=none) header.from=microchip.com Authentication-Results: phobos.denx.de; spf=fail smtp.mailfrom=Sergiu.Moga@microchip.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1670419029; x=1701955029; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=4r5AmS2/PSIe6hHTwdh3H2RbqkTSdNRVJMPZUU+1AMg=; b=aX1yyvn31kBjqbCtinwbkRfd1dEm5vjmN2tw/V+7k12AKgSVaZQ81h+o B+EiG/pz3f8BDGxrPgLuiyyq992DRRaCKpLwZkswHKRLOt04BCLvMDrwK sE+8bh0OSHiWC72dxGgbzw1c0BEH9QvdRRqwVCfFePg25GooIRZWA8D6G 1ED4DA2w49gKJRKQDCXCQRdAn0Z+Iuf3AmE3d/Mk4vyByTHLDOV1RYpPk 6JYK5hPkU3ZRgnX4LEVJzlwQ4ISsb6/0WlpDjavrdO6TvhaAbguBFq9HP JWZZAySt6xiH5Era98bLz3pPo1e+NE57+yavx8uYnJi16QZM2rn8mhFtq A==; X-IronPort-AV: E=Sophos;i="5.96,225,1665471600"; d="scan'208";a="186977554" Received: from unknown (HELO email.microchip.com) ([170.129.1.10]) by esa4.microchip.iphmx.com with ESMTP/TLS/AES256-SHA256; 07 Dec 2022 06:17:06 -0700 Received: from chn-vm-ex02.mchp-main.com (10.10.85.144) by chn-vm-ex01.mchp-main.com (10.10.85.143) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.12; Wed, 7 Dec 2022 06:17:03 -0700 Received: from ROB-ULT-M68701.mchp-main.com (10.10.115.15) by chn-vm-ex02.mchp-main.com (10.10.85.144) with Microsoft SMTP Server id 15.1.2507.12 via Frontend Transport; Wed, 7 Dec 2022 06:16:58 -0700 From: Sergiu Moga To: , , , , , , , , , , , , , , , , , , , , , , , CC: Subject: [PATCH 04/18] clk: at91: sam9x60: Add initial setup of UPLL and USBCK rates Date: Wed, 7 Dec 2022 15:14:33 +0200 Message-ID: <20221207131447.40590-5-sergiu.moga@microchip.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221207131447.40590-1-sergiu.moga@microchip.com> References: <20221207131447.40590-1-sergiu.moga@microchip.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.6 at phobos.denx.de X-Virus-Status: Clean In order for some of the functionalities, such as the USB clocks, to work properly we need some clocks to be properly initialised at the very beginning of booting. Signed-off-by: Sergiu Moga --- drivers/clk/at91/sam9x60.c | 62 +++++++++++++++++++++++++++++++++++++- 1 file changed, 61 insertions(+), 1 deletion(-) diff --git a/drivers/clk/at91/sam9x60.c b/drivers/clk/at91/sam9x60.c index eaf70c4668..4336148f73 100644 --- a/drivers/clk/at91/sam9x60.c +++ b/drivers/clk/at91/sam9x60.c @@ -380,6 +380,36 @@ static const struct { { .n = "dbgu_gclk", .id = 47, }, }; +/** + * Clock setup description + * @cid: clock id corresponding to clock subsystem + * @pid: parent clock id corresponding to clock subsystem + * @rate: clock rate + * @prate: parent rate + */ +static const struct pmc_clk_setup { + unsigned int cid; + unsigned int pid; + unsigned long rate; + unsigned long prate; +} sam9x60_clk_setup[] = { + { + .cid = AT91_TO_CLK_ID(PMC_TYPE_CORE, ID_PLL_U_FRAC), + .rate = 960000000, + }, + + { + .cid = AT91_TO_CLK_ID(PMC_TYPE_CORE, ID_PLL_U_DIV), + .rate = 480000000, + }, + + { + .cid = AT91_TO_CLK_ID(PMC_TYPE_CORE, ID_USBCK), + .pid = AT91_TO_CLK_ID(PMC_TYPE_CORE, ID_PLL_U_DIV), + .rate = 48000000, + }, +}; + #define prepare_mux_table(_allocs, _index, _dst, _src, _num, _label) \ do { \ int _i; \ @@ -399,7 +429,7 @@ static int sam9x60_clk_probe(struct udevice *dev) unsigned int *clkmuxallocs[64], *muxallocs[64]; const char *p[10]; unsigned int cm[10], m[10], *tmpclkmux, *tmpmux; - struct clk clk, *c; + struct clk clk, *c, *parent; int ret, muxallocindex = 0, clkmuxallocindex = 0, i; static const struct clk_range r = { 0, 0 }; @@ -672,6 +702,36 @@ static int sam9x60_clk_probe(struct udevice *dev) clk_dm(AT91_TO_CLK_ID(PMC_TYPE_GCK, sam9x60_gck[i].id), c); } + /* Setup clocks. */ + for (i = 0; i < ARRAY_SIZE(sam9x60_clk_setup); i++) { + ret = clk_get_by_id(sam9x60_clk_setup[i].cid, &c); + if (ret) + goto fail; + + if (sam9x60_clk_setup[i].pid) { + ret = clk_get_by_id(sam9x60_clk_setup[i].pid, &parent); + if (ret) + goto fail; + + ret = clk_set_parent(c, parent); + if (ret) + goto fail; + + if (sam9x60_clk_setup[i].prate) { + ret = clk_set_rate(parent, + sam9x60_clk_setup[i].prate); + if (ret < 0) + goto fail; + } + } + + if (sam9x60_clk_setup[i].rate) { + ret = clk_set_rate(c, sam9x60_clk_setup[i].rate); + if (ret < 0) + goto fail; + } + } + return 0; fail: -- 2.34.1