blob: 72d8edb8927a417c97aa49d346f5d58804667be9 [file] [log] [blame]
Sylwester Nawrockie51d5482012-11-22 14:29:18 +09001/*
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
11#include <linux/gpio.h>
Sylwester Nawrockie51d5482012-11-22 14:29:18 +090012#include <plat/gpio-cfg.h>
Linus Walleijb0161ca2014-01-14 14:24:24 +010013#include <mach/gpio-samsung.h>
Sylwester Nawrockie51d5482012-11-22 14:29:18 +090014
15/* Number of camera port pins, without FIELD */
16#define S3C_CAMIF_NUM_GPIOS 13
17
18/* Default camera port configuration helpers. */
19
20static void camif_get_gpios(int *gpio_start, int *gpio_reset)
21{
22#ifdef CONFIG_ARCH_S3C24XX
23 *gpio_start = S3C2410_GPJ(0);
24 *gpio_reset = S3C2410_GPJ(12);
25#else
26 /* s3c64xx */
27 *gpio_start = S3C64XX_GPF(0);
28 *gpio_reset = S3C64XX_GPF(3);
29#endif
30}
31
32int s3c_camif_gpio_get(void)
33{
34 int gpio_start, gpio_reset;
35 int ret, i;
36
37 camif_get_gpios(&gpio_start, &gpio_reset);
38
39 for (i = 0; i < S3C_CAMIF_NUM_GPIOS; i++) {
40 int gpio = gpio_start + i;
41
42 if (gpio == gpio_reset)
43 continue;
44
45 ret = gpio_request(gpio, "camif");
46 if (!ret)
47 ret = s3c_gpio_cfgpin(gpio, S3C_GPIO_SFN(2));
48 if (ret) {
49 pr_err("failed to configure GPIO %d\n", gpio);
50 for (--i; i >= 0; i--)
51 gpio_free(gpio--);
52 return ret;
53 }
54 s3c_gpio_setpull(gpio, S3C_GPIO_PULL_NONE);
55 }
56
57 return 0;
58}
59
60void s3c_camif_gpio_put(void)
61{
62 int i, gpio_start, gpio_reset;
63
64 camif_get_gpios(&gpio_start, &gpio_reset);
65
66 for (i = 0; i < S3C_CAMIF_NUM_GPIOS; i++) {
67 int gpio = gpio_start + i;
68 if (gpio != gpio_reset)
69 gpio_free(gpio);
70 }
71}