bL_switcher_dummy_if.c 1.3 KB

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