hdmi_tx_reg.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. /*
  2. * Amlogic M1
  3. * frame buffer driver-----------HDMI_TX
  4. * Copyright (C) 2010 Amlogic, Inc.
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the named License,
  9. * or any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. */
  17. #ifndef AVOS
  18. #include <linux/version.h>
  19. #include <linux/module.h>
  20. #include <linux/types.h>
  21. #include <linux/kernel.h>
  22. #include <linux/interrupt.h>
  23. #include <linux/fs.h>
  24. #include <linux/init.h>
  25. #include <linux/device.h>
  26. #include <linux/mm.h>
  27. #include <linux/major.h>
  28. #include <linux/platform_device.h>
  29. #include <linux/mutex.h>
  30. #include <linux/cdev.h>
  31. #include <asm/uaccess.h>
  32. #include <mach/am_regs.h>
  33. #else
  34. #include "ioapi.h"
  35. #include <chipsupport/chipsupport.h>
  36. #include <os/extend/interrupt.h>
  37. #include <Drivers/include/peripheral_reg.h>
  38. #include <Drivers/include/isa_reg.h>
  39. #include <Drivers/include/mpeg_reg.h>
  40. #include <interrupt.h>
  41. #include "displaydev.h"
  42. #include "policy.h"
  43. #endif
  44. #include "hdmi_tx_reg.h"
  45. #ifdef AVOS
  46. void WRITE_APB_REG(unsigned long addr, unsigned long data)
  47. {
  48. *((volatile unsigned long *) (APB_BASE+addr)) = data;
  49. }
  50. unsigned long READ_APB_REG(unsigned long addr)
  51. {
  52. unsigned long data;
  53. data = *((volatile unsigned long *)(APB_BASE+addr));
  54. return data;
  55. }
  56. #endif
  57. // In order to prevent system hangup, add check_cts_hdmi_sys_clk_status() to check
  58. // clock gate status . If status == 0, turn on gate first and then access HDMI port.
  59. static void check_cts_hdmi_sys_clk_status(void)
  60. {
  61. int status;
  62. status = READ_MPEG_REG(HHI_HDMI_CLK_CNTL) & (1<<8);
  63. if(status == 0){
  64. // turn on clock gate
  65. printk("HDMI System Clock is off, turn on now\n");
  66. WRITE_MPEG_REG(HHI_HDMI_CLK_CNTL, READ_MPEG_REG(HHI_HDMI_CLK_CNTL)|(1<<8));
  67. //delay some time
  68. status = 100;
  69. while(status--)
  70. ;
  71. }
  72. else{
  73. //do nothing
  74. }
  75. }
  76. unsigned long hdmi_rd_reg(unsigned long addr)
  77. {
  78. unsigned long data;
  79. check_cts_hdmi_sys_clk_status();
  80. WRITE_APB_REG(HDMI_ADDR_PORT, addr);
  81. WRITE_APB_REG(HDMI_ADDR_PORT, addr);
  82. data = READ_APB_REG(HDMI_DATA_PORT);
  83. return (data);
  84. }
  85. void hdmi_wr_only_reg(unsigned long addr, unsigned long data)
  86. {
  87. check_cts_hdmi_sys_clk_status();
  88. WRITE_APB_REG(HDMI_ADDR_PORT, addr);
  89. WRITE_APB_REG(HDMI_ADDR_PORT, addr);
  90. WRITE_APB_REG(HDMI_DATA_PORT, data);
  91. }
  92. void hdmi_wr_reg(unsigned long addr, unsigned long data)
  93. {
  94. unsigned long rd_data;
  95. check_cts_hdmi_sys_clk_status();
  96. WRITE_APB_REG(HDMI_ADDR_PORT, addr);
  97. WRITE_APB_REG(HDMI_ADDR_PORT, addr);
  98. WRITE_APB_REG(HDMI_DATA_PORT, data);
  99. rd_data = hdmi_rd_reg (addr);
  100. if (rd_data != data)
  101. {
  102. //printk("hdmi_wr_reg(%x,%x) fails to write: %x\n",addr, data, rd_data);
  103. //while(1){};
  104. }
  105. }