bL_switcher_dummy_if.c 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /*
  2. * arch/arm/common/bL_switcher_dummy_if.c -- b.L switcher dummy interface
  3. *
  4. * Created by: Nicolas Pitre, November 2012
  5. * Copyright: (C) 2012-2013 Linaro Limited
  6. *
  7. * Dummy interface to user space for debugging purpose only.
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License version 2 as
  11. * published by the Free Software Foundation.
  12. */
  13. #include <linux/init.h>
  14. #include <linux/module.h>
  15. #include <linux/fs.h>
  16. #include <linux/miscdevice.h>
  17. #include <asm/uaccess.h>
  18. #include <asm/bL_switcher.h>
  19. static ssize_t bL_switcher_write(struct file *file, const char __user *buf,
  20. size_t len, loff_t *pos)
  21. {
  22. unsigned char val[3];
  23. unsigned int cpu, cluster;
  24. int ret;
  25. pr_debug("%s\n", __func__);
  26. if (len < 3)
  27. return -EINVAL;
  28. if (copy_from_user(val, buf, 3))
  29. return -EFAULT;
  30. /* format: <cpu#>,<cluster#> */
  31. if (val[0] < '0' || val[0] > '9' ||
  32. val[1] != ',' ||
  33. val[2] < '0' || val[2] > '1')
  34. return -EINVAL;
  35. cpu = val[0] - '0';
  36. cluster = val[2] - '0';
  37. ret = bL_switch_request(cpu, cluster);
  38. return ret ? : len;
  39. }
  40. static const struct file_operations bL_switcher_fops = {
  41. .write = bL_switcher_write,
  42. .owner = THIS_MODULE,
  43. };
  44. static struct miscdevice bL_switcher_device = {
  45. MISC_DYNAMIC_MINOR,
  46. "b.L_switcher",
  47. &bL_switcher_fops
  48. };
  49. static int __init bL_switcher_dummy_if_init(void)
  50. {
  51. return misc_register(&bL_switcher_device);
  52. }
  53. static void __exit bL_switcher_dummy_if_exit(void)
  54. {
  55. misc_deregister(&bL_switcher_device);
  56. }
  57. module_init(bL_switcher_dummy_if_init);
  58. module_exit(bL_switcher_dummy_if_exit);