1d2912cb1SThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only
2b22537c6SNicolas Pitre /*
3b22537c6SNicolas Pitre * arch/arm/common/bL_switcher_dummy_if.c -- b.L switcher dummy interface
4b22537c6SNicolas Pitre *
5b22537c6SNicolas Pitre * Created by: Nicolas Pitre, November 2012
6b22537c6SNicolas Pitre * Copyright: (C) 2012-2013 Linaro Limited
7b22537c6SNicolas Pitre *
8b22537c6SNicolas Pitre * Dummy interface to user space for debugging purpose only.
9b22537c6SNicolas Pitre */
10b22537c6SNicolas Pitre
11b22537c6SNicolas Pitre #include <linux/init.h>
12b22537c6SNicolas Pitre #include <linux/module.h>
13b22537c6SNicolas Pitre #include <linux/fs.h>
14b22537c6SNicolas Pitre #include <linux/miscdevice.h>
157c0f6ba6SLinus Torvalds #include <linux/uaccess.h>
16b22537c6SNicolas Pitre #include <asm/bL_switcher.h>
17b22537c6SNicolas Pitre
bL_switcher_write(struct file * file,const char __user * buf,size_t len,loff_t * pos)18b22537c6SNicolas Pitre static ssize_t bL_switcher_write(struct file *file, const char __user *buf,
19b22537c6SNicolas Pitre size_t len, loff_t *pos)
20b22537c6SNicolas Pitre {
21b22537c6SNicolas Pitre unsigned char val[3];
22b22537c6SNicolas Pitre unsigned int cpu, cluster;
23b22537c6SNicolas Pitre int ret;
24b22537c6SNicolas Pitre
25b22537c6SNicolas Pitre pr_debug("%s\n", __func__);
26b22537c6SNicolas Pitre
27b22537c6SNicolas Pitre if (len < 3)
28b22537c6SNicolas Pitre return -EINVAL;
29b22537c6SNicolas Pitre
30b22537c6SNicolas Pitre if (copy_from_user(val, buf, 3))
31b22537c6SNicolas Pitre return -EFAULT;
32b22537c6SNicolas Pitre
33b22537c6SNicolas Pitre /* format: <cpu#>,<cluster#> */
34b22537c6SNicolas Pitre if (val[0] < '0' || val[0] > '9' ||
35b22537c6SNicolas Pitre val[1] != ',' ||
36b22537c6SNicolas Pitre val[2] < '0' || val[2] > '1')
37b22537c6SNicolas Pitre return -EINVAL;
38b22537c6SNicolas Pitre
39b22537c6SNicolas Pitre cpu = val[0] - '0';
40b22537c6SNicolas Pitre cluster = val[2] - '0';
41b22537c6SNicolas Pitre ret = bL_switch_request(cpu, cluster);
42b22537c6SNicolas Pitre
43b22537c6SNicolas Pitre return ret ? : len;
44b22537c6SNicolas Pitre }
45b22537c6SNicolas Pitre
46b22537c6SNicolas Pitre static const struct file_operations bL_switcher_fops = {
47b22537c6SNicolas Pitre .write = bL_switcher_write,
48b22537c6SNicolas Pitre .owner = THIS_MODULE,
49b22537c6SNicolas Pitre };
50b22537c6SNicolas Pitre
51b22537c6SNicolas Pitre static struct miscdevice bL_switcher_device = {
52b22537c6SNicolas Pitre MISC_DYNAMIC_MINOR,
53b22537c6SNicolas Pitre "b.L_switcher",
54b22537c6SNicolas Pitre &bL_switcher_fops
55b22537c6SNicolas Pitre };
56ca75d601SPrasannaKumar Muralidharan module_misc_device(bL_switcher_device);
57a21b4c10SArnd Bergmann
58a21b4c10SArnd Bergmann MODULE_AUTHOR("Nicolas Pitre <nico@linaro.org>");
59a21b4c10SArnd Bergmann MODULE_LICENSE("GPL v2");
60a21b4c10SArnd Bergmann MODULE_DESCRIPTION("big.LITTLE switcher dummy user interface");
61