disp_dts_gpio.c 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #include "disp_dts_gpio.h"
  2. #include <linux/bug.h>
  3. #include <linux/kernel.h> /* printk */
  4. static struct pinctrl *this_pctrl; /* static pinctrl instance */
  5. /* DTS state mapping name */
  6. static const char *this_state_name[DTS_GPIO_STATE_MAX] = {
  7. "mode_te_gpio", /* DTS_GPIO_STATE_TE_MODE_GPIO */
  8. "mode_te_te", /* DTS_GPIO_STATE_TE_MODE_TE */
  9. "pwm_test_pin_mux_gpio55", /* DTS_GPIO_STATE_PWM_TEST_PINMUX_55 */
  10. "pwm_test_pin_mux_gpio69", /* DTS_GPIO_STATE_PWM_TEST_PINMUX_69 */
  11. "pwm_test_pin_mux_gpio129" /* DTS_GPIO_STATE_PWM_TEST_PINMUX_129 */
  12. };
  13. /* pinctrl implementation */
  14. static long _set_state(const char *name)
  15. {
  16. long ret = 0;
  17. struct pinctrl_state *pState = 0;
  18. BUG_ON(!this_pctrl);
  19. pState = pinctrl_lookup_state(this_pctrl, name);
  20. if (IS_ERR(pState)) {
  21. pr_err("set state '%s' failed\n", name);
  22. ret = PTR_ERR(pState);
  23. goto exit;
  24. }
  25. /* select state! */
  26. pinctrl_select_state(this_pctrl, pState);
  27. exit:
  28. return ret; /* Good! */
  29. }
  30. long disp_dts_gpio_init(struct platform_device *pdev)
  31. {
  32. long ret = 0;
  33. struct pinctrl *pctrl;
  34. /* retrieve */
  35. pctrl = devm_pinctrl_get(&pdev->dev);
  36. if (IS_ERR(pctrl)) {
  37. dev_err(&pdev->dev, "Cannot find disp pinctrl!");
  38. ret = PTR_ERR(pctrl);
  39. goto exit;
  40. }
  41. this_pctrl = pctrl;
  42. exit:
  43. return ret;
  44. }
  45. long disp_dts_gpio_select_state(DTS_GPIO_STATE s)
  46. {
  47. BUG_ON(!((unsigned int)(s) < (unsigned int)(DTS_GPIO_STATE_MAX)));
  48. return _set_state(this_state_name[s]);
  49. }