punit_atom_debug.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. /*
  2. * Intel SOC Punit device state debug driver
  3. * Punit controls power management for North Complex devices (Graphics
  4. * blocks, Image Signal Processing, video processing, display, DSP etc.)
  5. *
  6. * Copyright (c) 2015, Intel Corporation.
  7. *
  8. * This program is free software; you can redistribute it and/or modify it
  9. * under the terms and conditions of the GNU General Public License,
  10. * version 2, as published by the Free Software Foundation.
  11. *
  12. * This program is distributed in the hope it will be useful, but WITHOUT
  13. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  14. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  15. * more details.
  16. *
  17. */
  18. #include <linux/module.h>
  19. #include <linux/init.h>
  20. #include <linux/device.h>
  21. #include <linux/debugfs.h>
  22. #include <linux/seq_file.h>
  23. #include <linux/io.h>
  24. #include <asm/cpu_device_id.h>
  25. #include <asm/intel-family.h>
  26. #include <asm/iosf_mbi.h>
  27. /* Subsystem config/status Video processor */
  28. #define VED_SS_PM0 0x32
  29. /* Subsystem config/status ISP (Image Signal Processor) */
  30. #define ISP_SS_PM0 0x39
  31. /* Subsystem config/status Input/output controller */
  32. #define MIO_SS_PM 0x3B
  33. /* Shift bits for getting status for video, isp and i/o */
  34. #define SSS_SHIFT 24
  35. /* Power gate status reg */
  36. #define PWRGT_STATUS 0x61
  37. /* Shift bits for getting status for graphics rendering */
  38. #define RENDER_POS 0
  39. /* Shift bits for getting status for media control */
  40. #define MEDIA_POS 2
  41. /* Shift bits for getting status for Valley View/Baytrail display */
  42. #define VLV_DISPLAY_POS 6
  43. /* Subsystem config/status display for Cherry Trail SOC */
  44. #define CHT_DSP_SSS 0x36
  45. /* Shift bits for getting status for display */
  46. #define CHT_DSP_SSS_POS 16
  47. struct punit_device {
  48. char *name;
  49. int reg;
  50. int sss_pos;
  51. };
  52. static const struct punit_device punit_device_tng[] = {
  53. { "DISPLAY", CHT_DSP_SSS, SSS_SHIFT },
  54. { "VED", VED_SS_PM0, SSS_SHIFT },
  55. { "ISP", ISP_SS_PM0, SSS_SHIFT },
  56. { "MIO", MIO_SS_PM, SSS_SHIFT },
  57. { NULL }
  58. };
  59. static const struct punit_device punit_device_byt[] = {
  60. { "GFX RENDER", PWRGT_STATUS, RENDER_POS },
  61. { "GFX MEDIA", PWRGT_STATUS, MEDIA_POS },
  62. { "DISPLAY", PWRGT_STATUS, VLV_DISPLAY_POS },
  63. { "VED", VED_SS_PM0, SSS_SHIFT },
  64. { "ISP", ISP_SS_PM0, SSS_SHIFT },
  65. { "MIO", MIO_SS_PM, SSS_SHIFT },
  66. { NULL }
  67. };
  68. static const struct punit_device punit_device_cht[] = {
  69. { "GFX RENDER", PWRGT_STATUS, RENDER_POS },
  70. { "GFX MEDIA", PWRGT_STATUS, MEDIA_POS },
  71. { "DISPLAY", CHT_DSP_SSS, CHT_DSP_SSS_POS },
  72. { "VED", VED_SS_PM0, SSS_SHIFT },
  73. { "ISP", ISP_SS_PM0, SSS_SHIFT },
  74. { "MIO", MIO_SS_PM, SSS_SHIFT },
  75. { NULL }
  76. };
  77. static const char * const dstates[] = {"D0", "D0i1", "D0i2", "D0i3"};
  78. static int punit_dev_state_show(struct seq_file *seq_file, void *unused)
  79. {
  80. u32 punit_pwr_status;
  81. struct punit_device *punit_devp = seq_file->private;
  82. int index;
  83. int status;
  84. seq_puts(seq_file, "\n\nPUNIT NORTH COMPLEX DEVICES :\n");
  85. while (punit_devp->name) {
  86. status = iosf_mbi_read(BT_MBI_UNIT_PMC, MBI_REG_READ,
  87. punit_devp->reg, &punit_pwr_status);
  88. if (status) {
  89. seq_printf(seq_file, "%9s : Read Failed\n",
  90. punit_devp->name);
  91. } else {
  92. index = (punit_pwr_status >> punit_devp->sss_pos) & 3;
  93. seq_printf(seq_file, "%9s : %s\n", punit_devp->name,
  94. dstates[index]);
  95. }
  96. punit_devp++;
  97. }
  98. return 0;
  99. }
  100. static int punit_dev_state_open(struct inode *inode, struct file *file)
  101. {
  102. return single_open(file, punit_dev_state_show, inode->i_private);
  103. }
  104. static const struct file_operations punit_dev_state_ops = {
  105. .open = punit_dev_state_open,
  106. .read = seq_read,
  107. .llseek = seq_lseek,
  108. .release = single_release,
  109. };
  110. static struct dentry *punit_dbg_file;
  111. static int punit_dbgfs_register(struct punit_device *punit_device)
  112. {
  113. static struct dentry *dev_state;
  114. punit_dbg_file = debugfs_create_dir("punit_atom", NULL);
  115. if (!punit_dbg_file)
  116. return -ENXIO;
  117. dev_state = debugfs_create_file("dev_power_state", S_IFREG | S_IRUGO,
  118. punit_dbg_file, punit_device,
  119. &punit_dev_state_ops);
  120. if (!dev_state) {
  121. pr_err("punit_dev_state register failed\n");
  122. debugfs_remove(punit_dbg_file);
  123. return -ENXIO;
  124. }
  125. return 0;
  126. }
  127. static void punit_dbgfs_unregister(void)
  128. {
  129. debugfs_remove_recursive(punit_dbg_file);
  130. }
  131. #define ICPU(model, drv_data) \
  132. { X86_VENDOR_INTEL, 6, model, X86_FEATURE_MWAIT,\
  133. (kernel_ulong_t)&drv_data }
  134. static const struct x86_cpu_id intel_punit_cpu_ids[] = {
  135. ICPU(INTEL_FAM6_ATOM_SILVERMONT1, punit_device_byt),
  136. ICPU(INTEL_FAM6_ATOM_MERRIFIELD, punit_device_tng),
  137. ICPU(INTEL_FAM6_ATOM_AIRMONT, punit_device_cht),
  138. {}
  139. };
  140. MODULE_DEVICE_TABLE(x86cpu, intel_punit_cpu_ids);
  141. static int __init punit_atom_debug_init(void)
  142. {
  143. const struct x86_cpu_id *id;
  144. int ret;
  145. id = x86_match_cpu(intel_punit_cpu_ids);
  146. if (!id)
  147. return -ENODEV;
  148. ret = punit_dbgfs_register((struct punit_device *)id->driver_data);
  149. if (ret < 0)
  150. return ret;
  151. return 0;
  152. }
  153. static void __exit punit_atom_debug_exit(void)
  154. {
  155. punit_dbgfs_unregister();
  156. }
  157. module_init(punit_atom_debug_init);
  158. module_exit(punit_atom_debug_exit);
  159. MODULE_AUTHOR("Kumar P, Mahesh <mahesh.kumar.p@intel.com>");
  160. MODULE_AUTHOR("Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>");
  161. MODULE_DESCRIPTION("Driver for Punit devices states debugging");
  162. MODULE_LICENSE("GPL v2");