Merge tag 'u-boot-imx-20190129' of git://git.denx.de/u-boot-imx
[oweals/u-boot.git] / arch / arm / mach-snapdragon / pinctrl-apq8096.c
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * Qualcomm APQ8096 pinctrl
4  *
5  * (C) Copyright 2019 Ramon Fried <ramon.fried@gmail.com>
6  *
7  */
8
9 #include "pinctrl-snapdragon.h"
10 #include <common.h>
11
12 #define MAX_PIN_NAME_LEN 32
13 static char pin_name[MAX_PIN_NAME_LEN];
14 static const char * const msm_pinctrl_pins[] = {
15         "SDC1_CLK",
16         "SDC1_CMD",
17         "SDC1_DATA",
18         "SDC2_CLK",
19         "SDC2_CMD",
20         "SDC2_DATA",
21         "SDC1_RCLK",
22 };
23
24 static const struct pinctrl_function msm_pinctrl_functions[] = {
25         {"blsp_uart8", 2},
26 };
27
28 static const char *apq8096_get_function_name(struct udevice *dev,
29                                              unsigned int selector)
30 {
31         return msm_pinctrl_functions[selector].name;
32 }
33
34 static const char *apq8096_get_pin_name(struct udevice *dev,
35                                         unsigned int selector)
36 {
37         if (selector < 150) {
38                 snprintf(pin_name, MAX_PIN_NAME_LEN, "GPIO_%u", selector);
39                 return pin_name;
40         } else {
41                 return msm_pinctrl_pins[selector - 150];
42         }
43 }
44
45 static unsigned int apq8096_get_function_mux(unsigned int selector)
46 {
47         return msm_pinctrl_functions[selector].val;
48 }
49
50 struct msm_pinctrl_data apq8096_data = {
51         .pin_count = 157,
52         .functions_count = ARRAY_SIZE(msm_pinctrl_functions),
53         .get_function_name = apq8096_get_function_name,
54         .get_function_mux = apq8096_get_function_mux,
55         .get_pin_name = apq8096_get_pin_name,
56 };