From patchwork Fri Sep 25 15:07:33 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Claudiu Beznea X-Patchwork-Id: 1371371 X-Patchwork-Delegate: eugen.hristev@microchip.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=quarantine dis=none) header.from=microchip.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=microchip.com header.i=@microchip.com header.a=rsa-sha256 header.s=mchp header.b=LKGA2xGO; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4ByZzJ2MQVz9sR4 for ; Sat, 26 Sep 2020 01:07:56 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id E161282423; Fri, 25 Sep 2020 17:07:51 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=fail (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=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=microchip.com header.i=@microchip.com header.b="LKGA2xGO"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 379CB82433; Fri, 25 Sep 2020 17:07:50 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL, SPF_HELO_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from esa1.microchip.iphmx.com (esa1.microchip.iphmx.com [68.232.147.91]) (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 CF6868241D for ; Fri, 25 Sep 2020 17:07:42 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=quarantine dis=none) header.from=microchip.com Authentication-Results: phobos.denx.de; spf=fail smtp.mailfrom=Claudiu.Beznea@microchip.com DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1601046462; x=1632582462; h=from:to:cc:subject:date:message-id:mime-version; bh=fdBc856tgpxEyJYzFo+GUVbYFkixllLKCKCZJHxonKE=; b=LKGA2xGOzTOGzjhZ+IV2JAtvCDNAydsILaCww/BdChmh2SAM3APTcZLV kD+SILDgTwWzZChvf28H/J03AkudtvTEWiK3QXuNtoJpaXenX3X2o/T/J j3woELf22WcKon+XNqXFNpwdHvMwTw5LhV4iYfY6QMUjN2fWWtlxFC6AC tfB0V2rp9m0JIyv2tjYAF/10ZAT7OI3PR3lm0oQ3h1vIt5Efp2f3d/5LA CLHidiDUi1WGiyKnHAfJGCNvwsty6QqYvg97CN5BlFo7ZdbMZo0ZXVCJS z27nmQGWuYpZO2GdUKe23gK37gnWnRVKOL8wUXw8PNuJVKHkAFxX10X+J w==; IronPort-SDR: H28UPLmX2wh3yP5Ra0dSCWqm4GwdfQSy2Nn3ahoWzbsd5++tOhSN7usWnnx25uhlD/9k3oIi3n E3kWtfEJwyllmbJhnH/BM1mfM14EIDRxs5vx/vYUhT0RSmWRgTPZ4w4BcWeNYPeqw79f7qqJbd xl6lUsiLTwL9xBlEU8j6TSJy8m8jYm8DNg74NSYt0iL1PxmtJoYhb6bJffgmt8lLm5mUNtyR2Y pIsF0Bkvz6i1IediqVwODjy/gtSKl87HUe3jXL+Vk4/UQbODLcqX3ugV5ibRfOdxhbTF4ODqp8 Rls= X-IronPort-AV: E=Sophos;i="5.77,302,1596524400"; d="scan'208";a="97205715" Received: from smtpout.microchip.com (HELO email.microchip.com) ([198.175.253.82]) by esa1.microchip.iphmx.com with ESMTP/TLS/AES256-SHA256; 25 Sep 2020 08:07:38 -0700 Received: from chn-vm-ex01.mchp-main.com (10.10.85.143) by chn-vm-ex02.mchp-main.com (10.10.85.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1979.3; Fri, 25 Sep 2020 08:07:03 -0700 Received: from m18063-ThinkPad-T460p.microchip.com (10.10.115.15) by chn-vm-ex01.mchp-main.com (10.10.85.143) with Microsoft SMTP Server id 15.1.1979.3 via Frontend Transport; Fri, 25 Sep 2020 08:07:02 -0700 From: Claudiu Beznea To: CC: , Claudiu Beznea Subject: [PATCH] cpu: at91: add driver for CPU Date: Fri, 25 Sep 2020 18:07:33 +0300 Message-ID: <1601046453-16512-1-git-send-email-claudiu.beznea@microchip.com> X-Mailer: git-send-email 2.7.4 MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 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.102.3 at phobos.denx.de X-Virus-Status: Clean Add basic CPU driver use to retrieve information about CPU itself. Signed-off-by: Claudiu Beznea --- MAINTAINERS | 1 + drivers/cpu/Makefile | 1 + drivers/cpu/at91_cpu.c | 123 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 125 insertions(+) create mode 100644 drivers/cpu/at91_cpu.c diff --git a/MAINTAINERS b/MAINTAINERS index 7e46470c709a..14b2fdc49135 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -291,6 +291,7 @@ S: Maintained T: git https://gitlab.denx.de/u-boot/custodians/u-boot-atmel.git F: arch/arm/mach-at91/ F: board/atmel/ +F: drivers/cpu/at91_cpu.c F: drivers/misc/microchip_flexcom.c ARM NEXELL S5P4418 diff --git a/drivers/cpu/Makefile b/drivers/cpu/Makefile index 0b5dbc7c88e6..c8532637ca7c 100644 --- a/drivers/cpu/Makefile +++ b/drivers/cpu/Makefile @@ -8,6 +8,7 @@ obj-$(CONFIG_CPU) += cpu-uclass.o obj-$(CONFIG_ARCH_BMIPS) += bmips_cpu.o obj-$(CONFIG_ARCH_IMX8) += imx8_cpu.o +obj-$(CONFIG_ARCH_AT91) += at91_cpu.o obj-$(CONFIG_CPU_MPC83XX) += mpc83xx_cpu.o obj-$(CONFIG_CPU_RISCV) += riscv_cpu.o obj-$(CONFIG_SANDBOX) += cpu_sandbox.o diff --git a/drivers/cpu/at91_cpu.c b/drivers/cpu/at91_cpu.c new file mode 100644 index 000000000000..347cf6bed1ab --- /dev/null +++ b/drivers/cpu/at91_cpu.c @@ -0,0 +1,123 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright (C) 2020 Microchip Technology Inc. and its subsidiaries + * + * Author: Claudiu Beznea + */ + +#include +#include +#include +#include +#include + +struct at91_cpu_platdata { + const char *name; + ulong cpufreq_mhz; + ulong mckfreq_mhz; + ulong xtalfreq_mhz; +}; + +extern char *get_cpu_name(void); + +const char *at91_cpu_get_name(void) +{ + return get_cpu_name(); +} + +int at91_cpu_get_desc(struct udevice *dev, char *buf, int size) +{ + struct at91_cpu_platdata *plat = dev_get_platdata(dev); + + snprintf(buf, size, "%s\n" + "Crystal frequency: %8lu MHz\n" + "CPU clock : %8lu MHz\n" + "Master clock : %8lu MHz\n", + plat->name, plat->xtalfreq_mhz, plat->cpufreq_mhz, + plat->mckfreq_mhz); + + return 0; +} + +static int at91_cpu_get_info(struct udevice *dev, struct cpu_info *info) +{ + struct at91_cpu_platdata *plat = dev_get_platdata(dev); + + info->cpu_freq = plat->cpufreq_mhz * 1000000; + info->features = BIT(CPU_FEAT_L1_CACHE); + + return 0; +} + +static int at91_cpu_get_count(struct udevice *dev) +{ + return 1; +} + +static int at91_cpu_get_vendor(struct udevice *dev, char *buf, int size) +{ + snprintf(buf, size, "Microchip Technology Inc."); + + return 0; +} + +static const struct cpu_ops at91_cpu_ops = { + .get_desc = at91_cpu_get_desc, + .get_info = at91_cpu_get_info, + .get_count = at91_cpu_get_count, + .get_vendor = at91_cpu_get_vendor, +}; + +static const struct udevice_id at91_cpu_ids[] = { + { .compatible = "arm,cortex-a7" }, + { /* Sentinel. */ } +}; + +static int at91_cpu_probe(struct udevice *dev) +{ + struct at91_cpu_platdata *plat = dev_get_platdata(dev); + struct clk clk; + ulong rate; + int ret; + + ret = clk_get_by_index(dev, 0, &clk); + if (ret) + return ret; + + rate = clk_get_rate(&clk); + if (!rate) + return -ENOTSUPP; + plat->cpufreq_mhz = DIV_ROUND_CLOSEST_ULL(rate, 1000000); + + ret = clk_get_by_index(dev, 1, &clk); + if (ret) + return ret; + + rate = clk_get_rate(&clk); + if (!rate) + return -ENOTSUPP; + plat->mckfreq_mhz = DIV_ROUND_CLOSEST_ULL(rate, 1000000); + + ret = clk_get_by_index(dev, 2, &clk); + if (ret) + return ret; + + rate = clk_get_rate(&clk); + if (!rate) + return -ENOTSUPP; + plat->xtalfreq_mhz = DIV_ROUND_CLOSEST_ULL(rate, 1000000); + + plat->name = get_cpu_name(); + + return 0; +} + +U_BOOT_DRIVER(cpu_at91_drv) = { + .name = "at91-cpu", + .id = UCLASS_CPU, + .of_match = at91_cpu_ids, + .ops = &at91_cpu_ops, + .probe = at91_cpu_probe, + .platdata_auto_alloc_size = sizeof(struct at91_cpu_platdata), + .flags = DM_FLAG_PRE_RELOC, +};