sim_slot.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /*
  2. * Copyright (c) 2010-2011 Samsung Electronics Co., Ltd.
  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. #include "sim_slot.h"
  9. #ifndef SIM_SLOT_PIN
  10. #error SIM_SLOT_PIN should be have a value. but not defined.
  11. #endif
  12. static int check_simslot_count(struct seq_file *m, void *v)
  13. {
  14. int retval, support_number_of_simslot;
  15. printk("\n SIM_SLOT_PIN : %d\n", SIM_SLOT_PIN); //temp log for checking GPIO Setting correctly applyed or not
  16. retval = gpio_request(SIM_SLOT_PIN,"SIM_SLOT_PIN");
  17. if (retval) {
  18. pr_err("%s:Failed to reqeust GPIO, code = %d.\n",
  19. __func__, retval);
  20. support_number_of_simslot = retval;
  21. }
  22. else
  23. {
  24. retval = gpio_direction_input(SIM_SLOT_PIN);
  25. if (retval){
  26. pr_err("%s:Failed to set direction of GPIO, code = %d.\n",
  27. __func__, retval);
  28. support_number_of_simslot = retval;
  29. }
  30. else
  31. {
  32. retval = gpio_get_value(SIM_SLOT_PIN);
  33. /* This codes are implemented assumption that count of GPIO about simslot is only one on H/W schematic
  34. You may change this codes if count of GPIO about simslot has change */
  35. switch(retval)
  36. {
  37. case SINGLE_SIM_VALUE:
  38. support_number_of_simslot = SINGLE_SIM;
  39. break;
  40. case DUAL_SIM_VALUE :
  41. support_number_of_simslot = DUAL_SIM;
  42. break;
  43. default :
  44. support_number_of_simslot = -1;
  45. break;
  46. }
  47. }
  48. gpio_free(SIM_SLOT_PIN);
  49. }
  50. if(support_number_of_simslot < 0)
  51. {
  52. pr_err("******* Make a forced kernel panic because can't check simslot count******\n");
  53. panic("kernel panic");
  54. }
  55. seq_printf(m, "%u\n", support_number_of_simslot);
  56. return 0;
  57. }
  58. static int check_simslot_count_open(struct inode *inode, struct file *file)
  59. {
  60. return single_open(file, check_simslot_count, NULL);
  61. }
  62. static const struct file_operations check_simslot_count_fops = {
  63. .open = check_simslot_count_open,
  64. .read = seq_read,
  65. .llseek = seq_lseek,
  66. .release= single_release,
  67. };
  68. static int __init simslot_count_init(void)
  69. {
  70. if(!proc_create("simslot_count",0,NULL,&check_simslot_count_fops))
  71. {
  72. pr_err("***** Make a forced kernel panic because can't make a simslot_count file node ******\n");
  73. panic("kernel panic");
  74. return -ENOMEM;
  75. }
  76. else return 0;
  77. }
  78. late_initcall(simslot_count_init);