AudDrv_Gpio.c 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323
  1. /*
  2. * Copyright (C) 2007 The Android Open Source Project
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. /*******************************************************************************
  17. *
  18. * Filename:
  19. * ---------
  20. * AudDrv_Gpio.c
  21. *
  22. * Project:
  23. * --------
  24. * MT6735 Audio Driver GPIO
  25. *
  26. * Description:
  27. * ------------
  28. * Audio register
  29. *
  30. * Author:
  31. * -------
  32. * George
  33. *
  34. *------------------------------------------------------------------------------
  35. *
  36. *
  37. *******************************************************************************/
  38. /*****************************************************************************
  39. * C O M P I L E R F L A G S
  40. *****************************************************************************/
  41. /*****************************************************************************
  42. * E X T E R N A L R E F E R E N C E S
  43. *****************************************************************************/
  44. #if !defined(CONFIG_MTK_LEGACY)
  45. #include <linux/gpio.h>
  46. #include <linux/pinctrl/consumer.h>
  47. #else
  48. #include <mt-plat/mt_gpio.h>
  49. #endif
  50. #include "AudDrv_Gpio.h"
  51. #if !defined(CONFIG_MTK_LEGACY)
  52. struct pinctrl *pinctrlaud;
  53. /*struct pinctrl_state *pins_default;
  54. struct pinctrl_state *audpmic_mode0, *audpmic_mode1, *audi2s1_mode0, *audi2s1_mode1;
  55. struct pinctrl_state *audextamp_high, *audextamp_low, *audextamp2_high, *audextamp2_low;
  56. struct pinctrl_state *audcvspk_high, *audcvspk_low;*/
  57. enum audio_system_gpio_type {
  58. GPIO_DEFAULT = 0,
  59. GPIO_PMIC_MODE0,
  60. GPIO_PMIC_MODE1,
  61. GPIO_I2S_MODE0,
  62. GPIO_I2S_MODE1,
  63. GPIO_EXTAMP_HIGH,
  64. GPIO_EXTAMP_LOW,
  65. GPIO_EXTAMP2_HIGH,
  66. GPIO_EXTAMP2_LOW,
  67. GPIO_RCVSPK_HIGH,
  68. GPIO_RCVSPK_LOW,
  69. GPIO_NUM
  70. };
  71. struct audio_gpio_attr {
  72. const char *name;
  73. bool gpio_prepare;
  74. struct pinctrl_state *gpioctrl;
  75. };
  76. static struct audio_gpio_attr aud_gpios[GPIO_NUM] = {
  77. [GPIO_DEFAULT] = {"default", false, NULL},
  78. [GPIO_PMIC_MODE0] = {"audpmicclk-mode0", false, NULL},
  79. [GPIO_PMIC_MODE1] = {"audpmicclk-mode1", false, NULL},
  80. [GPIO_I2S_MODE0] = {"audi2s1-mode0", false, NULL},
  81. [GPIO_I2S_MODE1] = {"audi2s1-mode1", false, NULL},
  82. [GPIO_EXTAMP_HIGH] = {"extamp-pullhigh", false, NULL},
  83. [GPIO_EXTAMP_LOW] = {"extamp-pulllow", false, NULL},
  84. [GPIO_EXTAMP2_HIGH] = {"extamp2-pullhigh", false, NULL},
  85. [GPIO_EXTAMP2_LOW] = {"extamp2-pulllow", false, NULL},
  86. [GPIO_RCVSPK_HIGH] = {"rcvspk-pullhigh", false, NULL},
  87. [GPIO_RCVSPK_LOW] = {"rcvspk-pulllow", false, NULL},
  88. };
  89. void AudDrv_GPIO_probe(void *dev)
  90. {
  91. int ret;
  92. int i = 0;
  93. pr_warn("%s\n", __func__);
  94. pinctrlaud = devm_pinctrl_get(dev);
  95. if (IS_ERR(pinctrlaud)) {
  96. ret = PTR_ERR(pinctrlaud);
  97. pr_err("Cannot find pinctrlaud!\n");
  98. return;
  99. }
  100. for (i = 0; i < ARRAY_SIZE(aud_gpios); i++) {
  101. aud_gpios[i].gpioctrl = pinctrl_lookup_state(pinctrlaud, aud_gpios[i].name);
  102. if (IS_ERR(aud_gpios[i].gpioctrl)) {
  103. ret = PTR_ERR(aud_gpios[i].gpioctrl);
  104. pr_err("%s pinctrl_lookup_state %s fail %d\n", __func__, aud_gpios[i].name,
  105. ret);
  106. } else {
  107. aud_gpios[i].gpio_prepare = true;
  108. }
  109. }
  110. #if 0
  111. pins_default = pinctrl_lookup_state(pinctrlaud, "default");
  112. if (IS_ERR(pins_default)) {
  113. ret = PTR_ERR(pins_default);
  114. dev_err(&pdev->dev, "Cannot find aud pinctrl default!\n");
  115. return;
  116. }
  117. audpmic_mode0 = pinctrl_lookup_state(pinctrlaud, "audpmicclk-mode0");
  118. if (IS_ERR(audpmic_mode0)) {
  119. ret = PTR_ERR(audpmic_mode0);
  120. dev_err(&pdev->dev, "Cannot find pinctrl audpmic_mode0!\n");
  121. return;
  122. }
  123. audpmic_mode1 = pinctrl_lookup_state(pinctrlaud, "audpmicclk-mode1");
  124. if (IS_ERR(audpmic_mode1)) {
  125. ret = PTR_ERR(audpmic_mode1);
  126. dev_err(&pdev->dev, "Cannot find pinctrl audpmic_mode1!\n");
  127. return;
  128. }
  129. audi2s1_mode0 = pinctrl_lookup_state(pinctrlaud, "audi2s1-mode0");
  130. if (IS_ERR(audi2s1_mode0)) {
  131. ret = PTR_ERR(audi2s1_mode0);
  132. dev_err(&pdev->dev, "Cannot find pinctrl audi2s1_mode0!\n");
  133. return;
  134. }
  135. audi2s1_mode1 = pinctrl_lookup_state(pinctrlaud, "audi2s1-mode1");
  136. if (IS_ERR(audi2s1_mode1)) {
  137. ret = PTR_ERR(audi2s1_mode1);
  138. dev_err(&pdev->dev, "Cannot find pinctrl audi2s1_mode1!\n");
  139. return;
  140. }
  141. audextamp_high = pinctrl_lookup_state(pinctrlaud, "extamp-pullhigh");
  142. if (IS_ERR(audextamp_high)) {
  143. ret = PTR_ERR(audextamp_high);
  144. dev_err(&pdev->dev, "Cannot find pinctrl audextamp_high!\n");
  145. return;
  146. }
  147. audextamp_low = pinctrl_lookup_state(pinctrlaud, "extamp-pulllow");
  148. if (IS_ERR(audextamp_low)) {
  149. ret = PTR_ERR(audextamp_low);
  150. dev_err(&pdev->dev, "Cannot find pinctrl audextamp_low!\n");
  151. return;
  152. }
  153. audextamp2_high = pinctrl_lookup_state(pinctrlaud, "extamp2-pullhigh");
  154. if (IS_ERR(audextamp2_high)) {
  155. ret = PTR_ERR(audextamp2_high);
  156. dev_err(&pdev->dev, "Cannot find pinctrl audextamp2_high!\n");
  157. return;
  158. }
  159. audextamp2_low = pinctrl_lookup_state(pinctrlaud, "extamp2-pulllow");
  160. if (IS_ERR(audextamp2_low)) {
  161. ret = PTR_ERR(audextamp2_low);
  162. dev_err(&pdev->dev, "Cannot find pinctrl audextamp2_low!\n");
  163. return;
  164. }
  165. audcvspk_high = pinctrl_lookup_state(pinctrlaud, "rcvspk-pullhigh");
  166. if (IS_ERR(audcvspk_high)) {
  167. ret = PTR_ERR(audcvspk_high);
  168. dev_err(&pdev->dev, "Cannot find pinctrl audcvspk_high!\n");
  169. return;
  170. }
  171. audcvspk_low = pinctrl_lookup_state(pinctrlaud, "rcvspk-pulllow");
  172. if (IS_ERR(audcvspk_low)) {
  173. ret = PTR_ERR(audcvspk_low);
  174. dev_err(&pdev->dev, "Cannot find pinctrl audcvspk_low!\n");
  175. return;
  176. }
  177. #endif
  178. }
  179. int AudDrv_GPIO_PMIC_Select(int bEnable)
  180. {
  181. int retval = 0;
  182. if (bEnable == 1) {
  183. if (aud_gpios[GPIO_PMIC_MODE1].gpio_prepare) {
  184. retval =
  185. pinctrl_select_state(pinctrlaud, aud_gpios[GPIO_PMIC_MODE1].gpioctrl);
  186. if (retval)
  187. pr_err("could not set aud_gpios[GPIO_PMIC_MODE1] pins\n");
  188. }
  189. } else {
  190. if (aud_gpios[GPIO_PMIC_MODE0].gpio_prepare) {
  191. retval =
  192. pinctrl_select_state(pinctrlaud, aud_gpios[GPIO_PMIC_MODE0].gpioctrl);
  193. if (retval)
  194. pr_err("could not set aud_gpios[GPIO_PMIC_MODE0] pins\n");
  195. }
  196. }
  197. return retval;
  198. }
  199. int AudDrv_GPIO_I2S_Select(int bEnable)
  200. {
  201. int retval = 0;
  202. if (bEnable == 1) {
  203. if (aud_gpios[GPIO_I2S_MODE1].gpio_prepare) {
  204. retval =
  205. pinctrl_select_state(pinctrlaud, aud_gpios[GPIO_I2S_MODE1].gpioctrl);
  206. if (retval)
  207. pr_err("could not set aud_gpios[GPIO_I2S_MODE1] pins\n");
  208. }
  209. } else {
  210. if (aud_gpios[GPIO_I2S_MODE0].gpio_prepare) {
  211. retval =
  212. pinctrl_select_state(pinctrlaud, aud_gpios[GPIO_I2S_MODE0].gpioctrl);
  213. if (retval)
  214. pr_err("could not set aud_gpios[GPIO_I2S_MODE0] pins\n");
  215. }
  216. }
  217. return retval;
  218. }
  219. int AudDrv_GPIO_EXTAMP_Select(int bEnable)
  220. {
  221. int retval = 0;
  222. if (bEnable == 1) {
  223. if (aud_gpios[GPIO_EXTAMP_HIGH].gpio_prepare) {
  224. retval =
  225. pinctrl_select_state(pinctrlaud, aud_gpios[GPIO_EXTAMP_HIGH].gpioctrl);
  226. if (retval)
  227. pr_err("could not set aud_gpios[GPIO_EXTAMP_HIGH] pins\n");
  228. }
  229. } else {
  230. if (aud_gpios[GPIO_EXTAMP_LOW].gpio_prepare) {
  231. retval =
  232. pinctrl_select_state(pinctrlaud, aud_gpios[GPIO_EXTAMP_LOW].gpioctrl);
  233. if (retval)
  234. pr_err("could not set aud_gpios[GPIO_EXTAMP_LOW] pins\n");
  235. }
  236. }
  237. return retval;
  238. }
  239. int AudDrv_GPIO_EXTAMP2_Select(int bEnable)
  240. {
  241. int retval = 0;
  242. if (bEnable == 1) {
  243. if (aud_gpios[GPIO_EXTAMP2_HIGH].gpio_prepare) {
  244. retval =
  245. pinctrl_select_state(pinctrlaud, aud_gpios[GPIO_EXTAMP2_HIGH].gpioctrl);
  246. if (retval)
  247. pr_err("could not set aud_gpios[GPIO_EXTAMP2_HIGH] pins\n");
  248. }
  249. } else {
  250. if (aud_gpios[GPIO_EXTAMP2_LOW].gpio_prepare) {
  251. retval =
  252. pinctrl_select_state(pinctrlaud, aud_gpios[GPIO_EXTAMP2_LOW].gpioctrl);
  253. if (retval)
  254. pr_err("could not set aud_gpios[GPIO_EXTAMP2_LOW] pins\n");
  255. }
  256. }
  257. return retval;
  258. }
  259. int AudDrv_GPIO_RCVSPK_Select(int bEnable)
  260. {
  261. int retval = 0;
  262. if (bEnable == 1) {
  263. if (aud_gpios[GPIO_RCVSPK_HIGH].gpio_prepare) {
  264. retval =
  265. pinctrl_select_state(pinctrlaud, aud_gpios[GPIO_RCVSPK_HIGH].gpioctrl);
  266. if (retval)
  267. pr_err("could not set aud_gpios[GPIO_RCVSPK_HIGH] pins\n");
  268. }
  269. } else {
  270. if (aud_gpios[GPIO_RCVSPK_LOW].gpio_prepare) {
  271. retval =
  272. pinctrl_select_state(pinctrlaud, aud_gpios[GPIO_RCVSPK_LOW].gpioctrl);
  273. if (retval)
  274. pr_err("could not set aud_gpios[GPIO_RCVSPK_LOW] pins\n");
  275. }
  276. }
  277. return retval;
  278. }
  279. #endif