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 <common.h>
10#include <dm.h>
11
12#include "pinctrl-qcom.h"
13
14#define MAX_PIN_NAME_LEN 32
15static char pin_name[MAX_PIN_NAME_LEN] __section(".data");
16static const char * const msm_pinctrl_pins[] = {
17	"sdc1_clk",
18	"sdc1_cmd",
19	"sdc1_data",
20	"sdc2_clk",
21	"sdc2_cmd",
22	"sdc2_data",
23	"sdc1_rclk",
24};
25
26static const struct pinctrl_function msm_pinctrl_functions[] = {
27	{"blsp_uart8", 2},
28};
29
30static const char *apq8096_get_function_name(struct udevice *dev,
31					     unsigned int selector)
32{
33	return msm_pinctrl_functions[selector].name;
34}
35
36static const char *apq8096_get_pin_name(struct udevice *dev,
37					unsigned int selector)
38{
39	if (selector < 150) {
40		snprintf(pin_name, MAX_PIN_NAME_LEN, "gpio%u", selector);
41		return pin_name;
42	} else {
43		return msm_pinctrl_pins[selector - 150];
44	}
45}
46
47static unsigned int apq8096_get_function_mux(__maybe_unused unsigned int pin,
48					     unsigned int selector)
49{
50	return msm_pinctrl_functions[selector].val;
51}
52
53static const struct msm_pinctrl_data apq8096_data = {
54	.pin_data = {
55		.pin_count = 157,
56		.special_pins_start = 150,
57	},
58	.functions_count = ARRAY_SIZE(msm_pinctrl_functions),
59	.get_function_name = apq8096_get_function_name,
60	.get_function_mux = apq8096_get_function_mux,
61	.get_pin_name = apq8096_get_pin_name,
62};
63
64static const struct udevice_id msm_pinctrl_ids[] = {
65	{ .compatible = "qcom,msm8996-pinctrl", .data = (ulong)&apq8096_data },
66	{ /* Sentinal */ }
67};
68
69U_BOOT_DRIVER(pinctrl_apq8096) = {
70	.name		= "pinctrl_apq8096",
71	.id		= UCLASS_NOP,
72	.of_match	= msm_pinctrl_ids,
73	.ops		= &msm_pinctrl_ops,
74	.bind		= msm_pinctrl_bind,
75};
76