From patchwork Tue Feb 6 17:27:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sui Jingfeng X-Patchwork-Id: 197554 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp1696931dyb; Tue, 6 Feb 2024 09:28:48 -0800 (PST) X-Google-Smtp-Source: AGHT+IHmelZrZqXY63M2/AO4jRKa5RaKPs1jdzksa5LHAVwX4/rPBBHoPsrcVrrUeBHTs5OM5vF2 X-Received: by 2002:a0c:a9dc:0:b0:68c:4b59:d4ee with SMTP id c28-20020a0ca9dc000000b0068c4b59d4eemr4062357qvb.21.1707240528429; Tue, 06 Feb 2024 09:28:48 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707240528; cv=pass; d=google.com; s=arc-20160816; b=vz1WmKOX5i/daUbkyqqFOymtX8HtI4bD9I71/ThEJETRuorIT/VIBcPWzufhtEIoeK rK1YR78hQbuHSTi5a5/Zuc2n6e0LGiRxp9vtoB4ZTGUCOou0fc8HuQGQ3kQC+aFlNqj+ 7nAbEbS8ww3a0PyGyYNH8vTPRZD9jrPqdlZ/g+ckIfPnGfAfLeHXzTEFyrZfW24B/8EW iQUB2hZ/5aA/lfJuVSMiC39r1pF4M7dfGkDeOgCotYU6IRUsx7ZBEczGHgtou44k5r9D CfTHS4e4gp6ys+MFHNFs+RKsA36wqsFbs0cZGZrpjYXJiBUMNq94gvDhx5nIINE+Ny60 Q9Wg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=BJeg+jbAcpnrVW6uuGDu8kXydhp7MfSBefIfBQvVhDk=; fh=tJ39T9O5nbJO+YdjMxlBbaFDNmsp0QVSvAof+ws9ERI=; b=xnCtsIm+28GKnqcstnjWBEHNlJl3YbCFG45BjzMP5BH8ff95faKKVmFc28UnqSkizW DLwBaT0uvFRNU3ME8FsOORYg1jhEOnds1LJwZS8xulno0Va1VMy0jKdGV7QmP/Bmyi62 vaLG+e97lcNWnnKVXqk8iQ28KVhZsby5ds6DMFiZPpQgbUWON7bOL8+NHkUd8ZwMxW8V nzbby8jT+qqn0rhFC6O6W0wzCdEz7u/tezIi+/gexeWKpJRr1J0hVa2S77nMoLA50uTy MsxT62NSK2EZUQ3zfBRQBMLiWOWn4OB+2nRgKWk7+J7Lvmwher5sYOyikLJa+RGGn+lX 0SOQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=i0jM8bBH; arc=pass (i=1 spf=pass spfdomain=linux.dev dkim=pass dkdomain=linux.dev dmarc=pass fromdomain=linux.dev); spf=pass (google.com: domain of linux-kernel+bounces-55372-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-55372-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev X-Forwarded-Encrypted: i=1; AJvYcCVbXsLmLjWedRTczQT9yr2q/l8DpV6y516pXl0mTTE/5cBDD4la61aAkZANvW0qx1/ImgtG6pynTpewiLx2VEYUlrlG2w== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id bd25-20020ad45699000000b0068cb82b0b87si773322qvb.195.2024.02.06.09.28.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Feb 2024 09:28:48 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-55372-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=i0jM8bBH; arc=pass (i=1 spf=pass spfdomain=linux.dev dkim=pass dkdomain=linux.dev dmarc=pass fromdomain=linux.dev); spf=pass (google.com: domain of linux-kernel+bounces-55372-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-55372-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 3ACA71C233F9 for ; Tue, 6 Feb 2024 17:28:48 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E09CFDDDC; Tue, 6 Feb 2024 17:28:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="i0jM8bBH" Received: from out-179.mta1.migadu.com (out-179.mta1.migadu.com [95.215.58.179]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 65D968F6F for ; Tue, 6 Feb 2024 17:28:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.179 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707240500; cv=none; b=ApiaRGJSoyPw8KPMzVkC4g4esku/TZpn25/RbqduXTPRD6vmnKRDhe/bNesvozbsRiv0vL1U4r0jqLY2ghxFBSkur1DyqVqHmrvdYXCGKFE2PO2r8LzRbl3sjrxNDPshHCTtj4QiV985SlnG0CVyS8hNw5cJK0nuY+iyp2eius0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707240500; c=relaxed/simple; bh=LYt6rRRAtz1tm8JjwmQJDe6JgOXcLEFYmNIyU0Zk4ew=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=XjECk0VJ4D42UxPs2G/W7e7w/ZRlg61+HZ0MQRZ56oibiJgY0+wt1SEYhcWBXPv8rCngR+Wz9gSH8Wvjthj27DCT+V+gy0oCaeOMDD2cz8Am/Acv1n1L5MRVAk9JyDiddfpqzhWXSz+nondtGbVy3GppRQQS0MGNPgAyRg99z68= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=i0jM8bBH; arc=none smtp.client-ip=95.215.58.179 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1707240496; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=BJeg+jbAcpnrVW6uuGDu8kXydhp7MfSBefIfBQvVhDk=; b=i0jM8bBHnaZzGn07/ZaR92j+Iu1f4A+Cgb8phFRhlfoT8PgwxmsUTchLLn6lKUrr19AHY5 JdBUHc6dtAMo0LCObrJqRS4qFFuPhU1C69xvB4mmudD5s0YrJCAlbGN5/6pJwye5WVPsQY P9m2JwQ3BrypIAMlYED2dzpX4SUOX8g= From: Sui Jingfeng To: Lucas Stach Cc: Russell King , Christian Gmeiner , David Airlie , Daniel Vetter , Maxime Ripard , Thomas Zimmermann , dri-devel@lists.freedesktop.org, etnaviv@lists.freedesktop.org, linux-kernel@vger.kernel.org, Sui Jingfeng Subject: [etnaviv-next v13 1/7] drm/etnaviv: Add a helper function to get clocks Date: Wed, 7 Feb 2024 01:27:53 +0800 Message-Id: <20240206172759.421737-2-sui.jingfeng@linux.dev> In-Reply-To: <20240206172759.421737-1-sui.jingfeng@linux.dev> References: <20240206172759.421737-1-sui.jingfeng@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790171444508710052 X-GMAIL-MSGID: 1790171444508710052 Because the current implementation is DT-based, this only works when the host platform has the DT support. The problem is that some host platforms does not provide DT-based clocks drivers, as a result, the driver rage quit. For example, the X86-64 and LoongArch desktop platform. Typically, PLL hardware is provided by the host platform, which is part of the entire clock tree, the PLL hardware provide clock pulse to the GPU core, but it's not belong to the GPU core. PLL registers can be manipulated directly by the device driver. Hence, add a dedicated helper function to get the various clocks, which make it possible to call this function only on the platform where DT support is available. Signed-off-by: Sui Jingfeng --- drivers/gpu/drm/etnaviv/etnaviv_gpu.c | 53 ++++++++++++++++----------- 1 file changed, 32 insertions(+), 21 deletions(-) diff --git a/drivers/gpu/drm/etnaviv/etnaviv_gpu.c b/drivers/gpu/drm/etnaviv/etnaviv_gpu.c index ce1e970f0209..654bf2631755 100644 --- a/drivers/gpu/drm/etnaviv/etnaviv_gpu.c +++ b/drivers/gpu/drm/etnaviv/etnaviv_gpu.c @@ -1617,6 +1617,35 @@ static irqreturn_t irq_handler(int irq, void *data) return ret; } +static int etnaviv_gpu_clk_get(struct etnaviv_gpu *gpu) +{ + struct device *dev = gpu->dev; + + gpu->clk_reg = devm_clk_get_optional(dev, "reg"); + DBG("clk_reg: %p", gpu->clk_reg); + if (IS_ERR(gpu->clk_reg)) + return PTR_ERR(gpu->clk_reg); + + gpu->clk_bus = devm_clk_get_optional(dev, "bus"); + DBG("clk_bus: %p", gpu->clk_bus); + if (IS_ERR(gpu->clk_bus)) + return PTR_ERR(gpu->clk_bus); + + gpu->clk_core = devm_clk_get(dev, "core"); + DBG("clk_core: %p", gpu->clk_core); + if (IS_ERR(gpu->clk_core)) + return PTR_ERR(gpu->clk_core); + gpu->base_rate_core = clk_get_rate(gpu->clk_core); + + gpu->clk_shader = devm_clk_get_optional(dev, "shader"); + DBG("clk_shader: %p", gpu->clk_shader); + if (IS_ERR(gpu->clk_shader)) + return PTR_ERR(gpu->clk_shader); + gpu->base_rate_shader = clk_get_rate(gpu->clk_shader); + + return 0; +} + static int etnaviv_gpu_clk_enable(struct etnaviv_gpu *gpu) { int ret; @@ -1892,27 +1921,9 @@ static int etnaviv_gpu_platform_probe(struct platform_device *pdev) } /* Get Clocks: */ - gpu->clk_reg = devm_clk_get_optional(&pdev->dev, "reg"); - DBG("clk_reg: %p", gpu->clk_reg); - if (IS_ERR(gpu->clk_reg)) - return PTR_ERR(gpu->clk_reg); - - gpu->clk_bus = devm_clk_get_optional(&pdev->dev, "bus"); - DBG("clk_bus: %p", gpu->clk_bus); - if (IS_ERR(gpu->clk_bus)) - return PTR_ERR(gpu->clk_bus); - - gpu->clk_core = devm_clk_get(&pdev->dev, "core"); - DBG("clk_core: %p", gpu->clk_core); - if (IS_ERR(gpu->clk_core)) - return PTR_ERR(gpu->clk_core); - gpu->base_rate_core = clk_get_rate(gpu->clk_core); - - gpu->clk_shader = devm_clk_get_optional(&pdev->dev, "shader"); - DBG("clk_shader: %p", gpu->clk_shader); - if (IS_ERR(gpu->clk_shader)) - return PTR_ERR(gpu->clk_shader); - gpu->base_rate_shader = clk_get_rate(gpu->clk_shader); + err = etnaviv_gpu_clk_get(gpu); + if (err) + return err; /* TODO: figure out max mapped size */ dev_set_drvdata(dev, gpu);