pinctrl.c 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /*
  2. * Driver core interface to the pinctrl subsystem.
  3. *
  4. * Copyright (C) 2012 ST-Ericsson SA
  5. * Written on behalf of Linaro for ST-Ericsson
  6. * Based on bits of regulator core, gpio core and clk core
  7. *
  8. * Author: Linus Walleij <linus.walleij@linaro.org>
  9. *
  10. * License terms: GNU General Public License (GPL) version 2
  11. */
  12. #include <linux/device.h>
  13. #include <linux/pinctrl/devinfo.h>
  14. #include <linux/pinctrl/consumer.h>
  15. #include <linux/slab.h>
  16. /**
  17. * pinctrl_bind_pins() - called by the device core before probe
  18. * @dev: the device that is just about to probe
  19. */
  20. int pinctrl_bind_pins(struct device *dev)
  21. {
  22. int ret;
  23. dev->pins = devm_kzalloc(dev, sizeof(*(dev->pins)), GFP_KERNEL);
  24. if (!dev->pins)
  25. return -ENOMEM;
  26. dev->pins->p = devm_pinctrl_get(dev);
  27. if (IS_ERR(dev->pins->p)) {
  28. dev_dbg(dev, "no pinctrl handle\n");
  29. ret = PTR_ERR(dev->pins->p);
  30. goto cleanup_alloc;
  31. }
  32. dev->pins->default_state = pinctrl_lookup_state(dev->pins->p,
  33. PINCTRL_STATE_DEFAULT);
  34. if (IS_ERR(dev->pins->default_state)) {
  35. dev_dbg(dev, "no default pinctrl state\n");
  36. ret = 0;
  37. goto cleanup_get;
  38. }
  39. ret = pinctrl_select_state(dev->pins->p, dev->pins->default_state);
  40. if (ret) {
  41. dev_dbg(dev, "failed to activate default pinctrl state\n");
  42. goto cleanup_get;
  43. }
  44. return 0;
  45. /*
  46. * If no pinctrl handle or default state was found for this device,
  47. * let's explicitly free the pin container in the device, there is
  48. * no point in keeping it around.
  49. */
  50. cleanup_get:
  51. devm_pinctrl_put(dev->pins->p);
  52. cleanup_alloc:
  53. devm_kfree(dev, dev->pins);
  54. dev->pins = NULL;
  55. /* Only return deferrals */
  56. if (ret != -EPROBE_DEFER)
  57. ret = 0;
  58. return ret;
  59. }