]>
Commit | Line | Data |
---|---|---|
83d290c5 | 1 | // SPDX-License-Identifier: GPL-2.0+ |
0c442298 AB |
2 | /* |
3 | * (C) Copyright 2011 | |
4 | * eInfochips Ltd. <www.einfochips.com> | |
c7c47ca2 | 5 | * Written-by: Ajay Bhargav <contact@8051projects.net> |
0c442298 AB |
6 | * |
7 | * (C) Copyright 2010 | |
8 | * Marvell Semiconductor <www.marvell.com> | |
0c442298 AB |
9 | */ |
10 | ||
11 | #include <common.h> | |
12 | #include <asm/io.h> | |
1221ce45 | 13 | #include <linux/errno.h> |
0c442298 AB |
14 | #include "mvgpio.h" |
15 | #include <asm/gpio.h> | |
16 | ||
17 | #ifndef MV_MAX_GPIO | |
18 | #define MV_MAX_GPIO 128 | |
19 | #endif | |
20 | ||
365d6070 | 21 | int gpio_request(unsigned gpio, const char *label) |
0c442298 | 22 | { |
365d6070 JH |
23 | if (gpio >= MV_MAX_GPIO) { |
24 | printf("%s: Invalid GPIO requested %d\n", __func__, gpio); | |
25 | return -1; | |
0c442298 AB |
26 | } |
27 | return 0; | |
28 | } | |
29 | ||
365d6070 | 30 | int gpio_free(unsigned gpio) |
0c442298 | 31 | { |
365d6070 | 32 | return 0; |
0c442298 AB |
33 | } |
34 | ||
365d6070 | 35 | int gpio_direction_input(unsigned gpio) |
0c442298 AB |
36 | { |
37 | struct gpio_reg *gpio_reg_bank; | |
38 | ||
365d6070 JH |
39 | if (gpio >= MV_MAX_GPIO) { |
40 | printf("%s: Invalid GPIO %d\n", __func__, gpio); | |
41 | return -1; | |
0c442298 AB |
42 | } |
43 | ||
365d6070 JH |
44 | gpio_reg_bank = get_gpio_base(GPIO_TO_REG(gpio)); |
45 | writel(GPIO_TO_BIT(gpio), &gpio_reg_bank->gcdr); | |
0c442298 AB |
46 | return 0; |
47 | } | |
48 | ||
365d6070 | 49 | int gpio_direction_output(unsigned gpio, int value) |
0c442298 AB |
50 | { |
51 | struct gpio_reg *gpio_reg_bank; | |
52 | ||
365d6070 JH |
53 | if (gpio >= MV_MAX_GPIO) { |
54 | printf("%s: Invalid GPIO %d\n", __func__, gpio); | |
55 | return -1; | |
0c442298 AB |
56 | } |
57 | ||
365d6070 JH |
58 | gpio_reg_bank = get_gpio_base(GPIO_TO_REG(gpio)); |
59 | writel(GPIO_TO_BIT(gpio), &gpio_reg_bank->gsdr); | |
60 | gpio_set_value(gpio, value); | |
0c442298 AB |
61 | return 0; |
62 | } | |
63 | ||
365d6070 | 64 | int gpio_get_value(unsigned gpio) |
0c442298 AB |
65 | { |
66 | struct gpio_reg *gpio_reg_bank; | |
365d6070 | 67 | u32 gpio_val; |
0c442298 | 68 | |
365d6070 JH |
69 | if (gpio >= MV_MAX_GPIO) { |
70 | printf("%s: Invalid GPIO %d\n", __func__, gpio); | |
71 | return -1; | |
0c442298 AB |
72 | } |
73 | ||
365d6070 JH |
74 | gpio_reg_bank = get_gpio_base(GPIO_TO_REG(gpio)); |
75 | gpio_val = readl(&gpio_reg_bank->gplr); | |
0c442298 | 76 | |
365d6070 | 77 | return GPIO_VAL(gpio, gpio_val); |
0c442298 AB |
78 | } |
79 | ||
365d6070 | 80 | int gpio_set_value(unsigned gpio, int value) |
0c442298 AB |
81 | { |
82 | struct gpio_reg *gpio_reg_bank; | |
83 | ||
365d6070 JH |
84 | if (gpio >= MV_MAX_GPIO) { |
85 | printf("%s: Invalid GPIO %d\n", __func__, gpio); | |
86 | return -1; | |
0c442298 AB |
87 | } |
88 | ||
365d6070 | 89 | gpio_reg_bank = get_gpio_base(GPIO_TO_REG(gpio)); |
0c442298 | 90 | if (value) |
365d6070 | 91 | writel(GPIO_TO_BIT(gpio), &gpio_reg_bank->gpsr); |
0c442298 | 92 | else |
365d6070 JH |
93 | writel(GPIO_TO_BIT(gpio), &gpio_reg_bank->gpcr); |
94 | ||
95 | return 0; | |
0c442298 | 96 | } |