blob: 5ecb434b03b6469df367615d56d00398d048a9bd [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Sughosh Ganu1b9c52b2010-11-30 11:25:01 -05002/*
3 * DaVinci pinmux functions.
4 *
5 * Copyright (C) 2009 Nick Thompson, GE Fanuc Ltd, <nick.thompson@gefanuc.com>
6 * Copyright (C) 2007 Sergey Kubushyn <ksi@koi8.net>
7 * Copyright (C) 2008 Lyrtech <www.lyrtech.com>
8 * Copyright (C) 2004 Texas Instruments.
Sughosh Ganu1b9c52b2010-11-30 11:25:01 -05009 */
10
Sughosh Ganu1b9c52b2010-11-30 11:25:01 -050011#include <asm/arch/hardware.h>
12#include <asm/io.h>
13#include <asm/arch/davinci_misc.h>
14
15/*
16 * Change the setting of a pin multiplexer field.
17 *
18 * Takes an array of pinmux settings similar to:
19 *
20 * struct pinmux_config uart_pins[] = {
21 * { &davinci_syscfg_regs->pinmux[8], 2, 7 },
22 * { &davinci_syscfg_regs->pinmux[9], 2, 0 }
23 * };
24 *
25 * Stepping through the array, each pinmux[n] register has the given value
26 * set in the pin mux field specified.
27 *
28 * The number of pins in the array must be passed (ARRAY_SIZE can provide
29 * this value conveniently).
30 *
31 * Returns 0 if all field numbers and values are in the correct range,
32 * else returns -1.
33 */
34int davinci_configure_pin_mux(const struct pinmux_config *pins,
35 const int n_pins)
36{
37 int i;
38
39 /* check for invalid pinmux values */
40 for (i = 0; i < n_pins; i++) {
41 if (pins[i].field >= PIN_MUX_NUM_FIELDS ||
42 (pins[i].value & ~PIN_MUX_FIELD_MASK) != 0)
43 return -1;
44 }
45
46 /* configure the pinmuxes */
47 for (i = 0; i < n_pins; i++) {
48 const int offset = pins[i].field * PIN_MUX_FIELD_SIZE;
49 const unsigned int value = pins[i].value << offset;
50 const unsigned int mask = PIN_MUX_FIELD_MASK << offset;
51 const dv_reg *mux = pins[i].mux;
52
53 writel(value | (readl(mux) & (~mask)), mux);
54 }
55
56 return 0;
57}
58
59/*
60 * Configure multiple pinmux resources.
61 *
62 * Takes an pinmux_resource array of pinmux_config and pin counts:
63 *
64 * const struct pinmux_resource pinmuxes[] = {
65 * PINMUX_ITEM(uart_pins),
66 * PINMUX_ITEM(i2c_pins),
67 * };
68 *
69 * The number of items in the array must be passed (ARRAY_SIZE can provide
70 * this value conveniently).
71 *
72 * Each item entry is configured in the defined order. If configuration
73 * of any item fails, -1 is returned and none of the following items are
74 * configured. On success, 0 is returned.
75 */
76int davinci_configure_pin_mux_items(const struct pinmux_resource *item,
77 const int n_items)
78{
79 int i;
80
81 for (i = 0; i < n_items; i++) {
82 if (davinci_configure_pin_mux(item[i].pins,
83 item[i].n_pins) != 0)
84 return -1;
85 }
86
87 return 0;
88}