vvcam_dwe_driver.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614
  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. dwe_reset(pdw200);
  237. vse_reset(pdw200);
  238. dwe_disable_irq(pdw200);
  239. mutex_unlock(pdw200->vvmutex);
  240. }
  241. /*destory circle queue*/
  242. vivdw200_destroy_circle_queue(&(pdw200->dwe_circle_list));
  243. vivdw200_destroy_circle_queue(&(pdw200->vse_circle_list));
  244. kfree(per_file);
  245. return 0;
  246. };
  247. static int vvcam_dwe_mmap(struct file *file, struct vm_area_struct *vma)
  248. {
  249. struct vvcam_dwe_per_file_dev *per_file = (struct vvcam_dwe_per_file_dev *)file->private_data;
  250. struct vvcam_dwe_driver_dev *pdriver_dev = per_file->pdriver_dev;
  251. int ret = 0;
  252. #ifdef USE_RESERVED_MEM
  253. unsigned long pfn_start = phys_to_pfn(pdriver_dev->mem.start) + vma->vm_pgoff;
  254. unsigned long size = vma->vm_end - vma->vm_start;
  255. 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);
  256. vma->vm_page_prot = pgprot_writecombine(vma->vm_page_prot);
  257. if (remap_pfn_range(vma, vma->vm_start, pfn_start, size, vma->vm_page_prot))
  258. {
  259. pr_err("-->%s: remap_pfn_range error!\n", __func__);
  260. return -EIO;
  261. }
  262. #else
  263. ret = -EIO;
  264. #endif
  265. return ret;
  266. };
  267. struct file_operations vvcam_dwe_fops = {
  268. .owner = THIS_MODULE,
  269. .open = vvcam_dwe_open,
  270. .release = vvcam_dwe_release,
  271. .unlocked_ioctl = vvcam_dwe_ioctl,
  272. .poll = vvcam_dwe_poll,
  273. .mmap = vvcam_dwe_mmap,
  274. };
  275. static int vvcam_dwe_runtime_suspend(struct device *dev)
  276. {
  277. struct vvcam_dwe_driver_dev *pdriver_dev = dev_get_drvdata(dev);
  278. if (IS_ERR(pdriver_dev->dweclk) || IS_ERR(pdriver_dev->vseclk)
  279. || IS_ERR(pdriver_dev->hclk) || IS_ERR(pdriver_dev->aclk)) {
  280. return 0;
  281. }
  282. dw_info("%s\n", __func__);
  283. clk_disable_unprepare(pdriver_dev->aclk);
  284. clk_disable_unprepare(pdriver_dev->hclk);
  285. clk_disable_unprepare(pdriver_dev->vseclk);
  286. clk_disable_unprepare(pdriver_dev->dweclk);
  287. return 0;
  288. }
  289. static int vvcam_dwe_runtime_resume(struct device *dev)
  290. {
  291. struct vvcam_dwe_driver_dev *pdriver_dev = dev_get_drvdata(dev);
  292. int ret = 0;
  293. if (IS_ERR(pdriver_dev->dweclk) || IS_ERR(pdriver_dev->vseclk)
  294. || IS_ERR(pdriver_dev->hclk) || IS_ERR(pdriver_dev->aclk)) {
  295. return 0;
  296. }
  297. ret = clk_prepare_enable(pdriver_dev->dweclk);
  298. if (ret < 0) {
  299. dev_err(dev, "could not prepare or enable dwe clock\n");
  300. }
  301. ret = clk_prepare_enable(pdriver_dev->vseclk);
  302. if (ret < 0) {
  303. dev_err(dev, "could not prepare or enable vse clock\n");
  304. clk_disable_unprepare(pdriver_dev->dweclk);
  305. //return ret;
  306. }
  307. ret = clk_prepare_enable(pdriver_dev->hclk);
  308. if (ret < 0) {
  309. dev_err(dev, "could not prepare or enable ahb clock\n");
  310. clk_disable_unprepare(pdriver_dev->dweclk);
  311. clk_disable_unprepare(pdriver_dev->vseclk);
  312. //return ret;
  313. }
  314. ret = clk_prepare_enable(pdriver_dev->aclk);
  315. if (ret < 0) {
  316. dev_err(dev, "could not prepare or enable axi clock\n");
  317. clk_disable_unprepare(pdriver_dev->dweclk);
  318. clk_disable_unprepare(pdriver_dev->vseclk);
  319. clk_disable_unprepare(pdriver_dev->hclk);
  320. //return ret;
  321. }
  322. dw_info("%s Enabled clock\n", __func__);
  323. return ret;
  324. }
  325. static const struct dev_pm_ops vvcam_dwe_runtime_pm_ops = {
  326. SET_RUNTIME_PM_OPS(vvcam_dwe_runtime_suspend, vvcam_dwe_runtime_resume, NULL)
  327. };
  328. void __iomem *visys_sw_rst;
  329. #ifdef USE_RESERVED_MEM
  330. static int vvcam_dwe_of_parse(struct platform_device *pdev)
  331. {
  332. struct device *dev = &pdev->dev;
  333. struct device_node *np;
  334. int ret = 0;
  335. struct vvcam_dwe_driver_dev *pdriver_dev = platform_get_drvdata(pdev);
  336. np = of_parse_phandle(dev->of_node, "memory-region", 0);
  337. if (!np) {
  338. dev_err(dev, "No %s specified\n", "memory-region");
  339. return -EINVAL;
  340. }
  341. ret = of_address_to_resource(np, 0, &pdriver_dev->mem);
  342. if (ret) {
  343. dev_err(dev, "of_address_to_resource fail\n");
  344. return ret;
  345. }
  346. dw_info("%s got mem start 0x%x size 0x%x\n", __func__, pdriver_dev->mem.start, resource_size(&pdriver_dev->mem));
  347. return ret;
  348. }
  349. #endif
  350. static int vvcam_dwe_probe(struct platform_device *pdev)
  351. {
  352. int ret = 0;
  353. struct vvcam_dwe_driver_dev *pdriver_dev;
  354. dw_info("enter %s\n", __func__);
  355. if (pdev->id >= VIVCAM_DWE_MAXCNT)
  356. {
  357. pr_err("%s:pdev id is %d error\n", __func__,pdev->id);
  358. return -EINVAL;
  359. }
  360. pdriver_dev = devm_kzalloc(&pdev->dev,sizeof(struct vvcam_dwe_driver_dev), GFP_KERNEL);
  361. if (pdriver_dev == NULL)
  362. {
  363. pr_err("%s:alloc struct vvcam_soc_driver_dev error\n", __func__);
  364. return -ENOMEM;
  365. }
  366. memset(pdriver_dev,0,sizeof(struct vvcam_dwe_driver_dev ));
  367. visys_sw_rst = ioremap(0xffe4040100, 0x00001000);
  368. #ifdef DWE_REG_RESET
  369. pdwe_dev->dwe_reset = ioremap(DWE_REG_RESET, 4);
  370. #endif
  371. #ifdef VSE_REG_RESET
  372. pdwe_dev->vse_reset = ioremap(VSE_REG_RESET, 4);
  373. #endif
  374. mutex_init(&pdriver_dev->vvmutex);
  375. platform_set_drvdata(pdev, pdriver_dev);
  376. pdriver_dev->pdev = pdev;
  377. pdriver_dev->irq_num[0] = platform_get_irq(pdev, 0);
  378. if (pdriver_dev->irq_num[0] == 0) {
  379. pr_err("%s:dw200_[%d]: could not map IRQ\n", __func__, pdev->id);
  380. dev_err(&pdev->dev, "could not map IRQ.\n");
  381. return -ENXIO;
  382. }
  383. dw_info("%s:dw200_[%d]: pdriver_dev->irq_num[0]=%d\n", __func__, pdev->id, pdriver_dev->irq_num[0]);
  384. pdriver_dev->irq_num[1] = platform_get_irq(pdev, 1);
  385. if (pdriver_dev->irq_num[1] == 0) {
  386. pr_err("%s:dw200_[%d]: could not map IRQ\n", __func__, pdev->id);
  387. dev_err(&pdev->dev, "could not map IRQ.\n");
  388. return -ENXIO;
  389. }
  390. dw_info("%s:dw200_[%d]: pdriver_dev->irq_num[1]=%d\n", __func__, pdev->id, pdriver_dev->irq_num[1]);
  391. ret = request_irq(pdriver_dev->irq_num[0], vivdw200_interrupt,
  392. IRQF_SHARED|IRQF_TRIGGER_RISING, "DEWARP_IRQ", (char *)pdriver_dev);
  393. if (ret) {
  394. pr_err("%s[%d]:request irq error!\n", __func__, __LINE__);
  395. return ret;
  396. }
  397. ret = request_irq(pdriver_dev->irq_num[1], vivdw200_interrupt,
  398. IRQF_SHARED|IRQF_TRIGGER_RISING, "SCALAR_IRQ", (char *)pdriver_dev);
  399. if (ret) {
  400. pr_err("%s[%d]:request irq error!\n", __func__, __LINE__);
  401. return ret;
  402. }
  403. #ifdef USE_RESERVED_MEM
  404. ret = vvcam_dwe_of_parse(pdev);
  405. if (ret) {
  406. pr_err("%s[%d]: vvcam_dwe_of_parse error!\n", __func__, __LINE__);
  407. return ret;
  408. }
  409. #else
  410. pr_info("%s:disable vvcam_dwe_of_parse reserved-memory\n", __func__);
  411. #endif
  412. if (devise_register_index == 0)
  413. {
  414. if (vvcam_dwe_major == 0)
  415. {
  416. ret = alloc_chrdev_region(&pdriver_dev->devt, 0, VIVCAM_DWE_MAXCNT, VIVCAM_DWE_NAME);
  417. if (ret != 0)
  418. {
  419. pr_err("%s:alloc_chrdev_region error\n", __func__);
  420. return ret;
  421. }
  422. vvcam_dwe_major = MAJOR(pdriver_dev->devt);
  423. vvcam_dwe_minor = MINOR(pdriver_dev->devt);
  424. }
  425. else
  426. {
  427. pdriver_dev->devt = MKDEV(vvcam_dwe_major, vvcam_dwe_minor);
  428. ret = register_chrdev_region(pdriver_dev->devt, VIVCAM_DWE_MAXCNT, VIVCAM_DWE_NAME);
  429. if (ret)
  430. {
  431. pr_err("%s:register_chrdev_region error\n", __func__);
  432. return ret;
  433. }
  434. }
  435. vvcam_dwe_class = class_create(THIS_MODULE, VIVCAM_DWE_NAME);
  436. if (IS_ERR(vvcam_dwe_class))
  437. {
  438. pr_err("%s[%d]:class_create error!\n", __func__, __LINE__);
  439. return -EINVAL;
  440. }
  441. }
  442. pdriver_dev->devt = MKDEV(vvcam_dwe_major, vvcam_dwe_minor + pdev->id + 1); // just in case platform instance num is -1
  443. cdev_init(&pdriver_dev->cdev, &vvcam_dwe_fops);
  444. ret = cdev_add(&pdriver_dev->cdev, pdriver_dev->devt, 1);
  445. if ( ret )
  446. {
  447. pr_err("%s[%d]:cdev_add error!\n", __func__, __LINE__);
  448. return ret;
  449. }
  450. pdriver_dev->class = vvcam_dwe_class;
  451. device_create(pdriver_dev->class, NULL, pdriver_dev->devt,
  452. pdriver_dev, "%s", VIVCAM_DWE_NAME);
  453. devise_register_index++;
  454. pdriver_dev->dweclk = devm_clk_get(&pdev->dev, "dweclk");
  455. if (IS_ERR(pdriver_dev->dweclk)) {
  456. dev_err(&pdev->dev, "failed to get dwe clk");
  457. //return -1;
  458. }
  459. pdriver_dev->vseclk = devm_clk_get(&pdev->dev, "vseclk");
  460. if (IS_ERR(pdriver_dev->vseclk)) {
  461. dev_err(&pdev->dev, "failed to get vse clk");
  462. //return -1;
  463. }
  464. pdriver_dev->hclk = devm_clk_get(&pdev->dev, "hclk");
  465. if (IS_ERR(pdriver_dev->hclk)) {
  466. dev_err(&pdev->dev, "failed to get hclk");
  467. //return -1;
  468. }
  469. pdriver_dev->aclk = devm_clk_get(&pdev->dev, "aclk");
  470. if (IS_ERR(pdriver_dev->aclk)) {
  471. dev_err(&pdev->dev, "failed to get aclk");
  472. //return -1;
  473. }
  474. pm_runtime_enable(&pdev->dev);
  475. pm_runtime_resume_and_get(&pdev->dev);
  476. pm_runtime_put_sync(&pdev->dev);
  477. dw_info("exit %s:[%d]\n", __func__, pdev->id);
  478. return ret;
  479. }
  480. static int vvcam_dwe_remove(struct platform_device *pdev)
  481. {
  482. struct vvcam_dwe_driver_dev *pdriver_dev;
  483. //struct dw200_subdev * pdwe_dev;
  484. dw_info("enter %s\n", __func__);
  485. devise_register_index--;
  486. pdriver_dev = platform_get_drvdata(pdev);
  487. free_irq(pdriver_dev->irq_num[0], pdriver_dev);
  488. free_irq(pdriver_dev->irq_num[1], pdriver_dev);
  489. //pdwe_dev = pdriver_dev->private;
  490. //iounmap(pdwe_dev->dwe_base);
  491. //iounmap(pdwe_dev->vse_base);
  492. //iounmap(pdwe_dev->dwe_reset);
  493. //iounmap(pdwe_dev->vse_reset);
  494. pm_runtime_disable(&pdev->dev);
  495. if (!pm_runtime_status_suspended(&pdev->dev)) { // turn off the power regardless of the ref cnt
  496. vvcam_dwe_runtime_suspend(&pdev->dev);
  497. }
  498. cdev_del(&pdriver_dev->cdev);
  499. device_destroy(pdriver_dev->class, pdriver_dev->devt);
  500. unregister_chrdev_region(pdriver_dev->devt, VIVCAM_DWE_MAXCNT);
  501. if (devise_register_index == 0)
  502. {
  503. class_destroy(pdriver_dev->class);
  504. }
  505. return 0;
  506. }
  507. static const struct of_device_id dewarp_of_match[] = {
  508. { .compatible = "thead,light-dewarp", },
  509. { /* sentinel */ },
  510. };
  511. static struct platform_driver vvcam_dwe_driver = {
  512. .probe = vvcam_dwe_probe,
  513. .remove = vvcam_dwe_remove,
  514. .driver = {
  515. .name = VIVCAM_DWE_NAME,
  516. .owner = THIS_MODULE,
  517. .of_match_table = of_match_ptr(dewarp_of_match),
  518. .pm = &vvcam_dwe_runtime_pm_ops,
  519. }
  520. };
  521. static int __init vvcam_dwe_init_module(void)
  522. {
  523. int ret = 0;
  524. dw_info("enter %s\n", __func__);
  525. ret = platform_driver_register(&vvcam_dwe_driver);
  526. if (ret)
  527. {
  528. pr_err("register platform driver failed.\n");
  529. return ret;
  530. }
  531. return ret;
  532. }
  533. static void __exit vvcam_dwe_exit_module(void)
  534. {
  535. dw_info("enter %s\n", __func__);
  536. platform_driver_unregister(&vvcam_dwe_driver);
  537. }
  538. module_init(vvcam_dwe_init_module);
  539. module_exit(vvcam_dwe_exit_module);
  540. MODULE_DESCRIPTION("DWE");
  541. MODULE_LICENSE("GPL");