bm_csi_dphy.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /*
  2. * Copyright (C) 2021 Alibaba Group Holding Limited
  3. * Author: liuyitong <yitong.lyt@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. #include "bm_printk.h"
  31. #include "bm_csi_ioctl.h"
  32. #include "bm_csi_hw.h"
  33. #include "bm_csi_dphy.h"
  34. #include "dw-dphy-rx.h"
  35. #define check_retval(x)\
  36. do {\
  37. if ((x))\
  38. return -EIO;\
  39. } while (0)
  40. #define REG_DPHY_OFFSET 0x40
  41. int bm_csi_dphy_write_reg(struct bm_csi_drvdata *drvdata, void *__user args)
  42. {
  43. struct bm_csi_reg_t reg;
  44. check_retval(copy_from_user(&reg, args, sizeof(reg)));
  45. struct dw_dphy_rx *dphy = drvdata->dphy;
  46. writel(reg.value, dphy->base_address + reg.offset);
  47. bm_info("%s addr 0x%08x val 0x%08x\n", __func__, reg.offset, reg.value);
  48. }
  49. int bm_csi_dphy_init(struct bm_csi_drvdata *drvdata, void *__user args)
  50. {
  51. struct dw_dphy_rx *dphy = drvdata->dphy;
  52. /*
  53. dphy->dphy_freq = 20000000;
  54. dphy->phy_type = 1;
  55. dphy->dphy_te_len = BIT12;
  56. dphy->lanes_config = CTRL_4_LANES;
  57. dphy->dphy_gen = GEN3;
  58. dphy->max_lanes = CTRL_4_LANES;
  59. dphy->lp_time = 1000; //ns
  60. dphy->base_address = drvdata->base + REG_DPHY_OFFSET;
  61. //dphy->dphy1_if_addr =visysreg
  62. dw_dphy_reset(dphy);
  63. dw_dphy_power_on(dphy);
  64. dw_dphy_init(dphy);
  65. */
  66. return 0;
  67. }
  68. int bm_csi_dphy_uinit(struct bm_csi_drvdata *drvdata, void *__user args)
  69. {
  70. struct dw_dphy_rx *dphy = &drvdata->dphy;
  71. dw_dphy_reset(dphy);
  72. dw_dphy_power_off(dphy);
  73. }
  74. int bm_csi_dphy_reset(struct bm_csi_drvdata *drvdata, void *__user args)
  75. {
  76. struct dw_dphy_rx *dphy = &drvdata->dphy;
  77. dw_dphy_reset(dphy);
  78. }