bm_demo_driver.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. /*
  2. * Copyright (C) 2021 Alibaba Group Holding Limited
  3. * Author: LuChongzhi <chongzhi.lcz@alibaba-inc.com>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License version 2 as
  7. * published by the Free Software Foundation.
  8. */
  9. #include <asm/io.h>
  10. #include <linux/cdev.h>
  11. #include <linux/module.h>
  12. #include <linux/platform_device.h>
  13. #include <linux/delay.h>
  14. #include <linux/clk.h>
  15. #include <linux/io.h>
  16. #include <linux/mm.h>
  17. #include <linux/timer.h>
  18. #include <linux/kernel.h>
  19. #include <linux/init.h>
  20. #include <linux/ioctl.h>
  21. #include <linux/poll.h>
  22. #include <linux/workqueue.h>
  23. #include <linux/slab.h>
  24. #include <linux/proc_fs.h>
  25. #include <linux/debugfs.h>
  26. #include <linux/miscdevice.h>
  27. #include <linux/uaccess.h>
  28. #include <linux/interrupt.h>
  29. #include <linux/of.h>
  30. #define BM_DEMO_NAME "bm_demo"
  31. #define BM_DRIVER_MAXCNT 2
  32. struct bm_demo_driver_dev
  33. {
  34. struct cdev cdev;
  35. dev_t devt;
  36. struct class *class;
  37. struct mutex vvmutex;
  38. unsigned int device_idx;
  39. struct work_struct demo_wq;
  40. wait_queue_head_t demo_wait;
  41. int irq_num;
  42. void *private;
  43. };
  44. #if 0
  45. struct work_struct* pWorkQueue = NULL;
  46. static unsigned int bm_demo_major = 0;
  47. static unsigned int bm_demo_minor = 0;
  48. struct class *bm_demo_class;
  49. static unsigned int devise_register_index = 0;
  50. static bool bm_demo_irq = false;
  51. #endif
  52. static unsigned int bm_demo_poll(struct file * filp, poll_table *wait)
  53. {
  54. return 0;
  55. }
  56. void bm_demo_work(struct work_struct *work)
  57. {
  58. }
  59. irqreturn_t bm_demo_irq(int irq, void *dev_id)
  60. {
  61. pr_info("enter %s\n", __func__);
  62. return IRQ_HANDLED;
  63. }
  64. static int bm_demo_open(struct inode * inode, struct file * file)
  65. {
  66. pr_info("enter %s\n", __func__);
  67. return 0;
  68. };
  69. static long bm_demo_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
  70. {
  71. pr_info("enter %s\n", __func__);
  72. return 0;
  73. };
  74. static int bm_demo_release(struct inode * inode, struct file * file)
  75. {
  76. pr_info("enter %s\n", __func__);
  77. return 0;
  78. };
  79. static int bm_demo_mmap(struct file *pFile, struct vm_area_struct *vma)
  80. {
  81. pr_info("enter %s\n", __func__);
  82. return 0;
  83. };
  84. struct file_operations bm_demo_fops = {
  85. .owner = THIS_MODULE,
  86. .open = bm_demo_open,
  87. .release = bm_demo_release,
  88. .unlocked_ioctl = bm_demo_ioctl,
  89. .mmap = bm_demo_mmap,
  90. .poll = bm_demo_poll,
  91. };
  92. static int bm_demo_probe(struct platform_device *pdev)
  93. {
  94. pr_info("enter %s\n", __func__);
  95. return 0;
  96. }
  97. static int bm_demo_remove(struct platform_device *pdev)
  98. {
  99. pr_info("enter %s\n", __func__);
  100. return 0;
  101. }
  102. static const struct of_device_id bm_demo_of_match[] = {
  103. { .compatible = "thead,bm-demo", },
  104. { /* sentinel */ },
  105. };
  106. MODULE_DEVICE_TABLE(of, bm_demo_of_match);
  107. static struct platform_driver bm_demo_driver = {
  108. .probe = bm_demo_probe,
  109. .remove = bm_demo_remove,
  110. .driver = {
  111. .name = BM_DEMO_NAME,
  112. .owner = THIS_MODULE,
  113. .of_match_table = of_match_ptr(bm_demo_of_match),
  114. }
  115. };
  116. static int __init bm_demo_init_module(void)
  117. {
  118. int ret = 0;
  119. pr_info("enter %s\n", __func__);
  120. ret = platform_driver_register(&bm_demo_driver);
  121. if (ret) {
  122. pr_err("register platform driver failed.\n");
  123. return ret;
  124. }
  125. return ret;
  126. }
  127. static void __exit bm_demo_exit_module(void)
  128. {
  129. pr_info("enter %s\n", __func__);
  130. platform_driver_unregister(&bm_demo_driver);
  131. }
  132. module_init(bm_demo_init_module);
  133. module_exit(bm_demo_exit_module);
  134. MODULE_AUTHOR("Lu Chongzhi");
  135. MODULE_DESCRIPTION("BAREMETAL-DEMO");
  136. MODULE_LICENSE("GPL");