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