setup-camif.c 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /*
  2. * Copyright (C) 2012 Sylwester Nawrocki <sylvester.nawrocki@gmail.com>
  3. *
  4. * Helper functions for S3C24XX/S3C64XX SoC series CAMIF driver
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License version 2 as
  8. * published by the Free Software Foundation.
  9. */
  10. #include <linux/gpio.h>
  11. #include <plat/gpio-cfg.h>
  12. /* Number of camera port pins, without FIELD */
  13. #define S3C_CAMIF_NUM_GPIOS 13
  14. /* Default camera port configuration helpers. */
  15. static void camif_get_gpios(int *gpio_start, int *gpio_reset)
  16. {
  17. #ifdef CONFIG_ARCH_S3C24XX
  18. *gpio_start = S3C2410_GPJ(0);
  19. *gpio_reset = S3C2410_GPJ(12);
  20. #else
  21. /* s3c64xx */
  22. *gpio_start = S3C64XX_GPF(0);
  23. *gpio_reset = S3C64XX_GPF(3);
  24. #endif
  25. }
  26. int s3c_camif_gpio_get(void)
  27. {
  28. int gpio_start, gpio_reset;
  29. int ret, i;
  30. camif_get_gpios(&gpio_start, &gpio_reset);
  31. for (i = 0; i < S3C_CAMIF_NUM_GPIOS; i++) {
  32. int gpio = gpio_start + i;
  33. if (gpio == gpio_reset)
  34. continue;
  35. ret = gpio_request(gpio, "camif");
  36. if (!ret)
  37. ret = s3c_gpio_cfgpin(gpio, S3C_GPIO_SFN(2));
  38. if (ret) {
  39. pr_err("failed to configure GPIO %d\n", gpio);
  40. for (--i; i >= 0; i--)
  41. gpio_free(gpio--);
  42. return ret;
  43. }
  44. s3c_gpio_setpull(gpio, S3C_GPIO_PULL_NONE);
  45. }
  46. return 0;
  47. }
  48. void s3c_camif_gpio_put(void)
  49. {
  50. int i, gpio_start, gpio_reset;
  51. camif_get_gpios(&gpio_start, &gpio_reset);
  52. for (i = 0; i < S3C_CAMIF_NUM_GPIOS; i++) {
  53. int gpio = gpio_start + i;
  54. if (gpio != gpio_reset)
  55. gpio_free(gpio);
  56. }
  57. }