vvcam_dwe_driver.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611
  1. /****************************************************************************
  2. *
  3. * The MIT License (MIT)
  4. *
  5. * Copyright (c) 2020 VeriSilicon Holdings Co., Ltd.
  6. *
  7. * Permission is hereby granted, free of charge, to any person obtaining a
  8. * copy of this software and associated documentation files (the "Software"),
  9. * to deal in the Software without restriction, including without limitation
  10. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  11. * and/or sell copies of the Software, and to permit persons to whom the
  12. * Software is furnished to do so, subject to the following conditions:
  13. *
  14. * The above copyright notice and this permission notice shall be included in
  15. * all copies or substantial portions of the Software.
  16. *
  17. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  18. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  19. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  20. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  21. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  22. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  23. * DEALINGS IN THE SOFTWARE.
  24. *
  25. *****************************************************************************
  26. *
  27. * The GPL License (GPL)
  28. *
  29. * Copyright (c) 2020 VeriSilicon Holdings Co., Ltd.
  30. *
  31. * This program is free software; you can redistribute it and/or
  32. * modify it under the terms of the GNU General Public License
  33. * as published by the Free Software Foundation; either version 2
  34. * of the License, or (at your option) any later version.
  35. *
  36. * This program is distributed in the hope that it will be useful,
  37. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  38. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  39. * GNU General Public License for more details.
  40. *
  41. * You should have received a copy of the GNU General Public License
  42. * along with this program;
  43. *
  44. *****************************************************************************
  45. *
  46. * Note: This software is released under dual MIT and GPL licenses. A
  47. * recipient may use this file under the terms of either the MIT license or
  48. * GPL License. If you wish to use only one license not the other, you can
  49. * indicate your decision by deleting one of the above license notices in your
  50. * version of this file.
  51. *
  52. *****************************************************************************/
  53. #include <asm/io.h>
  54. #include <linux/cdev.h>
  55. #include <linux/module.h>
  56. #include <linux/platform_device.h>
  57. #include <linux/delay.h>
  58. #include <linux/clk.h>
  59. #include <linux/pm_runtime.h>
  60. #include <linux/io.h>
  61. #include <linux/mm.h>
  62. #include <linux/slab.h>
  63. #include <linux/proc_fs.h>
  64. #include <linux/debugfs.h>
  65. #include <linux/miscdevice.h>
  66. #include <linux/uaccess.h>
  67. #include <linux/interrupt.h>
  68. #include <linux/of_address.h>
  69. #include "dw200_ioctl.h"
  70. #include "vivdw200_irq_queue.h"
  71. #define VIVCAM_DWE_NAME "vivdw200"
  72. #define VIVCAM_DWE_MAXCNT 1
  73. //#undef USE_RESERVED_MEM
  74. #ifdef __KERNEL__
  75. #define dw_info(...)
  76. #else
  77. #define dw_info(...)
  78. #endif
  79. struct vvcam_dwe_driver_dev
  80. {
  81. struct cdev cdev;
  82. dev_t devt;
  83. struct class *class;
  84. struct mutex vvmutex;
  85. unsigned int irq_num[2];
  86. struct vvcam_dwe_per_file_dev *current_file;
  87. unsigned long long int dw200_userid;
  88. struct platform_device *pdev;
  89. #ifdef USE_RESERVED_MEM
  90. struct resource mem;
  91. #endif
  92. struct clk *aclk;
  93. struct clk *hclk;
  94. struct clk *vseclk;
  95. struct clk *dweclk;
  96. struct task_struct *locker;
  97. };
  98. struct vvcam_dwe_per_file_dev
  99. {
  100. wait_queue_head_t irq_wait;
  101. bool irq_trigger;
  102. void *private; // point to dw200_subdev{}
  103. int id;
  104. struct vvcam_dwe_driver_dev *pdriver_dev; // point to global vvcam_dwe_driver_dev
  105. };
  106. static unsigned int vvcam_dwe_major = 0;
  107. static unsigned int vvcam_dwe_minor = 0;
  108. struct class *vvcam_dwe_class;
  109. static unsigned int devise_register_index = 0;
  110. static unsigned int vvcam_dwe_poll(struct file * filp, poll_table *wait)
  111. {
  112. unsigned int mask = 0;
  113. struct vvcam_dwe_per_file_dev *per_file = (struct vvcam_dwe_per_file_dev *)filp->private_data;
  114. poll_wait(filp, &per_file->irq_wait, wait);
  115. dw_info("poll dwe_irq %d for irq_wait %p id=%d\n", per_file->irq_trigger, &per_file->irq_wait, per_file->id);
  116. if (per_file->irq_trigger) {
  117. mask |= POLLIN |POLLRDNORM;
  118. dw_info("poll notify user space\n");
  119. per_file->irq_trigger = false;
  120. }
  121. return mask;
  122. }
  123. irqreturn_t vivdw200_interrupt(int irq, void* dev_id)
  124. {
  125. dw_info(" %s enter\n", __func__);
  126. vivdw200_mis_t node;
  127. unsigned int dwe_mis, vse_mis;
  128. struct vvcam_dwe_driver_dev *pdriver_dev = dev_id;
  129. struct vvcam_dwe_per_file_dev *current_file = pdriver_dev->current_file;
  130. struct dw200_subdev *pdw200 = (struct dw200_subdev *)current_file->private;
  131. dw_info("%s current per_file=%p,pdw200=%p id=%d\n", __func__, current_file, pdw200, current_file->id);
  132. dwe_mis = 0;
  133. vse_mis = 0;
  134. dwe_read_irq((struct dw200_subdev *)pdw200, &dwe_mis);
  135. dwe_mis = dwe_mis & (~0xff00);
  136. if (0 != dwe_mis) {
  137. dw_info(" %s dwe mis 0x%08x\n", __func__, dwe_mis);
  138. dwe_clear_irq((struct dw200_subdev *)pdw200, dwe_mis <<24);
  139. node.val = dwe_mis;
  140. vivdw200_write_circle_queue(&node, &pdw200->dwe_circle_list);
  141. current_file->irq_trigger |= true;
  142. }
  143. vse_read_irq((struct dw200_subdev *)pdw200, &vse_mis);
  144. if (0 != vse_mis) {
  145. dw_info(" %s vse mis 0x%08x\n", __func__, vse_mis);
  146. vse_clear_irq((struct dw200_subdev *)pdw200, vse_mis);
  147. node.val = vse_mis;
  148. vivdw200_write_circle_queue(&node, &pdw200->vse_circle_list);
  149. current_file->irq_trigger |= true;
  150. }
  151. if (dwe_mis || vse_mis){
  152. wake_up_interruptible(&current_file->irq_wait);
  153. } else {
  154. return IRQ_HANDLED; // return IRQ_NONE;
  155. }
  156. dw_info(" %s exit\n", __func__);
  157. return IRQ_HANDLED;
  158. }
  159. static int vvcam_dwe_open(struct inode * inode, struct file * file)
  160. {
  161. struct vvcam_dwe_driver_dev *pdriver_dev = container_of(inode->i_cdev, struct vvcam_dwe_driver_dev, cdev);
  162. struct dw200_subdev * pdw200 = kzalloc(sizeof(struct dw200_subdev), GFP_KERNEL);
  163. struct vvcam_dwe_per_file_dev *per_file = kzalloc(sizeof(struct vvcam_dwe_per_file_dev), GFP_KERNEL);
  164. per_file->id = pdriver_dev->dw200_userid++;
  165. dw_info("%s per_file=%p,pdw200=%p id=%d\n", __func__, per_file, pdw200, per_file->id);
  166. pdw200->dwe_base = ioremap(DWE_REG_BASE, DWE_REG_SIZE);
  167. pdw200->vse_base = ioremap(VSE_REG_BASE, VSE_REG_SIZE);
  168. #ifdef DWE_REG_RESET
  169. pdwe_dev->dwe_reset = ioremap(DWE_REG_RESET, 4);
  170. #endif
  171. #ifdef VSE_REG_RESET
  172. pdwe_dev->vse_reset = ioremap(VSE_REG_RESET, 4);
  173. #endif
  174. file->private_data = per_file;
  175. per_file->private = pdw200;
  176. per_file->pdriver_dev = pdriver_dev;
  177. /*create circle queue*/
  178. vivdw200_create_circle_queue(&(pdw200->dwe_circle_list), QUEUE_NODE_COUNT);
  179. vivdw200_create_circle_queue(&(pdw200->vse_circle_list), QUEUE_NODE_COUNT);
  180. init_waitqueue_head(&per_file->irq_wait);
  181. pdw200->vvmutex = &pdriver_dev->vvmutex;
  182. return 0;
  183. };
  184. static long vvcam_dwe_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
  185. {
  186. long ret = 0;
  187. struct dw200_subdev* pdwe_dev;
  188. struct vvcam_dwe_per_file_dev *per_file = (struct vvcam_dwe_per_file_dev *)file->private_data;
  189. struct vvcam_dwe_driver_dev *pdriver_dev = per_file->pdriver_dev;
  190. struct device *dev = &pdriver_dev->pdev->dev;
  191. if (per_file == NULL)
  192. {
  193. pr_err("%s:file private is null point error\n", __func__);
  194. return -ENOMEM;
  195. }
  196. pdwe_dev = per_file->private;
  197. dw_info("%s cmd=0x%x id=%d", __func__, cmd, per_file->id);
  198. switch (cmd) {
  199. case DW200IOC_UPDATECURR:
  200. pdriver_dev->current_file = per_file;
  201. dw_info("DW200IOC_UPDATECURR\n");
  202. break;
  203. #ifdef USE_RESERVED_MEM
  204. case DW200IOC_GET_RESERVE_ADDR:
  205. copy_to_user(arg, &pdriver_dev->mem.start, sizeof(uint32_t));
  206. dw_info("DW200IOC_GET_RESERVE_ADDR copied pdriver_dev->mem.start 0x%x\n", pdriver_dev->mem.start);
  207. break;
  208. #endif
  209. case DW200IOC_RUNTIME_RESUME:
  210. pm_runtime_resume_and_get(dev);
  211. break;
  212. case DW200IOC_RUNTIME_SUSPEND:
  213. pm_runtime_put_sync(dev);
  214. break;
  215. case DW200IOC_LOCK:
  216. mutex_lock(pdwe_dev->vvmutex);
  217. pdriver_dev->locker = current;
  218. break;
  219. case DW200IOC_UNLOCK:
  220. mutex_unlock(pdwe_dev->vvmutex);
  221. pdriver_dev->locker = NULL;
  222. break;
  223. }
  224. ret = dw200_priv_ioctl(pdwe_dev, cmd ,(void *)arg);
  225. return ret;
  226. };
  227. static int vvcam_dwe_release(struct inode * inode, struct file * file)
  228. {
  229. struct vvcam_dwe_per_file_dev *per_file = (struct vvcam_dwe_per_file_dev *)file->private_data;
  230. struct dw200_subdev * pdw200;
  231. pdw200 = (struct dw200_subdev *)per_file->private;
  232. struct vvcam_dwe_driver_dev *pdriver_dev = per_file->pdriver_dev;
  233. struct task_struct *owner = (struct task_struct *)(atomic_long_read(&pdw200->vvmutex->owner) & ~0x07);
  234. if (owner == pdriver_dev->locker && owner != NULL) {
  235. printk("unlocked with owner=%p\n", owner);
  236. mutex_unlock(pdw200->vvmutex);
  237. }
  238. /*destory circle queue*/
  239. vivdw200_destroy_circle_queue(&(pdw200->dwe_circle_list));
  240. vivdw200_destroy_circle_queue(&(pdw200->vse_circle_list));
  241. kfree(per_file);
  242. return 0;
  243. };
  244. static int vvcam_dwe_mmap(struct file *file, struct vm_area_struct *vma)
  245. {
  246. struct vvcam_dwe_per_file_dev *per_file = (struct vvcam_dwe_per_file_dev *)file->private_data;
  247. struct vvcam_dwe_driver_dev *pdriver_dev = per_file->pdriver_dev;
  248. int ret = 0;
  249. #ifdef USE_RESERVED_MEM
  250. unsigned long pfn_start = phys_to_pfn(pdriver_dev->mem.start) + vma->vm_pgoff;
  251. unsigned long size = vma->vm_end - vma->vm_start;
  252. dw_info("phy: 0x%lx, size: 0x%lx PAGE_SHIFT: %d vma->vm_pgoff: 0x%lx vma->vm_start: 0x%lx\n", pfn_to_phys(pfn_start), size, PAGE_SHIFT, vma->vm_pgoff, vma->vm_start);
  253. vma->vm_page_prot = pgprot_writecombine(vma->vm_page_prot);
  254. if (remap_pfn_range(vma, vma->vm_start, pfn_start, size, vma->vm_page_prot))
  255. {
  256. pr_err("-->%s: remap_pfn_range error!\n", __func__);
  257. return -EIO;
  258. }
  259. #else
  260. ret = -EIO;
  261. #endif
  262. return ret;
  263. };
  264. struct file_operations vvcam_dwe_fops = {
  265. .owner = THIS_MODULE,
  266. .open = vvcam_dwe_open,
  267. .release = vvcam_dwe_release,
  268. .unlocked_ioctl = vvcam_dwe_ioctl,
  269. .poll = vvcam_dwe_poll,
  270. .mmap = vvcam_dwe_mmap,
  271. };
  272. static int vvcam_dwe_runtime_suspend(struct device *dev)
  273. {
  274. struct vvcam_dwe_driver_dev *pdriver_dev = dev_get_drvdata(dev);
  275. if (IS_ERR(pdriver_dev->dweclk) || IS_ERR(pdriver_dev->vseclk)
  276. || IS_ERR(pdriver_dev->hclk) || IS_ERR(pdriver_dev->aclk)) {
  277. return 0;
  278. }
  279. dw_info("%s\n", __func__);
  280. clk_disable_unprepare(pdriver_dev->aclk);
  281. clk_disable_unprepare(pdriver_dev->hclk);
  282. clk_disable_unprepare(pdriver_dev->vseclk);
  283. clk_disable_unprepare(pdriver_dev->dweclk);
  284. return 0;
  285. }
  286. static int vvcam_dwe_runtime_resume(struct device *dev)
  287. {
  288. struct vvcam_dwe_driver_dev *pdriver_dev = dev_get_drvdata(dev);
  289. int ret = 0;
  290. if (IS_ERR(pdriver_dev->dweclk) || IS_ERR(pdriver_dev->vseclk)
  291. || IS_ERR(pdriver_dev->hclk) || IS_ERR(pdriver_dev->aclk)) {
  292. return 0;
  293. }
  294. ret = clk_prepare_enable(pdriver_dev->dweclk);
  295. if (ret < 0) {
  296. dev_err(dev, "could not prepare or enable dwe clock\n");
  297. }
  298. ret = clk_prepare_enable(pdriver_dev->vseclk);
  299. if (ret < 0) {
  300. dev_err(dev, "could not prepare or enable vse clock\n");
  301. clk_disable_unprepare(pdriver_dev->dweclk);
  302. //return ret;
  303. }
  304. ret = clk_prepare_enable(pdriver_dev->hclk);
  305. if (ret < 0) {
  306. dev_err(dev, "could not prepare or enable ahb clock\n");
  307. clk_disable_unprepare(pdriver_dev->dweclk);
  308. clk_disable_unprepare(pdriver_dev->vseclk);
  309. //return ret;
  310. }
  311. ret = clk_prepare_enable(pdriver_dev->aclk);
  312. if (ret < 0) {
  313. dev_err(dev, "could not prepare or enable axi clock\n");
  314. clk_disable_unprepare(pdriver_dev->dweclk);
  315. clk_disable_unprepare(pdriver_dev->vseclk);
  316. clk_disable_unprepare(pdriver_dev->hclk);
  317. //return ret;
  318. }
  319. dw_info("%s Enabled clock\n", __func__);
  320. return ret;
  321. }
  322. static const struct dev_pm_ops vvcam_dwe_runtime_pm_ops = {
  323. SET_RUNTIME_PM_OPS(vvcam_dwe_runtime_suspend, vvcam_dwe_runtime_resume, NULL)
  324. };
  325. void __iomem *visys_sw_rst;
  326. #ifdef USE_RESERVED_MEM
  327. static int vvcam_dwe_of_parse(struct platform_device *pdev)
  328. {
  329. struct device *dev = &pdev->dev;
  330. struct device_node *np;
  331. int ret = 0;
  332. struct vvcam_dwe_driver_dev *pdriver_dev = platform_get_drvdata(pdev);
  333. np = of_parse_phandle(dev->of_node, "memory-region", 0);
  334. if (!np) {
  335. dev_err(dev, "No %s specified\n", "memory-region");
  336. return -EINVAL;
  337. }
  338. ret = of_address_to_resource(np, 0, &pdriver_dev->mem);
  339. if (ret) {
  340. dev_err(dev, "of_address_to_resource fail\n");
  341. return ret;
  342. }
  343. dw_info("%s got mem start 0x%x size 0x%x\n", __func__, pdriver_dev->mem.start, resource_size(&pdriver_dev->mem));
  344. return ret;
  345. }
  346. #endif
  347. static int vvcam_dwe_probe(struct platform_device *pdev)
  348. {
  349. int ret = 0;
  350. struct vvcam_dwe_driver_dev *pdriver_dev;
  351. dw_info("enter %s\n", __func__);
  352. if (pdev->id >= VIVCAM_DWE_MAXCNT)
  353. {
  354. pr_err("%s:pdev id is %d error\n", __func__,pdev->id);
  355. return -EINVAL;
  356. }
  357. pdriver_dev = devm_kzalloc(&pdev->dev,sizeof(struct vvcam_dwe_driver_dev), GFP_KERNEL);
  358. if (pdriver_dev == NULL)
  359. {
  360. pr_err("%s:alloc struct vvcam_soc_driver_dev error\n", __func__);
  361. return -ENOMEM;
  362. }
  363. memset(pdriver_dev,0,sizeof(struct vvcam_dwe_driver_dev ));
  364. visys_sw_rst = ioremap(0xffe4040100, 0x00001000);
  365. #ifdef DWE_REG_RESET
  366. pdwe_dev->dwe_reset = ioremap(DWE_REG_RESET, 4);
  367. #endif
  368. #ifdef VSE_REG_RESET
  369. pdwe_dev->vse_reset = ioremap(VSE_REG_RESET, 4);
  370. #endif
  371. mutex_init(&pdriver_dev->vvmutex);
  372. platform_set_drvdata(pdev, pdriver_dev);
  373. pdriver_dev->pdev = pdev;
  374. pdriver_dev->irq_num[0] = platform_get_irq(pdev, 0);
  375. if (pdriver_dev->irq_num[0] == 0) {
  376. pr_err("%s:dw200_[%d]: could not map IRQ\n", __func__, pdev->id);
  377. dev_err(&pdev->dev, "could not map IRQ.\n");
  378. return -ENXIO;
  379. }
  380. dw_info("%s:dw200_[%d]: pdriver_dev->irq_num[0]=%d\n", __func__, pdev->id, pdriver_dev->irq_num[0]);
  381. pdriver_dev->irq_num[1] = platform_get_irq(pdev, 1);
  382. if (pdriver_dev->irq_num[1] == 0) {
  383. pr_err("%s:dw200_[%d]: could not map IRQ\n", __func__, pdev->id);
  384. dev_err(&pdev->dev, "could not map IRQ.\n");
  385. return -ENXIO;
  386. }
  387. dw_info("%s:dw200_[%d]: pdriver_dev->irq_num[1]=%d\n", __func__, pdev->id, pdriver_dev->irq_num[1]);
  388. ret = request_irq(pdriver_dev->irq_num[0], vivdw200_interrupt,
  389. IRQF_SHARED|IRQF_TRIGGER_RISING, "DEWARP_IRQ", (char *)pdriver_dev);
  390. if (ret) {
  391. pr_err("%s[%d]:request irq error!\n", __func__, __LINE__);
  392. return ret;
  393. }
  394. ret = request_irq(pdriver_dev->irq_num[1], vivdw200_interrupt,
  395. IRQF_SHARED|IRQF_TRIGGER_RISING, "SCALAR_IRQ", (char *)pdriver_dev);
  396. if (ret) {
  397. pr_err("%s[%d]:request irq error!\n", __func__, __LINE__);
  398. return ret;
  399. }
  400. #ifdef USE_RESERVED_MEM
  401. ret = vvcam_dwe_of_parse(pdev);
  402. if (ret) {
  403. pr_err("%s[%d]: vvcam_dwe_of_parse error!\n", __func__, __LINE__);
  404. return ret;
  405. }
  406. #else
  407. pr_info("%s:disable vvcam_dwe_of_parse reserved-memory\n", __func__);
  408. #endif
  409. if (devise_register_index == 0)
  410. {
  411. if (vvcam_dwe_major == 0)
  412. {
  413. ret = alloc_chrdev_region(&pdriver_dev->devt, 0, VIVCAM_DWE_MAXCNT, VIVCAM_DWE_NAME);
  414. if (ret != 0)
  415. {
  416. pr_err("%s:alloc_chrdev_region error\n", __func__);
  417. return ret;
  418. }
  419. vvcam_dwe_major = MAJOR(pdriver_dev->devt);
  420. vvcam_dwe_minor = MINOR(pdriver_dev->devt);
  421. }
  422. else
  423. {
  424. pdriver_dev->devt = MKDEV(vvcam_dwe_major, vvcam_dwe_minor);
  425. ret = register_chrdev_region(pdriver_dev->devt, VIVCAM_DWE_MAXCNT, VIVCAM_DWE_NAME);
  426. if (ret)
  427. {
  428. pr_err("%s:register_chrdev_region error\n", __func__);
  429. return ret;
  430. }
  431. }
  432. vvcam_dwe_class = class_create(THIS_MODULE, VIVCAM_DWE_NAME);
  433. if (IS_ERR(vvcam_dwe_class))
  434. {
  435. pr_err("%s[%d]:class_create error!\n", __func__, __LINE__);
  436. return -EINVAL;
  437. }
  438. }
  439. pdriver_dev->devt = MKDEV(vvcam_dwe_major, vvcam_dwe_minor + pdev->id + 1); // just in case platform instance num is -1
  440. cdev_init(&pdriver_dev->cdev, &vvcam_dwe_fops);
  441. ret = cdev_add(&pdriver_dev->cdev, pdriver_dev->devt, 1);
  442. if ( ret )
  443. {
  444. pr_err("%s[%d]:cdev_add error!\n", __func__, __LINE__);
  445. return ret;
  446. }
  447. pdriver_dev->class = vvcam_dwe_class;
  448. device_create(pdriver_dev->class, NULL, pdriver_dev->devt,
  449. pdriver_dev, "%s", VIVCAM_DWE_NAME);
  450. devise_register_index++;
  451. pdriver_dev->dweclk = devm_clk_get(&pdev->dev, "dweclk");
  452. if (IS_ERR(pdriver_dev->dweclk)) {
  453. dev_err(&pdev->dev, "failed to get dwe clk");
  454. //return -1;
  455. }
  456. pdriver_dev->vseclk = devm_clk_get(&pdev->dev, "vseclk");
  457. if (IS_ERR(pdriver_dev->vseclk)) {
  458. dev_err(&pdev->dev, "failed to get vse clk");
  459. //return -1;
  460. }
  461. pdriver_dev->hclk = devm_clk_get(&pdev->dev, "hclk");
  462. if (IS_ERR(pdriver_dev->hclk)) {
  463. dev_err(&pdev->dev, "failed to get hclk");
  464. //return -1;
  465. }
  466. pdriver_dev->aclk = devm_clk_get(&pdev->dev, "aclk");
  467. if (IS_ERR(pdriver_dev->aclk)) {
  468. dev_err(&pdev->dev, "failed to get aclk");
  469. //return -1;
  470. }
  471. pm_runtime_enable(&pdev->dev);
  472. pm_runtime_resume_and_get(&pdev->dev);
  473. pm_runtime_put_sync(&pdev->dev);
  474. dw_info("exit %s:[%d]\n", __func__, pdev->id);
  475. return ret;
  476. }
  477. static int vvcam_dwe_remove(struct platform_device *pdev)
  478. {
  479. struct vvcam_dwe_driver_dev *pdriver_dev;
  480. //struct dw200_subdev * pdwe_dev;
  481. dw_info("enter %s\n", __func__);
  482. devise_register_index--;
  483. pdriver_dev = platform_get_drvdata(pdev);
  484. free_irq(pdriver_dev->irq_num[0], pdriver_dev);
  485. free_irq(pdriver_dev->irq_num[1], pdriver_dev);
  486. //pdwe_dev = pdriver_dev->private;
  487. //iounmap(pdwe_dev->dwe_base);
  488. //iounmap(pdwe_dev->vse_base);
  489. //iounmap(pdwe_dev->dwe_reset);
  490. //iounmap(pdwe_dev->vse_reset);
  491. pm_runtime_disable(&pdev->dev);
  492. if (!pm_runtime_status_suspended(&pdev->dev)) { // turn off the power regardless of the ref cnt
  493. vvcam_dwe_runtime_suspend(&pdev->dev);
  494. }
  495. cdev_del(&pdriver_dev->cdev);
  496. device_destroy(pdriver_dev->class, pdriver_dev->devt);
  497. unregister_chrdev_region(pdriver_dev->devt, VIVCAM_DWE_MAXCNT);
  498. if (devise_register_index == 0)
  499. {
  500. class_destroy(pdriver_dev->class);
  501. }
  502. return 0;
  503. }
  504. static const struct of_device_id dewarp_of_match[] = {
  505. { .compatible = "thead,light-dewarp", },
  506. { /* sentinel */ },
  507. };
  508. static struct platform_driver vvcam_dwe_driver = {
  509. .probe = vvcam_dwe_probe,
  510. .remove = vvcam_dwe_remove,
  511. .driver = {
  512. .name = VIVCAM_DWE_NAME,
  513. .owner = THIS_MODULE,
  514. .of_match_table = of_match_ptr(dewarp_of_match),
  515. .pm = &vvcam_dwe_runtime_pm_ops,
  516. }
  517. };
  518. static int __init vvcam_dwe_init_module(void)
  519. {
  520. int ret = 0;
  521. dw_info("enter %s\n", __func__);
  522. ret = platform_driver_register(&vvcam_dwe_driver);
  523. if (ret)
  524. {
  525. pr_err("register platform driver failed.\n");
  526. return ret;
  527. }
  528. return ret;
  529. }
  530. static void __exit vvcam_dwe_exit_module(void)
  531. {
  532. dw_info("enter %s\n", __func__);
  533. platform_driver_unregister(&vvcam_dwe_driver);
  534. }
  535. module_init(vvcam_dwe_init_module);
  536. module_exit(vvcam_dwe_exit_module);
  537. MODULE_DESCRIPTION("DWE");
  538. MODULE_LICENSE("GPL");