aboutsummaryrefslogtreecommitdiff
path: root/sys/dev/qcom_tlmm/qcom_tlmm_var.h
blob: 1fea182753971405e790bf43882b4a5d492db2dd (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
/*-
 * SPDX-License-Identifier: BSD-2-Clause
 *
 * Copyright (c) 2021 Adrian Chadd <adrian@FreeBSD.org>.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice unmodified, this list of conditions, and the following
 *    disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 *
 */

#ifndef	__QCOM_TLMM_VAR_H__
#define	__QCOM_TLMM_VAR_H__

#define GPIO_LOCK(_sc)		mtx_lock(&(_sc)->gpio_mtx)
#define GPIO_UNLOCK(_sc)	mtx_unlock(&(_sc)->gpio_mtx)
#define GPIO_LOCK_ASSERT(_sc)	mtx_assert(&(_sc)->gpio_mtx, MA_OWNED)

/*
 * register space access macros
 */
#define GPIO_WRITE(sc, reg, val)	do {	\
		bus_write_4(sc->gpio_mem_res, (reg), (val)); \
	} while (0)

#define GPIO_READ(sc, reg)	 bus_read_4(sc->gpio_mem_res, (reg))

#define GPIO_SET_BITS(sc, reg, bits)	\
	GPIO_WRITE(sc, reg, GPIO_READ(sc, (reg)) | (bits))

#define GPIO_CLEAR_BITS(sc, reg, bits)	\
	GPIO_WRITE(sc, reg, GPIO_READ(sc, (reg)) & ~(bits))


enum prop_id {
	PIN_ID_BIAS_DISABLE = 0,
	PIN_ID_BIAS_HIGH_IMPEDANCE,
	PIN_ID_BIAS_BUS_HOLD,
	PIN_ID_BIAS_PULL_UP,
	PIN_ID_BIAS_PULL_DOWN,
	PIN_ID_BIAS_PULL_PIN_DEFAULT,
	PIN_ID_DRIVE_PUSH_PULL,
	PIN_ID_DRIVE_OPEN_DRAIN,
	PIN_ID_DRIVE_OPEN_SOURCE,
	PIN_ID_DRIVE_STRENGTH,
	PIN_ID_INPUT_ENABLE,
	PIN_ID_INPUT_DISABLE,
	PIN_ID_INPUT_SCHMITT_ENABLE,
	PIN_ID_INPUT_SCHMITT_DISABLE,
	PIN_ID_INPUT_DEBOUNCE,
	PIN_ID_POWER_SOURCE,
	PIN_ID_SLEW_RATE,
	PIN_ID_LOW_POWER_MODE_ENABLE,
	PIN_ID_LOW_POWER_MODE_DISABLE,
	PIN_ID_OUTPUT_LOW,
	PIN_ID_OUTPUT_HIGH,
	PIN_ID_VM_ENABLE,
	PIN_ID_VM_DISABLE,
	PROP_ID_MAX_ID
};

struct qcom_tlmm_prop_name {
	const char		*name;
	enum prop_id		id;
	int			have_value;
};

/*
 * Pull-up / pull-down configuration.
 */
typedef enum {
	QCOM_TLMM_PIN_PUPD_CONFIG_DISABLE = 0,
	QCOM_TLMM_PIN_PUPD_CONFIG_PULL_DOWN = 1,
	QCOM_TLMM_PIN_PUPD_CONFIG_PULL_UP = 2,
	QCOM_TLMM_PIN_PUPD_CONFIG_BUS_HOLD = 3,
} qcom_tlmm_pin_pupd_config_t;


/*
 * Pull-up / pull-down resistor configuration.
 */
typedef enum {
	QCOM_TLMM_PIN_RESISTOR_PUPD_CONFIG_10K = 0,
	QCOM_TLMM_PIN_RESISTOR_PUPD_CONFIG_1K5 = 1,
	QCOM_TLMM_PIN_RESISTOR_PUPD_CONFIG_35K = 2,
	QCOM_TLMM_PIN_RESISTOR_PUPD_CONFIG_20K = 3,
} qcom_tlmm_pin_resistor_pupd_config_t;

/*
 * configuration for one pin group.
 */
struct qcom_tlmm_pinctrl_cfg {
	char		*function;
	int		params[PROP_ID_MAX_ID];
};

#define GDEF(_id, ...)							\
{									\
	.id = _id,							\
	.name = "gpio" #_id,						\
	.functions = {"gpio", __VA_ARGS__}				\
}

struct qcom_tlmm_gpio_mux {
	int		id;
	char		*name;
	char		*functions[16]; /* XXX */
};

#define SDEF(n, r, ps, hs...)						\
{									\
	.name = n,							\
	.reg = r,							\
	.pull_shift = ps,						\
	.hdrv_shift = hs,						\
}


struct qcom_tlmm_spec_pin {
	char *name;
	uint32_t reg;
	uint32_t pull_shift;
	uint32_t hdrv_shift;
};

struct qcom_tlmm_softc {
	device_t		dev;
	device_t		busdev;
	struct mtx		gpio_mtx;
	struct resource		*gpio_mem_res;
	int			gpio_mem_rid;
	struct resource		*gpio_irq_res;
	int			gpio_irq_rid;
	void			*gpio_ih;
	int			gpio_npins;
	struct gpio_pin		*gpio_pins;
	uint32_t		sc_debug;

	const struct qcom_tlmm_gpio_mux	*gpio_muxes;
	const struct qcom_tlmm_spec_pin	*spec_pins;
};

/*
 * qcom_tlmm_pinmux.c
 */
extern	int qcom_tlmm_pinctrl_configure(device_t dev, phandle_t cfgxref);

#endif	/* __QCOM_TLMM_PINMUX_VAR_H__ */