setup-camif.c 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. #include <mach/gpio-samsung.h>
  13. /* Number of camera port pins, without FIELD */
  14. #define S3C_CAMIF_NUM_GPIOS 13
  15. /* Default camera port configuration helpers. */
  16. static void camif_get_gpios(int *gpio_start, int *gpio_reset)
  17. {
  18. #ifdef CONFIG_ARCH_S3C24XX
  19. *gpio_start = S3C2410_GPJ(0);
  20. *gpio_reset = S3C2410_GPJ(12);
  21. #else
  22. /* s3c64xx */
  23. *gpio_start = S3C64XX_GPF(0);
  24. *gpio_reset = S3C64XX_GPF(3);
  25. #endif
  26. }
  27. int s3c_camif_gpio_get(void)
  28. {
  29. int gpio_start, gpio_reset;
  30. int ret, i;
  31. camif_get_gpios(&gpio_start, &gpio_reset);
  32. for (i = 0; i < S3C_CAMIF_NUM_GPIOS; i++) {
  33. int gpio = gpio_start + i;
  34. if (gpio == gpio_reset)
  35. continue;
  36. ret = gpio_request(gpio, "camif");
  37. if (!ret)
  38. ret = s3c_gpio_cfgpin(gpio, S3C_GPIO_SFN(2));
  39. if (ret) {
  40. pr_err("failed to configure GPIO %d\n", gpio);
  41. for (--i; i >= 0; i--)
  42. gpio_free(gpio--);
  43. return ret;
  44. }
  45. s3c_gpio_setpull(gpio, S3C_GPIO_PULL_NONE);
  46. }
  47. return 0;
  48. }
  49. void s3c_camif_gpio_put(void)
  50. {
  51. int i, gpio_start, gpio_reset;
  52. camif_get_gpios(&gpio_start, &gpio_reset);
  53. for (i = 0; i < S3C_CAMIF_NUM_GPIOS; i++) {
  54. int gpio = gpio_start + i;
  55. if (gpio != gpio_reset)
  56. gpio_free(gpio);
  57. }
  58. }