AudDrv_Gpio.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384
  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_HPDEPOP_HIGH,
  70. GPIO_HPDEPOP_LOW,
  71. GPIO_NUM
  72. };
  73. struct audio_gpio_attr {
  74. const char *name;
  75. bool gpio_prepare;
  76. struct pinctrl_state *gpioctrl;
  77. };
  78. static struct audio_gpio_attr aud_gpios[GPIO_NUM] = {
  79. [GPIO_DEFAULT] = {"default", false, NULL},
  80. [GPIO_PMIC_MODE0] = {"audpmicclk-mode0", false, NULL},
  81. [GPIO_PMIC_MODE1] = {"audpmicclk-mode1", false, NULL},
  82. [GPIO_I2S_MODE0] = {"audi2s1-mode0", false, NULL},
  83. [GPIO_I2S_MODE1] = {"audi2s1-mode1", false, NULL},
  84. [GPIO_EXTAMP_HIGH] = {"extamp-pullhigh", false, NULL},
  85. [GPIO_EXTAMP_LOW] = {"extamp-pulllow", false, NULL},
  86. [GPIO_EXTAMP2_HIGH] = {"extamp2-pullhigh", false, NULL},
  87. [GPIO_EXTAMP2_LOW] = {"extamp2-pulllow", false, NULL},
  88. [GPIO_RCVSPK_HIGH] = {"rcvspk-pullhigh", false, NULL},
  89. [GPIO_RCVSPK_LOW] = {"rcvspk-pulllow", false, NULL},
  90. [GPIO_HPDEPOP_HIGH] = {"hpdepop-pullhigh", false, NULL},
  91. [GPIO_HPDEPOP_LOW] = {"hpdepop-pulllow", false, NULL},
  92. };
  93. void AudDrv_GPIO_probe(void *dev)
  94. {
  95. int ret;
  96. int i = 0;
  97. pr_warn("%s\n", __func__);
  98. pinctrlaud = devm_pinctrl_get(dev);
  99. if (IS_ERR(pinctrlaud)) {
  100. ret = PTR_ERR(pinctrlaud);
  101. pr_err("Cannot find pinctrlaud!\n");
  102. return;
  103. }
  104. for (i = 0; i < ARRAY_SIZE(aud_gpios); i++) {
  105. aud_gpios[i].gpioctrl = pinctrl_lookup_state(pinctrlaud, aud_gpios[i].name);
  106. if (IS_ERR(aud_gpios[i].gpioctrl)) {
  107. ret = PTR_ERR(aud_gpios[i].gpioctrl);
  108. pr_err("%s pinctrl_lookup_state %s fail %d\n", __func__, aud_gpios[i].name,
  109. ret);
  110. } else {
  111. aud_gpios[i].gpio_prepare = true;
  112. }
  113. }
  114. #if 0
  115. pins_default = pinctrl_lookup_state(pinctrlaud, "default");
  116. if (IS_ERR(pins_default)) {
  117. ret = PTR_ERR(pins_default);
  118. dev_err(&pdev->dev, "Cannot find aud pinctrl default!\n");
  119. return;
  120. }
  121. audpmic_mode0 = pinctrl_lookup_state(pinctrlaud, "audpmicclk-mode0");
  122. if (IS_ERR(audpmic_mode0)) {
  123. ret = PTR_ERR(audpmic_mode0);
  124. dev_err(&pdev->dev, "Cannot find pinctrl audpmic_mode0!\n");
  125. return;
  126. }
  127. audpmic_mode1 = pinctrl_lookup_state(pinctrlaud, "audpmicclk-mode1");
  128. if (IS_ERR(audpmic_mode1)) {
  129. ret = PTR_ERR(audpmic_mode1);
  130. dev_err(&pdev->dev, "Cannot find pinctrl audpmic_mode1!\n");
  131. return;
  132. }
  133. audi2s1_mode0 = pinctrl_lookup_state(pinctrlaud, "audi2s1-mode0");
  134. if (IS_ERR(audi2s1_mode0)) {
  135. ret = PTR_ERR(audi2s1_mode0);
  136. dev_err(&pdev->dev, "Cannot find pinctrl audi2s1_mode0!\n");
  137. return;
  138. }
  139. audi2s1_mode1 = pinctrl_lookup_state(pinctrlaud, "audi2s1-mode1");
  140. if (IS_ERR(audi2s1_mode1)) {
  141. ret = PTR_ERR(audi2s1_mode1);
  142. dev_err(&pdev->dev, "Cannot find pinctrl audi2s1_mode1!\n");
  143. return;
  144. }
  145. audextamp_high = pinctrl_lookup_state(pinctrlaud, "extamp-pullhigh");
  146. if (IS_ERR(audextamp_high)) {
  147. ret = PTR_ERR(audextamp_high);
  148. dev_err(&pdev->dev, "Cannot find pinctrl audextamp_high!\n");
  149. return;
  150. }
  151. audextamp_low = pinctrl_lookup_state(pinctrlaud, "extamp-pulllow");
  152. if (IS_ERR(audextamp_low)) {
  153. ret = PTR_ERR(audextamp_low);
  154. dev_err(&pdev->dev, "Cannot find pinctrl audextamp_low!\n");
  155. return;
  156. }
  157. audextamp2_high = pinctrl_lookup_state(pinctrlaud, "extamp2-pullhigh");
  158. if (IS_ERR(audextamp2_high)) {
  159. ret = PTR_ERR(audextamp2_high);
  160. dev_err(&pdev->dev, "Cannot find pinctrl audextamp2_high!\n");
  161. return;
  162. }
  163. audextamp2_low = pinctrl_lookup_state(pinctrlaud, "extamp2-pulllow");
  164. if (IS_ERR(audextamp2_low)) {
  165. ret = PTR_ERR(audextamp2_low);
  166. dev_err(&pdev->dev, "Cannot find pinctrl audextamp2_low!\n");
  167. return;
  168. }
  169. audcvspk_high = pinctrl_lookup_state(pinctrlaud, "rcvspk-pullhigh");
  170. if (IS_ERR(audcvspk_high)) {
  171. ret = PTR_ERR(audcvspk_high);
  172. dev_err(&pdev->dev, "Cannot find pinctrl audcvspk_high!\n");
  173. return;
  174. }
  175. audcvspk_low = pinctrl_lookup_state(pinctrlaud, "rcvspk-pulllow");
  176. if (IS_ERR(audcvspk_low)) {
  177. ret = PTR_ERR(audcvspk_low);
  178. dev_err(&pdev->dev, "Cannot find pinctrl audcvspk_low!\n");
  179. return;
  180. }
  181. #endif
  182. }
  183. int AudDrv_GPIO_PMIC_Select(int bEnable)
  184. {
  185. int retval = 0;
  186. if (bEnable == 1) {
  187. if (aud_gpios[GPIO_PMIC_MODE1].gpio_prepare) {
  188. retval =
  189. pinctrl_select_state(pinctrlaud, aud_gpios[GPIO_PMIC_MODE1].gpioctrl);
  190. if (retval)
  191. pr_err("could not set aud_gpios[GPIO_PMIC_MODE1] pins\n");
  192. }
  193. } else {
  194. if (aud_gpios[GPIO_PMIC_MODE0].gpio_prepare) {
  195. retval =
  196. pinctrl_select_state(pinctrlaud, aud_gpios[GPIO_PMIC_MODE0].gpioctrl);
  197. if (retval)
  198. pr_err("could not set aud_gpios[GPIO_PMIC_MODE0] pins\n");
  199. }
  200. }
  201. return retval;
  202. }
  203. int AudDrv_GPIO_I2S_Select(int bEnable)
  204. {
  205. int retval = 0;
  206. if (bEnable == 1) {
  207. if (aud_gpios[GPIO_I2S_MODE1].gpio_prepare) {
  208. retval =
  209. pinctrl_select_state(pinctrlaud, aud_gpios[GPIO_I2S_MODE1].gpioctrl);
  210. if (retval)
  211. pr_err("could not set aud_gpios[GPIO_I2S_MODE1] pins\n");
  212. }
  213. } else {
  214. if (aud_gpios[GPIO_I2S_MODE0].gpio_prepare) {
  215. retval =
  216. pinctrl_select_state(pinctrlaud, aud_gpios[GPIO_I2S_MODE0].gpioctrl);
  217. if (retval)
  218. pr_err("could not set aud_gpios[GPIO_I2S_MODE0] pins\n");
  219. }
  220. }
  221. return retval;
  222. }
  223. int AudDrv_GPIO_EXTAMP_Select(int bEnable, int mode)
  224. {
  225. int retval = 0;
  226. int extamp_mode;
  227. int i;
  228. if (bEnable == 1) {
  229. if (mode == 1)
  230. extamp_mode = 1;
  231. else if (mode == 2)
  232. extamp_mode = 2;
  233. else
  234. extamp_mode = 3; /* default mode is 3 */
  235. if (aud_gpios[GPIO_EXTAMP_HIGH].gpio_prepare) {
  236. for (i = 0; i < extamp_mode; i++) {
  237. retval = pinctrl_select_state(pinctrlaud,
  238. aud_gpios[GPIO_EXTAMP_LOW].gpioctrl);
  239. if (retval)
  240. pr_err("could not set aud_gpios[GPIO_EXTAMP_LOW] pins\n");
  241. udelay(2);
  242. retval = pinctrl_select_state(pinctrlaud,
  243. aud_gpios[GPIO_EXTAMP_HIGH].gpioctrl);
  244. if (retval)
  245. pr_err("could not set aud_gpios[GPIO_EXTAMP_HIGH] pins\n");
  246. udelay(2);
  247. }
  248. }
  249. } else {
  250. if (aud_gpios[GPIO_EXTAMP_LOW].gpio_prepare) {
  251. retval =
  252. pinctrl_select_state(pinctrlaud, aud_gpios[GPIO_EXTAMP_LOW].gpioctrl);
  253. if (retval)
  254. pr_err("could not set aud_gpios[GPIO_EXTAMP_LOW] pins\n");
  255. }
  256. }
  257. return retval;
  258. }
  259. int AudDrv_GPIO_EXTAMP2_Select(int bEnable, int mode)
  260. {
  261. int retval = 0;
  262. int extamp_mode;
  263. int i;
  264. if (bEnable == 1) {
  265. if (mode == 1)
  266. extamp_mode = 1;
  267. else if (mode == 2)
  268. extamp_mode = 2;
  269. else
  270. extamp_mode = 3; /* default mode is 3 */
  271. if (aud_gpios[GPIO_EXTAMP2_HIGH].gpio_prepare) {
  272. for (i = 0; i < extamp_mode; i++) {
  273. retval = pinctrl_select_state(pinctrlaud,
  274. aud_gpios[GPIO_EXTAMP2_LOW].gpioctrl);
  275. if (retval)
  276. pr_err("could not set aud_gpios[GPIO_EXTAMP2_LOW] pins\n");
  277. udelay(2);
  278. retval = pinctrl_select_state(pinctrlaud,
  279. aud_gpios[GPIO_EXTAMP2_HIGH].gpioctrl);
  280. if (retval)
  281. pr_err("could not set aud_gpios[GPIO_EXTAMP2_HIGH] pins\n");
  282. udelay(2);
  283. }
  284. }
  285. } else {
  286. if (aud_gpios[GPIO_EXTAMP2_LOW].gpio_prepare) {
  287. retval =
  288. pinctrl_select_state(pinctrlaud, aud_gpios[GPIO_EXTAMP2_LOW].gpioctrl);
  289. if (retval)
  290. pr_err("could not set aud_gpios[GPIO_EXTAMP2_LOW] pins\n");
  291. }
  292. }
  293. return retval;
  294. }
  295. int AudDrv_GPIO_RCVSPK_Select(int bEnable)
  296. {
  297. int retval = 0;
  298. if (bEnable == 1) {
  299. if (aud_gpios[GPIO_RCVSPK_HIGH].gpio_prepare) {
  300. retval =
  301. pinctrl_select_state(pinctrlaud, aud_gpios[GPIO_RCVSPK_HIGH].gpioctrl);
  302. if (retval)
  303. pr_err("could not set aud_gpios[GPIO_RCVSPK_HIGH] pins\n");
  304. }
  305. } else {
  306. if (aud_gpios[GPIO_RCVSPK_LOW].gpio_prepare) {
  307. retval =
  308. pinctrl_select_state(pinctrlaud, aud_gpios[GPIO_RCVSPK_LOW].gpioctrl);
  309. if (retval)
  310. pr_err("could not set aud_gpios[GPIO_RCVSPK_LOW] pins\n");
  311. }
  312. }
  313. return retval;
  314. }
  315. int AudDrv_GPIO_HPDEPOP_Select(int bEnable)
  316. {
  317. int retval = 0;
  318. if (bEnable == 1) {
  319. if (aud_gpios[GPIO_HPDEPOP_LOW].gpio_prepare) {
  320. retval =
  321. pinctrl_select_state(pinctrlaud, aud_gpios[GPIO_HPDEPOP_LOW].gpioctrl);
  322. if (retval)
  323. pr_err("could not set aud_gpios[GPIO_HPDEPOP_LOW] pins\n");
  324. }
  325. } else {
  326. if (aud_gpios[GPIO_HPDEPOP_HIGH].gpio_prepare) {
  327. retval =
  328. pinctrl_select_state(pinctrlaud, aud_gpios[GPIO_HPDEPOP_HIGH].gpioctrl);
  329. if (retval)
  330. pr_err("could not set aud_gpios[GPIO_HPDEPOP_HIGH] pins\n");
  331. }
  332. }
  333. return retval;
  334. }
  335. #endif