Advertisement
Guest User

Untitled

a guest
Jun 22nd, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.24 KB | None | 0 0
  1. /*
  2. * platform driver for msm_wifi device
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License version 2 as
  6. * published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope that it will be useful, but
  9. * WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. * General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public License
  14. * along with this program; if not, write to the Free Software
  15. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  16. * 02110-1301 USA
  17. *
  18. * Copyright (C) 2008 Google Inc
  19. */
  20. #include <linux/platform_device.h>
  21. #include <linux/wifi_tiwlan.h>
  22. #include <linux/proc_fs.h>
  23.  
  24. extern unsigned char *get_wifi_nvs_ram(void);
  25. static struct proc_dir_entry *tiwlan_calibration;
  26.  
  27. #define WIFI_NVS_LEN_OFFSET 0x0C
  28. #define WIFI_NVS_DATA_OFFSET 0x40
  29. #define WIFI_NVS_MAX_SIZE 0x800UL
  30.  
  31. static unsigned long tiwlan_get_nvs_size( void )
  32. {
  33. unsigned char *ptr;
  34. unsigned long len;
  35.  
  36. ptr = get_wifi_nvs_ram();
  37. if( ptr == NULL ) {
  38. return 0;
  39. }
  40. /* Size in format LE assumed */
  41. memcpy( (void *)&len, (void *)(ptr + WIFI_NVS_LEN_OFFSET), sizeof(len) );
  42. len = min( len, (WIFI_NVS_MAX_SIZE-WIFI_NVS_DATA_OFFSET) );
  43. return len;
  44. }
  45.  
  46. static int tiwlan_calibration_read_proc(char *page, char **start, off_t off,
  47. int count, int *eof, void *data)
  48. {
  49. unsigned char *ptr;
  50. unsigned long len;
  51.  
  52. ptr = get_wifi_nvs_ram();
  53. if( ptr == NULL ) {
  54. return 0;
  55. }
  56. len = tiwlan_get_nvs_size();
  57. /* i += sprintf(page+i, "WiFi Calibration Size = %lu %x bytes\n", len); */
  58. memcpy( (void *)page, (void *)(ptr + WIFI_NVS_DATA_OFFSET), len );
  59. return len;
  60. }
  61.  
  62. static int tiwlan_calibration_write_proc(struct file *file, const char *buffer,
  63. unsigned long count, void *data)
  64. {
  65. return 0;
  66. }
  67.  
  68. static int wifi_probe(struct platform_device *pdev)
  69. {
  70. struct wifi_platform_data *wifi_ctrl =
  71. (struct wifi_platform_data *)(pdev->dev.platform_data);
  72.  
  73. printk(KERN_DEBUG "wifi probe start\n");
  74.  
  75. if (!wifi_ctrl)
  76. return -ENODEV;
  77.  
  78. if (wifi_ctrl->set_power)
  79. wifi_ctrl->set_power(1); /* Power On */
  80. if (wifi_ctrl->set_reset)
  81. wifi_ctrl->set_reset(0); /* Reset clear */
  82. if (wifi_ctrl->set_carddetect)
  83. wifi_ctrl->set_carddetect(1); /* CardDetect (0->1) */
  84.  
  85. printk(KERN_DEBUG "wifi probe done\n");
  86. return 0;
  87. }
  88.  
  89. static int wifi_remove(struct platform_device *pdev)
  90. {
  91. struct wifi_platform_data *wifi_ctrl =
  92. (struct wifi_platform_data *)(pdev->dev.platform_data);
  93.  
  94. printk(KERN_DEBUG "wifi remove start\n");
  95. if (!wifi_ctrl)
  96. return -ENODEV;
  97.  
  98. if (wifi_ctrl->set_carddetect)
  99. wifi_ctrl->set_carddetect(0); /* CardDetect (1->0) */
  100. if (wifi_ctrl->set_reset)
  101. wifi_ctrl->set_reset(1); /* Reset active */
  102. if (wifi_ctrl->set_power)
  103. wifi_ctrl->set_power(0); /* Power Off */
  104.  
  105. printk(KERN_DEBUG "wifi remove end\n");
  106. return 0;
  107. }
  108.  
  109. static struct platform_driver wifi_device = {
  110. .probe = wifi_probe,
  111. .remove = wifi_remove,
  112. .driver = {
  113. .name = "msm_wifi",
  114. },
  115. };
  116.  
  117. static int __init msm_wifi_sdio_init(void)
  118. {
  119. tiwlan_calibration = create_proc_entry("calibration", 0644, NULL);
  120. if (tiwlan_calibration) {
  121. tiwlan_calibration->size = tiwlan_get_nvs_size();
  122. tiwlan_calibration->read_proc = tiwlan_calibration_read_proc;
  123. tiwlan_calibration->write_proc = tiwlan_calibration_write_proc;
  124. }
  125. return platform_driver_register(&wifi_device);
  126. }
  127.  
  128. static void __exit msm_wifi_sdio_exit(void)
  129. {
  130. platform_driver_unregister(&wifi_device);
  131. }
  132.  
  133. module_init(msm_wifi_sdio_init);
  134. module_exit(msm_wifi_sdio_exit);
  135. MODULE_LICENSE("GPL");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement