/drivers/media/isdbtmm/tuner_drv_wrap.c

https://gitlab.com/SerenityS/android_kernel_jalteskt · C · 334 lines · 177 code · 34 blank · 123 comment · 16 complexity · 4a3eb81a52d10091de02fa7a6defe009 MD5 · raw file

  1. /*
  2. *
  3. * drivers/media/isdbtmm/tuner_drv_wrap.c
  4. *
  5. * MM Tuner Driver
  6. *
  7. * Copyright (C) (2013, Samsung Electronics)
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation version 2.
  12. *
  13. * This program is distributed "as is" WITHOUT ANY WARRANTY of any
  14. * kind, whether express or implied; without even the implied warranty
  15. * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. */
  19. /******************************************************************************
  20. * include
  21. ******************************************************************************/
  22. #include <linux/module.h>
  23. #include <linux/kernel.h>
  24. #include <linux/init.h>
  25. #include <linux/types.h>
  26. #include <linux/fs.h>
  27. #include <linux/cdev.h>
  28. #include <linux/sched.h>
  29. #include <linux/platform_device.h>
  30. #include <linux/device.h>
  31. #include <linux/err.h>
  32. #include <linux/slab.h>
  33. #include <linux/i2c.h>
  34. #include <linux/i2c-dev.h>
  35. #include <linux/mm.h>
  36. #include <asm/uaccess.h>
  37. #include "tuner_drv.h"
  38. #include <asm/system_info.h>
  39. #ifdef TUNER_CONFIG_IRQ_PC_LINUX
  40. #include "../../../i2c-parport-x/i2c-parport.h"
  41. #endif /* TUNER_CONFIG_IRQ_PC_LINUX */
  42. /******************************************************************************/
  43. /* function */
  44. /******************************************************************************/
  45. int tuner_drv_ctl_power( int data );
  46. int tuner_drv_set_interrupt( void );
  47. void tuner_drv_release_interrupt( void );
  48. void tuner_drv_gpio_config_poweron( void );
  49. void tuner_drv_gpio_config_poweroff( void );
  50. /******************************************************************************
  51. * code area
  52. ******************************************************************************/
  53. /******************************************************************************
  54. * function: tuner_drv_ctl_power
  55. * brief : power control of a driver
  56. * date : 2011.08.26
  57. * author : M.Takahashi(*)
  58. *
  59. * return : 0 normal exit
  60. * : -1 error exit
  61. * input : data setting data
  62. * output : none
  63. ******************************************************************************/
  64. int tuner_drv_ctl_power( int data )
  65. {
  66. /* power on */
  67. if( data == TUNER_DRV_CTL_POWON )
  68. {
  69. DEBUG_PRINT("tuner_drv_ctl_power poweron\n");
  70. /* poweron gpio config setting */
  71. tuner_drv_gpio_config_poweron();
  72. /* TMM_PWR_EN high */
  73. gpio_set_value(GPIO_TMM_PWR_EN, GPIO_LEVEL_HIGH);
  74. /* 15ms sleep */
  75. usleep_range(15000, 15000);
  76. /* TMM_RST high */
  77. gpio_set_value(GPIO_TMM_RST, GPIO_LEVEL_HIGH);
  78. /* 2ms sleep */
  79. usleep_range(2000, 2000);
  80. }
  81. /* power off */
  82. else
  83. {
  84. DEBUG_PRINT("tuner_drv_ctl_power poweroff\n");
  85. /* poweroff gpio config setting */
  86. tuner_drv_gpio_config_poweroff();
  87. /* 1ms sleep */
  88. usleep_range(1000, 1000);
  89. /* TMM_RST low */
  90. gpio_set_value(GPIO_TMM_RST, GPIO_LEVEL_LOW);
  91. /* 2ms sleep */
  92. usleep_range(2000, 2000);
  93. /* TMM_PWR_EN low */
  94. gpio_set_value(GPIO_TMM_PWR_EN, GPIO_LEVEL_LOW);
  95. }
  96. return 0;
  97. }
  98. /******************************************************************************
  99. * function: tuner_drv_set_interrupt
  100. * brief : interruption registration control of a driver
  101. * date : 2011.08.26
  102. * author : M.Takahashi(*)
  103. *
  104. * return : 0 normal exit
  105. * : -1 error exit
  106. * input : pdev
  107. * output : none
  108. ******************************************************************************/
  109. int tuner_drv_set_interrupt( void )
  110. {
  111. #ifndef TUNER_CONFIG_IRQ_PC_LINUX
  112. int ret;
  113. if(system_rev == 0x01)
  114. {
  115. /* HW-REV-0.3(0x01) */
  116. ret = request_irq( GPIO_TMM_INT_REV03,
  117. tuner_interrupt,
  118. IRQF_DISABLED | IRQF_TRIGGER_RISING,
  119. "mm_tuner",
  120. NULL );
  121. }
  122. else
  123. {
  124. /* HW-REV-0.0(0x0b), HW-REV-0.1(0x09) */
  125. ret = request_irq( GPIO_TMM_INT_REV00,
  126. tuner_interrupt,
  127. IRQF_DISABLED | IRQF_TRIGGER_RISING,
  128. "mm_tuner",
  129. NULL );
  130. }
  131. if( ret != 0 )
  132. {
  133. return -1;
  134. }
  135. #else /* TUNER_CONFIG_IRQ_PC_LINUX */
  136. i2c_set_interrupt( tuner_interrupt );
  137. #endif /* TUNER_CONFIG_IRQ_PC_LINUX */
  138. return 0;
  139. }
  140. /******************************************************************************
  141. * function: tuner_drv_release_interrupt
  142. * brief : interruption registration release control of a driver
  143. * date : 2011.08.26
  144. * author : M.Takahashi(*)
  145. *
  146. * return : none
  147. * input : none
  148. * output : none
  149. ******************************************************************************/
  150. void tuner_drv_release_interrupt( void )
  151. {
  152. #ifndef TUNER_CONFIG_IRQ_PC_LINUX
  153. if(system_rev == 0x01)
  154. {
  155. /* HW-REV-0.3(0x01) */
  156. free_irq( GPIO_TMM_INT_REV03, NULL );
  157. }
  158. else
  159. {
  160. /* HW-REV-0.0(0x0b), HW-REV-0.1(0x09) */
  161. free_irq( GPIO_TMM_INT_REV00, NULL );
  162. }
  163. #else /* TUNER_CONFIG_IRQ_PC_LINUX */
  164. i2c_release_interrupt( NULL );
  165. #endif /* TUNER_CONFIG_IRQ_PC_LINUX */
  166. }
  167. #ifdef TUNER_CONFIG_IRQ_LEVELTRIGGER
  168. /******************************************************************************
  169. * function: tuner_drv_enable_interrupt
  170. * brief : interruption registration enable control of a driver
  171. * date : 2011.09.18
  172. * author : M.Takahashi(*)(*)
  173. *
  174. * return : none
  175. * input : none
  176. * output : none
  177. ******************************************************************************/
  178. void tuner_drv_enable_interrupt( void )
  179. {
  180. #ifndef TUNER_CONFIG_IRQ_PC_LINUX
  181. if(system_rev == 0x01)
  182. {
  183. /* HW-REV-0.3(0x01) */
  184. enable_irq( GPIO_TMM_INT_REV03)
  185. }
  186. else
  187. {
  188. /* HW-REV-0.0(0x0b), HW-REV-0.1(0x09) */
  189. enable_irq( GPIO_TMM_INT_REV00)
  190. }
  191. #else /* TUNER_CONFIG_IRQ_PC_LINUX */
  192. i2c_set_interrupt( tuner_interrupt );
  193. #endif /* TUNER_CONFIG_IRQ_PC_LINUX */
  194. }
  195. /******************************************************************************
  196. * function: tuner_drv_disable_interrupt
  197. * brief : interruption registration disable control of a driver
  198. * date : 2011.09.18
  199. * author : M.Takahashi(*)(*)
  200. *
  201. * return : none
  202. * input : none
  203. * output : none
  204. ******************************************************************************/
  205. void tuner_drv_disable_interrupt( void )
  206. {
  207. #ifndef TUNER_CONFIG_IRQ_PC_LINUX
  208. if(system_rev == 0x01)
  209. {
  210. /* HW-REV-0.3(0x01) */
  211. disable_irq( GPIO_TMM_INT_REV03);
  212. }
  213. else
  214. {
  215. /* HW-REV-0.0(0x0b), HW-REV-0.1(0x09) */
  216. disable_irq( GPIO_TMM_INT_REV00);
  217. }
  218. #else /* TUNER_CONFIG_IRQ_PC_LINUX */
  219. i2c_release_interrupt( NULL );
  220. #endif /* TUNER_CONFIG_IRQ_PC_LINUX */
  221. }
  222. #endif /* TUNER_CONFIG_IRQ_LEVELTRIGGER */
  223. /******************************************************************************
  224. * function: tuner_drv_gpio_config_poweron
  225. * brief : interruption registration disable control of a driver
  226. * date : 2012.12.18
  227. * author : K.Matsumaru(*)(*)
  228. *
  229. * return : none
  230. * input : none
  231. * output : none
  232. ******************************************************************************/
  233. void tuner_drv_gpio_config_poweron( void )
  234. {
  235. if(system_rev == 0x01)
  236. {
  237. /* HW-REV-0.3(0x01) */
  238. s3c_gpio_cfgpin(GPIO_TMM_INT_REV03, S3C_GPIO_INPUT);
  239. s3c_gpio_setpull(GPIO_TMM_INT_REV03, S3C_GPIO_PULL_NONE);
  240. }
  241. else
  242. {
  243. /* HW-REV-0.0(0x0b), HW-REV-0.1(0x09) */
  244. s3c_gpio_cfgpin(GPIO_TMM_INT_REV00, S3C_GPIO_INPUT);
  245. s3c_gpio_setpull(GPIO_TMM_INT_REV00, S3C_GPIO_PULL_NONE);
  246. }
  247. s3c_gpio_cfgpin(GPIO_TMM_RST, S3C_GPIO_OUTPUT);
  248. s3c_gpio_setpull(GPIO_TMM_RST, S3C_GPIO_PULL_NONE);
  249. gpio_set_value(GPIO_TMM_RST, GPIO_LEVEL_LOW);
  250. s3c_gpio_cfgpin(GPIO_TMM_PWR_EN, S3C_GPIO_OUTPUT);
  251. s3c_gpio_setpull(GPIO_TMM_PWR_EN, S3C_GPIO_PULL_NONE);
  252. gpio_set_value(GPIO_TMM_PWR_EN, GPIO_LEVEL_LOW);
  253. s3c_gpio_cfgpin(GPIO_LTE_SPI_CLK, GPIO_SPI_SFN);
  254. s3c_gpio_setpull(GPIO_LTE_SPI_CLK, S3C_GPIO_PULL_NONE);
  255. s3c_gpio_cfgpin(GPIO_LTE_SPI_MISO, GPIO_SPI_SFN);
  256. s3c_gpio_setpull(GPIO_LTE_SPI_MISO, S3C_GPIO_PULL_NONE);
  257. s3c_gpio_cfgpin(GPIO_LTE_SPI_CSN, GPIO_SPI_SFN);
  258. s3c_gpio_setpull(GPIO_LTE_SPI_CSN, S3C_GPIO_PULL_NONE);
  259. s3c_gpio_cfgpin(GPIO_LTE_SPI_MOSI, GPIO_SPI_SFN);
  260. s3c_gpio_setpull(GPIO_LTE_SPI_MOSI, S3C_GPIO_PULL_NONE);
  261. }
  262. /******************************************************************************
  263. * function: tuner_drv_gpio_config_poweroff
  264. * brief : interruption registration disable control of a driver
  265. * date : 2012.12.18
  266. * author : K.Matsumaru(*)(*)
  267. *
  268. * return : none
  269. * input : none
  270. * output : none
  271. ******************************************************************************/
  272. void tuner_drv_gpio_config_poweroff( void )
  273. {
  274. if(system_rev == 0x01)
  275. {
  276. /* HW-REV-0.3(0x01) */
  277. s3c_gpio_cfgpin(GPIO_TMM_INT_REV03, S3C_GPIO_INPUT);
  278. s3c_gpio_setpull(GPIO_TMM_INT_REV03, S3C_GPIO_PULL_NONE);
  279. }
  280. else
  281. {
  282. /* HW-REV-0.0(0x0b), HW-REV-0.1(0x09) */
  283. s3c_gpio_cfgpin(GPIO_TMM_INT_REV00, S3C_GPIO_INPUT);
  284. s3c_gpio_setpull(GPIO_TMM_INT_REV00, S3C_GPIO_PULL_NONE);
  285. }
  286. s3c_gpio_cfgpin(GPIO_TMM_RST, S3C_GPIO_OUTPUT);
  287. s3c_gpio_setpull(GPIO_TMM_RST, S3C_GPIO_PULL_NONE);
  288. gpio_set_value(GPIO_TMM_RST, GPIO_LEVEL_LOW);
  289. s3c_gpio_cfgpin(GPIO_TMM_PWR_EN, S3C_GPIO_OUTPUT);
  290. s3c_gpio_setpull(GPIO_TMM_PWR_EN, S3C_GPIO_PULL_NONE);
  291. gpio_set_value(GPIO_TMM_PWR_EN, GPIO_LEVEL_LOW);
  292. s3c_gpio_cfgpin(GPIO_LTE_SPI_CLK, GPIO_SPI_SFN);
  293. s3c_gpio_setpull(GPIO_LTE_SPI_CLK, S3C_GPIO_PULL_DOWN);
  294. s3c_gpio_cfgpin(GPIO_LTE_SPI_MISO, GPIO_SPI_SFN);
  295. s3c_gpio_setpull(GPIO_LTE_SPI_MISO, S3C_GPIO_PULL_DOWN);
  296. s3c_gpio_cfgpin(GPIO_LTE_SPI_CSN, GPIO_SPI_SFN);
  297. s3c_gpio_setpull(GPIO_LTE_SPI_CSN, S3C_GPIO_PULL_DOWN);
  298. s3c_gpio_cfgpin(GPIO_LTE_SPI_MOSI, GPIO_SPI_SFN);
  299. s3c_gpio_setpull(GPIO_LTE_SPI_MOSI, S3C_GPIO_PULL_DOWN);
  300. }