AudDrv_Gpio.c 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  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. * MT6580 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. enum audio_system_gpio_type {
  54. GPIO_DEFAULT = 0,
  55. GPIO_PMIC_MODE0,
  56. GPIO_PMIC_MODE1,
  57. GPIO_I2S_MODE0,
  58. GPIO_I2S_MODE1,
  59. GPIO_EXTAMP_HIGH,
  60. GPIO_EXTAMP_LOW,
  61. GPIO_EXTAMP2_HIGH,
  62. GPIO_EXTAMP2_LOW,
  63. GPIO_RCVSPK_HIGH,
  64. GPIO_RCVSPK_LOW,
  65. GPIO_NUM
  66. };
  67. struct audio_gpio_attr {
  68. const char *name;
  69. bool gpio_prepare;
  70. struct pinctrl_state *gpioctrl;
  71. };
  72. static struct audio_gpio_attr aud_gpios[GPIO_NUM] = {
  73. [GPIO_DEFAULT] = {"default", false, NULL},
  74. [GPIO_PMIC_MODE0] = {"audpmicclk-mode0", false, NULL},
  75. [GPIO_PMIC_MODE1] = {"audpmicclk-mode1", false, NULL},
  76. [GPIO_I2S_MODE0] = {"audi2s1-mode0", false, NULL},
  77. [GPIO_I2S_MODE1] = {"audi2s1-mode1", false, NULL},
  78. [GPIO_EXTAMP_HIGH] = {"extamp-pullhigh", false, NULL},
  79. [GPIO_EXTAMP_LOW] = {"extamp-pulllow", false, NULL},
  80. [GPIO_EXTAMP2_HIGH] = {"extamp2-pullhigh", false, NULL},
  81. [GPIO_EXTAMP2_LOW] = {"extamp2-pulllow", false, NULL},
  82. [GPIO_RCVSPK_HIGH] = {"rcvspk-pullhigh", false, NULL},
  83. [GPIO_RCVSPK_LOW] = {"rcvspk-pulllow", false, NULL},
  84. };
  85. void AudDrv_GPIO_probe(void *dev)
  86. {
  87. int ret;
  88. int i = 0;
  89. pr_warn("%s\n", __func__);
  90. pinctrlaud = devm_pinctrl_get(dev);
  91. if (IS_ERR(pinctrlaud)) {
  92. ret = PTR_ERR(pinctrlaud);
  93. pr_err("Cannot find pinctrlaud!\n");
  94. return;
  95. }
  96. for (i = 0; i < ARRAY_SIZE(aud_gpios); i++) {
  97. aud_gpios[i].gpioctrl = pinctrl_lookup_state(pinctrlaud, aud_gpios[i].name);
  98. if (IS_ERR(aud_gpios[i].gpioctrl)) {
  99. ret = PTR_ERR(aud_gpios[i].gpioctrl);
  100. pr_err("%s pinctrl_lookup_state %s fail %d\n", __func__, aud_gpios[i].name,
  101. ret);
  102. } else {
  103. aud_gpios[i].gpio_prepare = true;
  104. }
  105. }
  106. #if 0
  107. pins_default = pinctrl_lookup_state(pinctrlaud, "default");
  108. if (IS_ERR(pins_default)) {
  109. ret = PTR_ERR(pins_default);
  110. dev_err(&pdev->dev, "Cannot find aud pinctrl default!\n");
  111. return;
  112. }
  113. audpmic_mode0 = pinctrl_lookup_state(pinctrlaud, "audpmicclk-mode0");
  114. if (IS_ERR(audpmic_mode0)) {
  115. ret = PTR_ERR(audpmic_mode0);
  116. dev_err(&pdev->dev, "Cannot find pinctrl audpmic_mode0!\n");
  117. return;
  118. }
  119. audpmic_mode1 = pinctrl_lookup_state(pinctrlaud, "audpmicclk-mode1");
  120. if (IS_ERR(audpmic_mode1)) {
  121. ret = PTR_ERR(audpmic_mode1);
  122. dev_err(&pdev->dev, "Cannot find pinctrl audpmic_mode1!\n");
  123. return;
  124. }
  125. audi2s1_mode0 = pinctrl_lookup_state(pinctrlaud, "audi2s1-mode0");
  126. if (IS_ERR(audi2s1_mode0)) {
  127. ret = PTR_ERR(audi2s1_mode0);
  128. dev_err(&pdev->dev, "Cannot find pinctrl audi2s1_mode0!\n");
  129. return;
  130. }
  131. audi2s1_mode1 = pinctrl_lookup_state(pinctrlaud, "audi2s1-mode1");
  132. if (IS_ERR(audi2s1_mode1)) {
  133. ret = PTR_ERR(audi2s1_mode1);
  134. dev_err(&pdev->dev, "Cannot find pinctrl audi2s1_mode1!\n");
  135. return;
  136. }
  137. audextamp_high = pinctrl_lookup_state(pinctrlaud, "extamp-pullhigh");
  138. if (IS_ERR(audextamp_high)) {
  139. ret = PTR_ERR(audextamp_high);
  140. dev_err(&pdev->dev, "Cannot find pinctrl audextamp_high!\n");
  141. return;
  142. }
  143. audextamp_low = pinctrl_lookup_state(pinctrlaud, "extamp-pulllow");
  144. if (IS_ERR(audextamp_low)) {
  145. ret = PTR_ERR(audextamp_low);
  146. dev_err(&pdev->dev, "Cannot find pinctrl audextamp_low!\n");
  147. return;
  148. }
  149. audextamp2_high = pinctrl_lookup_state(pinctrlaud, "extamp2-pullhigh");
  150. if (IS_ERR(audextamp2_high)) {
  151. ret = PTR_ERR(audextamp2_high);
  152. dev_err(&pdev->dev, "Cannot find pinctrl audextamp2_high!\n");
  153. return;
  154. }
  155. audextamp2_low = pinctrl_lookup_state(pinctrlaud, "extamp2-pulllow");
  156. if (IS_ERR(audextamp2_low)) {
  157. ret = PTR_ERR(audextamp2_low);
  158. dev_err(&pdev->dev, "Cannot find pinctrl audextamp2_low!\n");
  159. return;
  160. }
  161. audcvspk_high = pinctrl_lookup_state(pinctrlaud, "rcvspk-pullhigh");
  162. if (IS_ERR(audcvspk_high)) {
  163. ret = PTR_ERR(audcvspk_high);
  164. dev_err(&pdev->dev, "Cannot find pinctrl audcvspk_high!\n");
  165. return;
  166. }
  167. audcvspk_low = pinctrl_lookup_state(pinctrlaud, "rcvspk-pulllow");
  168. if (IS_ERR(audcvspk_low)) {
  169. ret = PTR_ERR(audcvspk_low);
  170. dev_err(&pdev->dev, "Cannot find pinctrl audcvspk_low!\n");
  171. return;
  172. }
  173. #endif
  174. }
  175. int AudDrv_GPIO_PMIC_Select(int bEnable)
  176. {
  177. int retval = 0;
  178. if (bEnable == 1) {
  179. if (aud_gpios[GPIO_PMIC_MODE1].gpio_prepare) {
  180. retval =
  181. pinctrl_select_state(pinctrlaud, aud_gpios[GPIO_PMIC_MODE1].gpioctrl);
  182. if (retval)
  183. pr_err("could not set aud_gpios[GPIO_PMIC_MODE1] pins\n");
  184. }
  185. } else {
  186. if (aud_gpios[GPIO_PMIC_MODE0].gpio_prepare) {
  187. retval =
  188. pinctrl_select_state(pinctrlaud, aud_gpios[GPIO_PMIC_MODE0].gpioctrl);
  189. if (retval)
  190. pr_err("could not set aud_gpios[GPIO_PMIC_MODE0] pins\n");
  191. }
  192. }
  193. return retval;
  194. }
  195. int AudDrv_GPIO_I2S_Select(int bEnable)
  196. {
  197. int retval = 0;
  198. if (bEnable == 1) {
  199. if (aud_gpios[GPIO_I2S_MODE1].gpio_prepare) {
  200. retval =
  201. pinctrl_select_state(pinctrlaud, aud_gpios[GPIO_I2S_MODE1].gpioctrl);
  202. if (retval)
  203. pr_err("could not set aud_gpios[GPIO_I2S_MODE1] pins\n");
  204. }
  205. } else {
  206. if (aud_gpios[GPIO_I2S_MODE0].gpio_prepare) {
  207. retval =
  208. pinctrl_select_state(pinctrlaud, aud_gpios[GPIO_I2S_MODE0].gpioctrl);
  209. if (retval)
  210. pr_err("could not set aud_gpios[GPIO_I2S_MODE0] pins\n");
  211. }
  212. }
  213. return retval;
  214. }
  215. int AudDrv_GPIO_EXTAMP_Select(int bEnable)
  216. {
  217. int retval = 0;
  218. if (bEnable == 1) {
  219. if (aud_gpios[GPIO_EXTAMP_HIGH].gpio_prepare) {
  220. retval =
  221. pinctrl_select_state(pinctrlaud, aud_gpios[GPIO_EXTAMP_HIGH].gpioctrl);
  222. if (retval)
  223. pr_err("could not set aud_gpios[GPIO_EXTAMP_HIGH] pins\n");
  224. }
  225. } else {
  226. if (aud_gpios[GPIO_EXTAMP_LOW].gpio_prepare) {
  227. retval =
  228. pinctrl_select_state(pinctrlaud, aud_gpios[GPIO_EXTAMP_LOW].gpioctrl);
  229. if (retval)
  230. pr_err("could not set aud_gpios[GPIO_EXTAMP_LOW] pins\n");
  231. }
  232. }
  233. return retval;
  234. }
  235. int AudDrv_GPIO_EXTAMP2_Select(int bEnable)
  236. {
  237. int retval = 0;
  238. if (bEnable == 1) {
  239. if (aud_gpios[GPIO_EXTAMP2_HIGH].gpio_prepare) {
  240. retval =
  241. pinctrl_select_state(pinctrlaud, aud_gpios[GPIO_EXTAMP2_HIGH].gpioctrl);
  242. if (retval)
  243. pr_err("could not set aud_gpios[GPIO_EXTAMP2_HIGH] pins\n");
  244. }
  245. } else {
  246. if (aud_gpios[GPIO_EXTAMP2_LOW].gpio_prepare) {
  247. retval =
  248. pinctrl_select_state(pinctrlaud, aud_gpios[GPIO_EXTAMP2_LOW].gpioctrl);
  249. if (retval)
  250. pr_err("could not set aud_gpios[GPIO_EXTAMP2_LOW] pins\n");
  251. }
  252. }
  253. return retval;
  254. }
  255. int AudDrv_GPIO_RCVSPK_Select(int bEnable)
  256. {
  257. int retval = 0;
  258. if (bEnable == 1) {
  259. if (aud_gpios[GPIO_RCVSPK_HIGH].gpio_prepare) {
  260. retval =
  261. pinctrl_select_state(pinctrlaud, aud_gpios[GPIO_RCVSPK_HIGH].gpioctrl);
  262. if (retval)
  263. pr_err("could not set aud_gpios[GPIO_RCVSPK_HIGH] pins\n");
  264. }
  265. } else {
  266. if (aud_gpios[GPIO_RCVSPK_LOW].gpio_prepare) {
  267. retval =
  268. pinctrl_select_state(pinctrlaud, aud_gpios[GPIO_RCVSPK_LOW].gpioctrl);
  269. if (retval)
  270. pr_err("could not set aud_gpios[GPIO_RCVSPK_LOW] pins\n");
  271. }
  272. }
  273. return retval;
  274. }
  275. #endif