lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <1628e048220f066204b8ac27f3cedf7f3cc02963.1645427180.git.edwinchiu0505tw@gmail.com>
Date:   Mon, 21 Feb 2022 15:26:18 +0800
From:   Edwin Chiu <edwinchiu0505tw@...il.com>
To:     edwin.chiu@...plus.com, robh+dt@...nel.org,
        devicetree@...r.kernel.org, linux-kernel@...r.kernel.org,
        rafael@...nel.org, daniel.lezcano@...aro.org,
        linux-pm@...r.kernel.org
Cc:     Edwin Chiu <edwinchiu0505tw@...il.com>
Subject: [PATCH v5] cpuidle: sunplus: Create cpuidle driver for sunplus sp7021

Create cpuidle driver for sunplus sp7021 chip

Signed-off-by: Edwin Chiu <edwinchiu0505tw@...il.com>
---
Changes in v3
 - Rearrangement #include sequence
 - Change remark style to /*~*/
 - Align author email address to same as sob
 - Optimal code
Changes in v4
 - According Rob Herringrobh's comment
   There is no need for this binding.
   Just wanting a different driver is not a reason
   for a duplicate schema.
   So remove yaml file and submit driver again.
Changes in v5
 - According Krzysztof's comment
   You either use appropriate compatible in DT
   or add your compatible to cpuidle-arm.
   Even if this did not work, then the solution is to
   use common parts, not to duplicate entire driver.
   According Sudeep's comment
   In short NACK for any dedicated driver for this platform,
   use the generic cpuidle-arm driver with appropriate platform hooks
   Create cpuidle-sunplus.c in arch/arm/mach-sunplus/
   for hook generic cpuidle-arm driver

 MAINTAINERS                                   |  6 ++
 arch/arm/mach-sunplus/cpuidle-sunplus.c       | 88 +++++++++++++++++
 include/linux/platform_data/cpuidle-sunplus.h | 12 ++++
 3 files changed, 106 insertions(+)
 create mode 100644 arch/arm/mach-sunplus/cpuidle-sunplus.c
 create mode 100644 include/linux/platform_data/cpuidle-sunplus.h

diff --git a/MAINTAINERS b/MAINTAINERS
index e0dca8f..5c96428 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -18252,6 +18252,12 @@ L:	netdev@...r.kernel.org
 S:	Maintained
 F:	drivers/net/ethernet/dlink/sundance.c
 
+SUNPLUS CPUIDLE DRIVER
+M:	Edwin Chiu <edwinchiu0505tw@...il.com>
+S:	Maintained
+F:	arch/arm/mach-sunplus/cpuidle-sunplus.c
+F:	include/linux/platform_data/cpuidle-sunplus.h
+
 SUPERH
 M:	Yoshinori Sato <ysato@...rs.sourceforge.jp>
 M:	Rich Felker <dalias@...c.org>
diff --git a/arch/arm/mach-sunplus/cpuidle-sunplus.c b/arch/arm/mach-sunplus/cpuidle-sunplus.c
new file mode 100644
index 0000000..e9d9738
--- /dev/null
+++ b/arch/arm/mach-sunplus/cpuidle-sunplus.c
@@ -0,0 +1,88 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * SP7021 cpu idle Driver.
+ * Copyright (C) Sunplus Tech / Tibbo Tech.
+ */
+#define pr_fmt(fmt) "CPUidle arm: " fmt
+
+#include <linux/cpuidle.h>
+#include <linux/of_device.h>
+#include <linux/platform_data/cpuidle-sunplus.h>
+
+#include <asm/cpuidle.h>
+
+typedef int (*idle_fn)(void);
+
+static DEFINE_PER_CPU(idle_fn*, sp7021_idle_ops);
+
+static int sp7021_cpuidle_enter(unsigned long index)
+{
+	return __this_cpu_read(sp7021_idle_ops)[index]();
+}
+static int sp7021_cpu_spc(void)
+{
+	cpu_v7_do_idle();   /* idle to WFI */
+	return 0;
+}
+static const struct of_device_id sp7021_idle_state_match[] = {
+	{ .compatible = "arm,idle-state", .data = sp7021_cpu_spc },
+	{ },
+};
+static int sp7021_cpuidle_init(struct device_node *cpu_node, int cpu)
+{
+	const struct of_device_id *match_id;
+	struct device_node *state_node;
+	int i;
+	int state_count = 1;
+	idle_fn idle_fns[CPUIDLE_STATE_MAX];
+	idle_fn *fns;
+
+	for (i = 0; ; i++) {
+		state_node = of_parse_phandle(cpu_node, "cpu-idle-states", i);
+		if (!state_node)
+			break;
+
+		if (!of_device_is_available(state_node))
+			continue;
+
+		if (i == CPUIDLE_STATE_MAX) {
+			pr_warn("%s: cpuidle states reached max possible\n",
+					__func__);
+			break;
+		}
+
+		match_id = of_match_node(sp7021_idle_state_match, state_node);
+		if (!match_id)
+			return -ENODEV;
+
+		idle_fns[state_count] = match_id->data;
+
+		state_count++;
+	}
+
+	if (state_count == 1)
+		goto check_sp;
+
+	fns = devm_kcalloc(get_cpu_device(cpu), state_count, sizeof(*fns),
+			GFP_KERNEL);
+	if (!fns)
+		return -ENOMEM;
+
+	for (i = 1; i < state_count; i++)
+		fns[i] = idle_fns[i];
+
+	per_cpu(sp7021_idle_ops, cpu) = fns;
+
+check_sp:
+	return 0;
+}
+static const struct cpuidle_ops sp7021_cpuidle_ops __initconst = {
+	.suspend = sp7021_cpuidle_enter,
+	.init = sp7021_cpuidle_init,
+};
+CPUIDLE_METHOD_OF_DECLARE(sc_smp, "sunplus,sc-smp", &sp7021_cpuidle_ops);
+
+MODULE_AUTHOR("Edwin Chiu <edwinchiu0505tw@...il.com>");
+MODULE_DESCRIPTION("Sunplus sp7021 cpuidle driver");
+MODULE_LICENSE("GPL");
+
diff --git a/include/linux/platform_data/cpuidle-sunplus.h b/include/linux/platform_data/cpuidle-sunplus.h
new file mode 100644
index 0000000..12e98e5
--- /dev/null
+++ b/include/linux/platform_data/cpuidle-sunplus.h
@@ -0,0 +1,12 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * SP7021 cpu idle Driver.
+ * Copyright (C) Sunplus Tech / Tibbo Tech.
+ */
+
+#ifndef __CPUIDLE_SP7021_H
+#define __CPUIDLE_SP7021_H
+
+extern int cpu_v7_do_idle(void);
+
+#endif
-- 
2.7.4

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ