2 * Pinctrl driver for the Toumaz Xenif TZ1090 SoC
4 * Copyright (c) 2013, Imagination Technologies Ltd.
6 * Derived from Tegra code:
7 * Copyright (c) 2011-2012, NVIDIA CORPORATION. All rights reserved.
10 * Copyright (C) 2010 Google, Inc.
11 * Copyright (C) 2010 NVIDIA Corporation
12 * Copyright (C) 2009-2011 ST-Ericsson AB
14 * This program is free software; you can redistribute it and/or modify it
15 * under the terms and conditions of the GNU General Public License,
16 * version 2, as published by the Free Software Foundation.
18 * This program is distributed in the hope it will be useful, but WITHOUT
19 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
24 #include <linux/bitops.h>
26 #include <linux/module.h>
28 #include <linux/platform_device.h>
29 #include <linux/pinctrl/machine.h>
30 #include <linux/pinctrl/pinconf-generic.h>
31 #include <linux/pinctrl/pinctrl.h>
32 #include <linux/pinctrl/pinmux.h>
33 #include <linux/slab.h>
34 #include <linux/spinlock.h>
37 * The registers may be shared with other threads/cores, so we need to use the
38 * metag global lock2 for atomicity.
40 #include <asm/global_lock.h>
45 /* Register offsets from bank base address */
46 #define REG_PINCTRL_SELECT 0x10
47 #define REG_PINCTRL_SCHMITT 0x90
48 #define REG_PINCTRL_PU_PD 0xa0
49 #define REG_PINCTRL_SR 0xc0
50 #define REG_PINCTRL_DR 0xd0
51 #define REG_PINCTRL_IF_CTL 0xe0
53 /* REG_PINCTRL_PU_PD field values */
54 #define REG_PU_PD_TRISTATE 0
55 #define REG_PU_PD_UP 1
56 #define REG_PU_PD_DOWN 2
57 #define REG_PU_PD_REPEATER 3
59 /* REG_PINCTRL_DR field values */
66 * struct tz1090_function - TZ1090 pinctrl mux function
67 * @name: The name of the function, exported to pinctrl core.
68 * @groups: An array of pin groups that may select this function.
69 * @ngroups: The number of entries in @groups.
71 struct tz1090_function
{
73 const char * const *groups
;
78 * struct tz1090_muxdesc - TZ1090 individual mux description
79 * @funcs: Function for each mux value.
80 * @reg: Mux register offset. 0 if unsupported.
81 * @bit: Mux register bit. 0 if unsupported.
82 * @width: Mux field width. 0 if unsupported.
84 * A representation of a group of signals (possibly just one signal) in the
85 * TZ1090 which can be muxed to a set of functions or sub muxes.
87 struct tz1090_muxdesc
{
95 * struct tz1090_pingroup - TZ1090 pin group
96 * @name: Name of pin group.
97 * @pins: Array of pin numbers in this pin group.
98 * @npins: Number of pins in this pin group.
99 * @mux: Top level mux.
100 * @drv: Drive control supported, 0 if unsupported.
101 * This means Schmitt, Slew, and Drive strength.
102 * @slw_bit: Slew register bit. 0 if unsupported.
103 * The same bit is used for Schmitt, and Drive (*2).
104 * @func: Currently muxed function.
105 * @func_count: Number of pins using current mux function.
107 * A representation of a group of pins (possibly just one pin) in the TZ1090
108 * pin controller. Each group allows some parameter or parameters to be
109 * configured. The most common is mux function selection.
111 struct tz1090_pingroup
{
113 const unsigned int *pins
;
115 struct tz1090_muxdesc mux
;
121 unsigned int func_count
;
125 * Most pins affected by the pinmux can also be GPIOs. Define these first.
126 * These must match how the GPIO driver names/numbers its pins.
139 TZ1090_PIN_SPI0_MCLK
,
143 TZ1090_PIN_SPI0_DOUT
,
145 TZ1090_PIN_SPI1_MCLK
,
149 TZ1090_PIN_SPI1_DOUT
,
151 TZ1090_PIN_UART0_RXD
,
152 TZ1090_PIN_UART0_TXD
,
153 TZ1090_PIN_UART0_CTS
,
154 TZ1090_PIN_UART0_RTS
,
155 TZ1090_PIN_UART1_RXD
,
156 TZ1090_PIN_UART1_TXD
,
157 TZ1090_PIN_SCB0_SDAT
,
158 TZ1090_PIN_SCB0_SCLK
,
159 TZ1090_PIN_SCB1_SDAT
,
160 TZ1090_PIN_SCB1_SCLK
,
161 TZ1090_PIN_SCB2_SDAT
,
162 TZ1090_PIN_SCB2_SCLK
,
164 TZ1090_PIN_I2S_BCLK_OUT
,
165 TZ1090_PIN_I2S_LRCLK_OUT
,
166 TZ1090_PIN_I2S_DOUT0
,
167 TZ1090_PIN_I2S_DOUT1
,
168 TZ1090_PIN_I2S_DOUT2
,
182 TZ1090_PIN_TFT_GREEN0
,
183 TZ1090_PIN_TFT_GREEN1
,
184 TZ1090_PIN_TFT_GREEN2
,
185 TZ1090_PIN_TFT_GREEN3
,
186 TZ1090_PIN_TFT_GREEN4
,
187 TZ1090_PIN_TFT_GREEN5
,
188 TZ1090_PIN_TFT_GREEN6
,
189 TZ1090_PIN_TFT_GREEN7
,
190 TZ1090_PIN_TFT_BLUE0
,
191 TZ1090_PIN_TFT_BLUE1
,
192 TZ1090_PIN_TFT_BLUE2
,
193 TZ1090_PIN_TFT_BLUE3
,
194 TZ1090_PIN_TFT_BLUE4
,
195 TZ1090_PIN_TFT_BLUE5
,
196 TZ1090_PIN_TFT_BLUE6
,
197 TZ1090_PIN_TFT_BLUE7
,
198 TZ1090_PIN_TFT_VDDEN_GD
,
199 TZ1090_PIN_TFT_PANELCLK
,
200 TZ1090_PIN_TFT_BLANK_LS
,
201 TZ1090_PIN_TFT_VSYNC_NS
,
202 TZ1090_PIN_TFT_HSYNC_NR
,
203 TZ1090_PIN_TFT_VD12ACB
,
204 TZ1090_PIN_TFT_PWRSAVE
,
220 TZ1090_PIN_SDH_CLK_IN
,
231 NUM_GPIOS
= TZ1090_PIN_TCK
,
236 static const struct pinctrl_pin_desc tz1090_pins
[] = {
238 PINCTRL_PIN(TZ1090_PIN_SDIO_CLK
, "sdio_clk"),
239 PINCTRL_PIN(TZ1090_PIN_SDIO_CMD
, "sdio_cmd"),
240 PINCTRL_PIN(TZ1090_PIN_SDIO_D0
, "sdio_d0"),
241 PINCTRL_PIN(TZ1090_PIN_SDIO_D1
, "sdio_d1"),
242 PINCTRL_PIN(TZ1090_PIN_SDIO_D2
, "sdio_d2"),
243 PINCTRL_PIN(TZ1090_PIN_SDIO_D3
, "sdio_d3"),
244 PINCTRL_PIN(TZ1090_PIN_SDH_CD
, "sdh_cd"),
245 PINCTRL_PIN(TZ1090_PIN_SDH_WP
, "sdh_wp"),
246 PINCTRL_PIN(TZ1090_PIN_SPI0_MCLK
, "spi0_mclk"),
247 PINCTRL_PIN(TZ1090_PIN_SPI0_CS0
, "spi0_cs0"),
248 PINCTRL_PIN(TZ1090_PIN_SPI0_CS1
, "spi0_cs1"),
249 PINCTRL_PIN(TZ1090_PIN_SPI0_CS2
, "spi0_cs2"),
250 PINCTRL_PIN(TZ1090_PIN_SPI0_DOUT
, "spi0_dout"),
251 PINCTRL_PIN(TZ1090_PIN_SPI0_DIN
, "spi0_din"),
252 PINCTRL_PIN(TZ1090_PIN_SPI1_MCLK
, "spi1_mclk"),
253 PINCTRL_PIN(TZ1090_PIN_SPI1_CS0
, "spi1_cs0"),
254 PINCTRL_PIN(TZ1090_PIN_SPI1_CS1
, "spi1_cs1"),
255 PINCTRL_PIN(TZ1090_PIN_SPI1_CS2
, "spi1_cs2"),
256 PINCTRL_PIN(TZ1090_PIN_SPI1_DOUT
, "spi1_dout"),
257 PINCTRL_PIN(TZ1090_PIN_SPI1_DIN
, "spi1_din"),
258 PINCTRL_PIN(TZ1090_PIN_UART0_RXD
, "uart0_rxd"),
259 PINCTRL_PIN(TZ1090_PIN_UART0_TXD
, "uart0_txd"),
260 PINCTRL_PIN(TZ1090_PIN_UART0_CTS
, "uart0_cts"),
261 PINCTRL_PIN(TZ1090_PIN_UART0_RTS
, "uart0_rts"),
262 PINCTRL_PIN(TZ1090_PIN_UART1_RXD
, "uart1_rxd"),
263 PINCTRL_PIN(TZ1090_PIN_UART1_TXD
, "uart1_txd"),
264 PINCTRL_PIN(TZ1090_PIN_SCB0_SDAT
, "scb0_sdat"),
265 PINCTRL_PIN(TZ1090_PIN_SCB0_SCLK
, "scb0_sclk"),
266 PINCTRL_PIN(TZ1090_PIN_SCB1_SDAT
, "scb1_sdat"),
267 PINCTRL_PIN(TZ1090_PIN_SCB1_SCLK
, "scb1_sclk"),
268 PINCTRL_PIN(TZ1090_PIN_SCB2_SDAT
, "scb2_sdat"),
269 PINCTRL_PIN(TZ1090_PIN_SCB2_SCLK
, "scb2_sclk"),
270 PINCTRL_PIN(TZ1090_PIN_I2S_MCLK
, "i2s_mclk"),
271 PINCTRL_PIN(TZ1090_PIN_I2S_BCLK_OUT
, "i2s_bclk_out"),
272 PINCTRL_PIN(TZ1090_PIN_I2S_LRCLK_OUT
, "i2s_lrclk_out"),
273 PINCTRL_PIN(TZ1090_PIN_I2S_DOUT0
, "i2s_dout0"),
274 PINCTRL_PIN(TZ1090_PIN_I2S_DOUT1
, "i2s_dout1"),
275 PINCTRL_PIN(TZ1090_PIN_I2S_DOUT2
, "i2s_dout2"),
276 PINCTRL_PIN(TZ1090_PIN_I2S_DIN
, "i2s_din"),
277 PINCTRL_PIN(TZ1090_PIN_PDM_A
, "pdm_a"),
278 PINCTRL_PIN(TZ1090_PIN_PDM_B
, "pdm_b"),
279 PINCTRL_PIN(TZ1090_PIN_PDM_C
, "pdm_c"),
280 PINCTRL_PIN(TZ1090_PIN_PDM_D
, "pdm_d"),
281 PINCTRL_PIN(TZ1090_PIN_TFT_RED0
, "tft_red0"),
282 PINCTRL_PIN(TZ1090_PIN_TFT_RED1
, "tft_red1"),
283 PINCTRL_PIN(TZ1090_PIN_TFT_RED2
, "tft_red2"),
284 PINCTRL_PIN(TZ1090_PIN_TFT_RED3
, "tft_red3"),
285 PINCTRL_PIN(TZ1090_PIN_TFT_RED4
, "tft_red4"),
286 PINCTRL_PIN(TZ1090_PIN_TFT_RED5
, "tft_red5"),
287 PINCTRL_PIN(TZ1090_PIN_TFT_RED6
, "tft_red6"),
288 PINCTRL_PIN(TZ1090_PIN_TFT_RED7
, "tft_red7"),
289 PINCTRL_PIN(TZ1090_PIN_TFT_GREEN0
, "tft_green0"),
290 PINCTRL_PIN(TZ1090_PIN_TFT_GREEN1
, "tft_green1"),
291 PINCTRL_PIN(TZ1090_PIN_TFT_GREEN2
, "tft_green2"),
292 PINCTRL_PIN(TZ1090_PIN_TFT_GREEN3
, "tft_green3"),
293 PINCTRL_PIN(TZ1090_PIN_TFT_GREEN4
, "tft_green4"),
294 PINCTRL_PIN(TZ1090_PIN_TFT_GREEN5
, "tft_green5"),
295 PINCTRL_PIN(TZ1090_PIN_TFT_GREEN6
, "tft_green6"),
296 PINCTRL_PIN(TZ1090_PIN_TFT_GREEN7
, "tft_green7"),
297 PINCTRL_PIN(TZ1090_PIN_TFT_BLUE0
, "tft_blue0"),
298 PINCTRL_PIN(TZ1090_PIN_TFT_BLUE1
, "tft_blue1"),
299 PINCTRL_PIN(TZ1090_PIN_TFT_BLUE2
, "tft_blue2"),
300 PINCTRL_PIN(TZ1090_PIN_TFT_BLUE3
, "tft_blue3"),
301 PINCTRL_PIN(TZ1090_PIN_TFT_BLUE4
, "tft_blue4"),
302 PINCTRL_PIN(TZ1090_PIN_TFT_BLUE5
, "tft_blue5"),
303 PINCTRL_PIN(TZ1090_PIN_TFT_BLUE6
, "tft_blue6"),
304 PINCTRL_PIN(TZ1090_PIN_TFT_BLUE7
, "tft_blue7"),
305 PINCTRL_PIN(TZ1090_PIN_TFT_VDDEN_GD
, "tft_vdden_gd"),
306 PINCTRL_PIN(TZ1090_PIN_TFT_PANELCLK
, "tft_panelclk"),
307 PINCTRL_PIN(TZ1090_PIN_TFT_BLANK_LS
, "tft_blank_ls"),
308 PINCTRL_PIN(TZ1090_PIN_TFT_VSYNC_NS
, "tft_vsync_ns"),
309 PINCTRL_PIN(TZ1090_PIN_TFT_HSYNC_NR
, "tft_hsync_nr"),
310 PINCTRL_PIN(TZ1090_PIN_TFT_VD12ACB
, "tft_vd12acb"),
311 PINCTRL_PIN(TZ1090_PIN_TFT_PWRSAVE
, "tft_pwrsave"),
312 PINCTRL_PIN(TZ1090_PIN_TX_ON
, "tx_on"),
313 PINCTRL_PIN(TZ1090_PIN_RX_ON
, "rx_on"),
314 PINCTRL_PIN(TZ1090_PIN_PLL_ON
, "pll_on"),
315 PINCTRL_PIN(TZ1090_PIN_PA_ON
, "pa_on"),
316 PINCTRL_PIN(TZ1090_PIN_RX_HP
, "rx_hp"),
317 PINCTRL_PIN(TZ1090_PIN_GAIN0
, "gain0"),
318 PINCTRL_PIN(TZ1090_PIN_GAIN1
, "gain1"),
319 PINCTRL_PIN(TZ1090_PIN_GAIN2
, "gain2"),
320 PINCTRL_PIN(TZ1090_PIN_GAIN3
, "gain3"),
321 PINCTRL_PIN(TZ1090_PIN_GAIN4
, "gain4"),
322 PINCTRL_PIN(TZ1090_PIN_GAIN5
, "gain5"),
323 PINCTRL_PIN(TZ1090_PIN_GAIN6
, "gain6"),
324 PINCTRL_PIN(TZ1090_PIN_GAIN7
, "gain7"),
325 PINCTRL_PIN(TZ1090_PIN_ANT_SEL0
, "ant_sel0"),
326 PINCTRL_PIN(TZ1090_PIN_ANT_SEL1
, "ant_sel1"),
327 PINCTRL_PIN(TZ1090_PIN_SDH_CLK_IN
, "sdh_clk_in"),
330 PINCTRL_PIN(TZ1090_PIN_TCK
, "tck"),
331 PINCTRL_PIN(TZ1090_PIN_TRST
, "trst"),
332 PINCTRL_PIN(TZ1090_PIN_TDI
, "tdi"),
333 PINCTRL_PIN(TZ1090_PIN_TDO
, "tdo"),
334 PINCTRL_PIN(TZ1090_PIN_TMS
, "tms"),
335 PINCTRL_PIN(TZ1090_PIN_CLK_OUT0
, "clk_out0"),
336 PINCTRL_PIN(TZ1090_PIN_CLK_OUT1
, "clk_out1"),
339 /* Pins in each pin group */
341 static const unsigned int spi1_cs2_pins
[] = {
345 static const unsigned int pdm_d_pins
[] = {
349 static const unsigned int tft_pins
[] = {
358 TZ1090_PIN_TFT_GREEN0
,
359 TZ1090_PIN_TFT_GREEN1
,
360 TZ1090_PIN_TFT_GREEN2
,
361 TZ1090_PIN_TFT_GREEN3
,
362 TZ1090_PIN_TFT_GREEN4
,
363 TZ1090_PIN_TFT_GREEN5
,
364 TZ1090_PIN_TFT_GREEN6
,
365 TZ1090_PIN_TFT_GREEN7
,
366 TZ1090_PIN_TFT_BLUE0
,
367 TZ1090_PIN_TFT_BLUE1
,
368 TZ1090_PIN_TFT_BLUE2
,
369 TZ1090_PIN_TFT_BLUE3
,
370 TZ1090_PIN_TFT_BLUE4
,
371 TZ1090_PIN_TFT_BLUE5
,
372 TZ1090_PIN_TFT_BLUE6
,
373 TZ1090_PIN_TFT_BLUE7
,
374 TZ1090_PIN_TFT_VDDEN_GD
,
375 TZ1090_PIN_TFT_PANELCLK
,
376 TZ1090_PIN_TFT_BLANK_LS
,
377 TZ1090_PIN_TFT_VSYNC_NS
,
378 TZ1090_PIN_TFT_HSYNC_NR
,
379 TZ1090_PIN_TFT_VD12ACB
,
380 TZ1090_PIN_TFT_PWRSAVE
,
383 static const unsigned int afe_pins
[] = {
401 static const unsigned int sdio_pins
[] = {
410 static const unsigned int sdh_pins
[] = {
413 TZ1090_PIN_SDH_CLK_IN
,
416 static const unsigned int spi0_pins
[] = {
417 TZ1090_PIN_SPI0_MCLK
,
421 TZ1090_PIN_SPI0_DOUT
,
425 static const unsigned int spi1_pins
[] = {
426 TZ1090_PIN_SPI1_MCLK
,
430 TZ1090_PIN_SPI1_DOUT
,
434 static const unsigned int uart0_pins
[] = {
435 TZ1090_PIN_UART0_RTS
,
436 TZ1090_PIN_UART0_CTS
,
437 TZ1090_PIN_UART0_TXD
,
438 TZ1090_PIN_UART0_RXD
,
441 static const unsigned int uart1_pins
[] = {
442 TZ1090_PIN_UART1_TXD
,
443 TZ1090_PIN_UART1_RXD
,
446 static const unsigned int uart_pins
[] = {
447 TZ1090_PIN_UART1_TXD
,
448 TZ1090_PIN_UART1_RXD
,
449 TZ1090_PIN_UART0_RTS
,
450 TZ1090_PIN_UART0_CTS
,
451 TZ1090_PIN_UART0_TXD
,
452 TZ1090_PIN_UART0_RXD
,
455 static const unsigned int scb0_pins
[] = {
456 TZ1090_PIN_SCB0_SDAT
,
457 TZ1090_PIN_SCB0_SCLK
,
460 static const unsigned int scb1_pins
[] = {
461 TZ1090_PIN_SCB1_SDAT
,
462 TZ1090_PIN_SCB1_SCLK
,
465 static const unsigned int scb2_pins
[] = {
466 TZ1090_PIN_SCB2_SDAT
,
467 TZ1090_PIN_SCB2_SCLK
,
470 static const unsigned int i2s_pins
[] = {
472 TZ1090_PIN_I2S_BCLK_OUT
,
473 TZ1090_PIN_I2S_LRCLK_OUT
,
474 TZ1090_PIN_I2S_DOUT0
,
475 TZ1090_PIN_I2S_DOUT1
,
476 TZ1090_PIN_I2S_DOUT2
,
480 static const unsigned int jtag_pins
[] = {
488 /* Pins in each drive pin group */
490 static const unsigned int drive_sdio_pins
[] = {
499 TZ1090_PIN_SDH_CLK_IN
,
502 static const unsigned int drive_i2s_pins
[] = {
505 TZ1090_PIN_I2S_DOUT0
,
506 TZ1090_PIN_I2S_DOUT1
,
507 TZ1090_PIN_I2S_DOUT2
,
508 TZ1090_PIN_I2S_LRCLK_OUT
,
509 TZ1090_PIN_I2S_BCLK_OUT
,
513 static const unsigned int drive_scb0_pins
[] = {
514 TZ1090_PIN_SCB0_SCLK
,
515 TZ1090_PIN_SCB0_SDAT
,
520 static const unsigned int drive_pdm_pins
[] = {
526 /* Pin groups each function can be muxed to */
529 * The magic "perip" function allows otherwise non-muxing pins to be enabled in
532 static const char * const perip_groups
[] = {
533 /* non-muxing convenient gpio pingroups */
543 /* individual pins not part of a pin mux group */
579 static const char * const sdh_sdio_groups
[] = {
595 static const char * const spi1_cs2_groups
[] = {
599 static const char * const pdm_dac_groups
[] = {
603 static const char * const usb_vbus_groups
[] = {
608 static const char * const afe_groups
[] = {
628 static const char * const tft_groups
[] = {
664 /* Mux functions that can be used by a mux */
667 /* internal placeholder */
669 /* magic per-non-muxing-GPIO-pin peripheral mode mux */
683 TZ1090_MUX_NOT_IQADC_STB
,
684 TZ1090_MUX_IQDAC_STB
,
689 TZ1090_MUX_LCD_TRACE
,
690 TZ1090_MUX_PHY_RINGOSC
,
693 #define FUNCTION(mux, fname, group) \
694 [(TZ1090_MUX_ ## mux)] = { \
696 .groups = group##_groups, \
697 .ngroups = ARRAY_SIZE(group##_groups), \
699 /* For intermediate functions with submuxes */
700 #define NULL_FUNCTION(mux, fname) \
701 [(TZ1090_MUX_ ## mux)] = { \
705 /* Must correlate with enum tz1090_mux */
706 static const struct tz1090_function tz1090_functions
[] = {
707 /* FUNCTION function name pingroups */
708 FUNCTION(PERIP
, perip
, perip
),
709 FUNCTION(SDH
, sdh
, sdh_sdio
),
710 FUNCTION(SDIO
, sdio
, sdh_sdio
),
711 FUNCTION(SPI1_CS2
, spi1_cs2
, spi1_cs2
),
712 FUNCTION(PDM_DAC
, pdm_dac
, pdm_dac
),
713 FUNCTION(USB_VBUS
, usb_vbus
, usb_vbus
),
714 FUNCTION(AFE
, afe
, afe
),
715 FUNCTION(TS_OUT_0
, ts_out_0
, afe
),
716 FUNCTION(DAC
, ext_dac
, tft
),
717 FUNCTION(NOT_IQADC_STB
, not_iqadc_stb
, tft
),
718 FUNCTION(IQDAC_STB
, iqdac_stb
, tft
),
719 FUNCTION(TFT
, tft
, tft
),
720 NULL_FUNCTION(EXT_DAC
, _ext_dac
),
721 FUNCTION(TS_OUT_1
, ts_out_1
, tft
),
722 FUNCTION(LCD_TRACE
, lcd_trace
, tft
),
723 FUNCTION(PHY_RINGOSC
, phy_ringosc
, tft
),
729 * MUX() - Initialise a mux description.
730 * @f0: Function 0 (TZ1090_MUX_ is prepended, NA for none)
731 * @f1: Function 1 (TZ1090_MUX_ is prepended, NA for none)
732 * @f2: Function 2 (TZ1090_MUX_ is prepended, NA for none)
733 * @f3: Function 3 (TZ1090_MUX_ is prepended, NA for none)
734 * @f4: Function 4 (TZ1090_MUX_ is prepended, NA for none)
735 * @mux_r: Mux register (REG_PINCTRL_ is prepended)
736 * @mux_b: Bit number in register that the mux field begins
737 * @mux_w: Width of mux field in register
739 #define MUX(f0, f1, f2, f3, f4, mux_r, mux_b, mux_w) \
748 .reg = (REG_PINCTRL_ ## mux_r), \
754 * DEFINE_SUBMUX() - Defines a submux description separate from a pin group.
755 * @mux: Mux name (_submux is appended)
756 * @f0: Function 0 (TZ1090_MUX_ is prepended, NA for none)
757 * @f1: Function 1 (TZ1090_MUX_ is prepended, NA for none)
758 * @f2: Function 2 (TZ1090_MUX_ is prepended, NA for none)
759 * @f3: Function 3 (TZ1090_MUX_ is prepended, NA for none)
760 * @f4: Function 4 (TZ1090_MUX_ is prepended, NA for none)
761 * @mux_r: Mux register (REG_PINCTRL_ is prepended)
762 * @mux_b: Bit number in register that the mux field begins
763 * @mux_w: Width of mux field in register
765 * A sub mux is a nested mux that can be bound to a magic function number used
766 * by another mux description. For example value 4 of the top level mux might
767 * correspond to a function which has a submux pointed to in tz1090_submux[].
768 * The outer mux can then take on any function in the top level mux or the
769 * submux, and if a submux function is chosen both muxes are updated to route
770 * the signal from the submux.
772 * The submux can be defined with DEFINE_SUBMUX and pointed to from
773 * tz1090_submux[] using SUBMUX.
775 #define DEFINE_SUBMUX(mux, f0, f1, f2, f3, f4, mux_r, mux_b, mux_w) \
776 static struct tz1090_muxdesc mux ## _submux = \
777 MUX(f0, f1, f2, f3, f4, mux_r, mux_b, mux_w)
780 * SUBMUX() - Link a submux to a function number.
781 * @f: Function name (TZ1090_MUX_ is prepended)
782 * @submux: Submux name (_submux is appended)
784 * For use in tz1090_submux[] initialisation to link an intermediate function
785 * number to a particular submux description. It indicates that when the
786 * function is chosen the signal is connected to the submux.
788 #define SUBMUX(f, submux) [(TZ1090_MUX_ ## f)] = &(submux ## _submux)
791 * MUX_PG() - Initialise a pin group with mux control
792 * @pg_name: Pin group name (stringified, _pins appended to get pins array)
793 * @f0: Function 0 (TZ1090_MUX_ is prepended, NA for none)
794 * @f1: Function 1 (TZ1090_MUX_ is prepended, NA for none)
795 * @f2: Function 2 (TZ1090_MUX_ is prepended, NA for none)
796 * @f3: Function 3 (TZ1090_MUX_ is prepended, NA for none)
797 * @f4: Function 4 (TZ1090_MUX_ is prepended, NA for none)
798 * @mux_r: Mux register (REG_PINCTRL_ is prepended)
799 * @mux_b: Bit number in register that the mux field begins
800 * @mux_w: Width of mux field in register
802 #define MUX_PG(pg_name, f0, f1, f2, f3, f4, \
803 mux_r, mux_b, mux_w) \
806 .pins = pg_name##_pins, \
807 .npins = ARRAY_SIZE(pg_name##_pins), \
808 .mux = MUX(f0, f1, f2, f3, f4, \
809 mux_r, mux_b, mux_w), \
813 * SIMPLE_PG() - Initialise a simple convenience pin group
814 * @pg_name: Pin group name (stringified, _pins appended to get pins array)
816 * A simple pin group is simply used for binding pins together so they can be
817 * referred to by a single name instead of having to list every pin
820 #define SIMPLE_PG(pg_name) \
823 .pins = pg_name##_pins, \
824 .npins = ARRAY_SIZE(pg_name##_pins), \
828 * DRV_PG() - Initialise a pin group with drive control
829 * @pg_name: Pin group name (stringified, _pins appended to get pins array)
830 * @slw_b: Slew register bit.
831 * The same bit is used for Schmitt, and Drive (*2).
833 #define DRV_PG(pg_name, slw_b) \
836 .pins = pg_name##_pins, \
837 .npins = ARRAY_SIZE(pg_name##_pins), \
839 .slw_bit = (slw_b), \
843 * Define main muxing pin groups
848 /* name f0, f1, f2, f3, f4, mux r/b/w */
849 DEFINE_SUBMUX(ext_dac
, DAC
, NOT_IQADC_STB
, IQDAC_STB
, NA
, NA
, IF_CTL
, 6, 2);
851 /* bind submuxes to internal functions */
852 static struct tz1090_muxdesc
*tz1090_submux
[] = {
853 SUBMUX(EXT_DAC
, ext_dac
),
857 * These are the pin mux groups. Pin muxing can be enabled and disabled for each
858 * pin individually so these groups are internal. The mapping of pins to pin mux
859 * group is below (tz1090_mux_pins).
861 static struct tz1090_pingroup tz1090_mux_groups
[] = {
862 /* Muxing pin groups */
863 /* pg_name, f0, f1, f2, f3, f4, mux r/b/w */
864 MUX_PG(sdh
, SDH
, SDIO
, NA
, NA
, NA
, IF_CTL
, 20, 2),
865 MUX_PG(sdio
, SDIO
, SDH
, NA
, NA
, NA
, IF_CTL
, 16, 2),
866 MUX_PG(spi1_cs2
, SPI1_CS2
, USB_VBUS
, NA
, NA
, NA
, IF_CTL
, 10, 2),
867 MUX_PG(pdm_d
, PDM_DAC
, USB_VBUS
, NA
, NA
, NA
, IF_CTL
, 8, 2),
868 MUX_PG(afe
, AFE
, TS_OUT_0
, NA
, NA
, NA
, IF_CTL
, 4, 2),
869 MUX_PG(tft
, TFT
, EXT_DAC
, TS_OUT_1
, LCD_TRACE
, PHY_RINGOSC
, IF_CTL
, 0, 3),
873 * This is the mapping from GPIO pins to pin mux groups in tz1090_mux_groups[].
874 * Pins which aren't muxable to multiple peripherals are set to
875 * TZ1090_MUX_GROUP_MAX to enable the "perip" function to enable/disable
876 * peripheral control of the pin.
878 * This array is initialised in tz1090_init_mux_pins().
880 static u8 tz1090_mux_pins
[NUM_GPIOS
];
882 /* TZ1090_MUX_GROUP_MAX is used in tz1090_mux_pins[] for non-muxing pins */
883 #define TZ1090_MUX_GROUP_MAX ARRAY_SIZE(tz1090_mux_groups)
886 * tz1090_init_mux_pins() - Initialise GPIO pin to mux group mapping.
888 * Initialises the tz1090_mux_pins[] array to be the inverse of the pin lists in
889 * each pin mux group in tz1090_mux_groups[].
891 * It is assumed that no pin mux groups overlap (share pins).
893 static void __init
tz1090_init_mux_pins(void)
896 const struct tz1090_pingroup
*grp
;
897 const unsigned int *pin
;
899 for (p
= 0; p
< NUM_GPIOS
; ++p
)
900 tz1090_mux_pins
[p
] = TZ1090_MUX_GROUP_MAX
;
902 grp
= tz1090_mux_groups
;
903 for (g
= 0, grp
= tz1090_mux_groups
;
904 g
< ARRAY_SIZE(tz1090_mux_groups
); ++g
, ++grp
)
905 for (pin
= grp
->pins
, p
= 0; p
< grp
->npins
; ++p
, ++pin
)
906 tz1090_mux_pins
[*pin
] = g
;
910 * These are the externally visible pin groups. Some of them allow group control
911 * of drive configuration. Some are just simple convenience pingroups. All the
912 * internal pin mux groups in tz1090_mux_groups[] are mirrored here with the
914 * Pseudo pin groups follow in the group numbers after this array for each GPIO
915 * pin. Any group used for muxing must have all pins belonging to the same pin
918 static struct tz1090_pingroup tz1090_groups
[] = {
919 /* Pin groups with drive control (with no out of place pins) */
920 /* pg_name, slw/schmitt/drv b */
921 DRV_PG(jtag
, 11 /* 11, 22 */),
922 DRV_PG(tft
, 10 /* 10, 20 */),
923 DRV_PG(scb2
, 9 /* 9, 18 */),
924 DRV_PG(spi0
, 7 /* 7, 14 */),
925 DRV_PG(uart
, 5 /* 5, 10 */),
926 DRV_PG(scb1
, 4 /* 4, 8 */),
927 DRV_PG(spi1
, 3 /* 3, 6 */),
928 DRV_PG(afe
, 0 /* 0, 0 */),
931 * Drive specific pin groups (with odd combinations of pins which makes
932 * the pin group naming somewhat arbitrary)
934 /* pg_name, slw/schmitt/drv b */
935 DRV_PG(drive_sdio
, 8 /* 8, 16 */), /* sdio_* + sdh_* */
936 DRV_PG(drive_i2s
, 6 /* 6, 12 */), /* i2s_* + clk_out1 */
937 DRV_PG(drive_scb0
, 2 /* 2, 4 */), /* scb0_* + pdm_{c,d} */
938 DRV_PG(drive_pdm
, 1 /* 1, 2 */), /* pdm_{a,b} + clk_out0 */
940 /* Convenience pin groups */
949 /* pseudo-pingroups for each GPIO pin follow */
953 * struct tz1090_pmx - Private pinctrl data
954 * @dev: Platform device
955 * @pctl: Pin control device
956 * @regs: Register region
957 * @lock: Lock protecting coherency of pin_en, gpio_en, and SELECT regs
958 * @pin_en: Pins that have been enabled (32 pins packed into each element)
959 * @gpio_en: GPIOs that have been enabled (32 pins packed into each element)
963 struct pinctrl_dev
*pctl
;
970 static inline u32
pmx_read(struct tz1090_pmx
*pmx
, u32 reg
)
972 return ioread32(pmx
->regs
+ reg
);
975 static inline void pmx_write(struct tz1090_pmx
*pmx
, u32 val
, u32 reg
)
977 iowrite32(val
, pmx
->regs
+ reg
);
981 * Pin control operations
984 /* each GPIO pin has it's own pseudo pingroup containing only itself */
986 static int tz1090_pinctrl_get_groups_count(struct pinctrl_dev
*pctldev
)
988 return ARRAY_SIZE(tz1090_groups
) + NUM_GPIOS
;
991 static const char *tz1090_pinctrl_get_group_name(struct pinctrl_dev
*pctldev
,
994 if (group
< ARRAY_SIZE(tz1090_groups
)) {
995 /* normal pingroup */
996 return tz1090_groups
[group
].name
;
998 /* individual gpio pin pseudo-pingroup */
999 unsigned int pin
= group
- ARRAY_SIZE(tz1090_groups
);
1000 return tz1090_pins
[pin
].name
;
1004 static int tz1090_pinctrl_get_group_pins(struct pinctrl_dev
*pctldev
,
1006 const unsigned int **pins
,
1007 unsigned int *num_pins
)
1009 if (group
< ARRAY_SIZE(tz1090_groups
)) {
1010 /* normal pingroup */
1011 *pins
= tz1090_groups
[group
].pins
;
1012 *num_pins
= tz1090_groups
[group
].npins
;
1014 /* individual gpio pin pseudo-pingroup */
1015 unsigned int pin
= group
- ARRAY_SIZE(tz1090_groups
);
1016 *pins
= &tz1090_pins
[pin
].number
;
1023 #ifdef CONFIG_DEBUG_FS
1024 static void tz1090_pinctrl_pin_dbg_show(struct pinctrl_dev
*pctldev
,
1026 unsigned int offset
)
1028 seq_printf(s
, " %s", dev_name(pctldev
->dev
));
1032 static int reserve_map(struct device
*dev
, struct pinctrl_map
**map
,
1033 unsigned int *reserved_maps
, unsigned int *num_maps
,
1034 unsigned int reserve
)
1036 unsigned int old_num
= *reserved_maps
;
1037 unsigned int new_num
= *num_maps
+ reserve
;
1038 struct pinctrl_map
*new_map
;
1040 if (old_num
>= new_num
)
1043 new_map
= krealloc(*map
, sizeof(*new_map
) * new_num
, GFP_KERNEL
);
1045 dev_err(dev
, "krealloc(map) failed\n");
1049 memset(new_map
+ old_num
, 0, (new_num
- old_num
) * sizeof(*new_map
));
1052 *reserved_maps
= new_num
;
1057 static int add_map_mux(struct pinctrl_map
**map
, unsigned int *reserved_maps
,
1058 unsigned int *num_maps
, const char *group
,
1059 const char *function
)
1061 if (WARN_ON(*num_maps
== *reserved_maps
))
1064 (*map
)[*num_maps
].type
= PIN_MAP_TYPE_MUX_GROUP
;
1065 (*map
)[*num_maps
].data
.mux
.group
= group
;
1066 (*map
)[*num_maps
].data
.mux
.function
= function
;
1072 static int add_map_configs(struct device
*dev
,
1073 struct pinctrl_map
**map
,
1074 unsigned int *reserved_maps
, unsigned int *num_maps
,
1075 const char *group
, unsigned long *configs
,
1076 unsigned int num_configs
)
1078 unsigned long *dup_configs
;
1080 if (WARN_ON(*num_maps
== *reserved_maps
))
1083 dup_configs
= kmemdup(configs
, num_configs
* sizeof(*dup_configs
),
1086 dev_err(dev
, "kmemdup(configs) failed\n");
1090 (*map
)[*num_maps
].type
= PIN_MAP_TYPE_CONFIGS_GROUP
;
1091 (*map
)[*num_maps
].data
.configs
.group_or_pin
= group
;
1092 (*map
)[*num_maps
].data
.configs
.configs
= dup_configs
;
1093 (*map
)[*num_maps
].data
.configs
.num_configs
= num_configs
;
1099 static void tz1090_pinctrl_dt_free_map(struct pinctrl_dev
*pctldev
,
1100 struct pinctrl_map
*map
,
1101 unsigned int num_maps
)
1105 for (i
= 0; i
< num_maps
; i
++)
1106 if (map
[i
].type
== PIN_MAP_TYPE_CONFIGS_GROUP
)
1107 kfree(map
[i
].data
.configs
.configs
);
1112 static int tz1090_pinctrl_dt_subnode_to_map(struct device
*dev
,
1113 struct device_node
*np
,
1114 struct pinctrl_map
**map
,
1115 unsigned int *reserved_maps
,
1116 unsigned int *num_maps
)
1119 const char *function
;
1120 unsigned long *configs
= NULL
;
1121 unsigned int num_configs
= 0;
1122 unsigned int reserve
;
1123 struct property
*prop
;
1126 ret
= of_property_read_string(np
, "tz1090,function", &function
);
1128 /* EINVAL=missing, which is fine since it's optional */
1130 dev_err(dev
, "could not parse property function\n");
1134 ret
= pinconf_generic_parse_dt_config(np
, NULL
, &configs
, &num_configs
);
1139 if (function
!= NULL
)
1143 ret
= of_property_count_strings(np
, "tz1090,pins");
1145 dev_err(dev
, "could not parse property pins\n");
1150 ret
= reserve_map(dev
, map
, reserved_maps
, num_maps
, reserve
);
1154 of_property_for_each_string(np
, "tz1090,pins", prop
, group
) {
1156 ret
= add_map_mux(map
, reserved_maps
, num_maps
,
1163 ret
= add_map_configs(dev
, map
, reserved_maps
,
1164 num_maps
, group
, configs
,
1178 static int tz1090_pinctrl_dt_node_to_map(struct pinctrl_dev
*pctldev
,
1179 struct device_node
*np_config
,
1180 struct pinctrl_map
**map
,
1181 unsigned int *num_maps
)
1183 unsigned int reserved_maps
;
1184 struct device_node
*np
;
1191 for_each_child_of_node(np_config
, np
) {
1192 ret
= tz1090_pinctrl_dt_subnode_to_map(pctldev
->dev
, np
, map
,
1196 tz1090_pinctrl_dt_free_map(pctldev
, *map
, *num_maps
);
1204 static struct pinctrl_ops tz1090_pinctrl_ops
= {
1205 .get_groups_count
= tz1090_pinctrl_get_groups_count
,
1206 .get_group_name
= tz1090_pinctrl_get_group_name
,
1207 .get_group_pins
= tz1090_pinctrl_get_group_pins
,
1208 #ifdef CONFIG_DEBUG_FS
1209 .pin_dbg_show
= tz1090_pinctrl_pin_dbg_show
,
1211 .dt_node_to_map
= tz1090_pinctrl_dt_node_to_map
,
1212 .dt_free_map
= tz1090_pinctrl_dt_free_map
,
1216 * Pin mux operations
1219 static int tz1090_pinctrl_get_funcs_count(struct pinctrl_dev
*pctldev
)
1221 return ARRAY_SIZE(tz1090_functions
);
1224 static const char *tz1090_pinctrl_get_func_name(struct pinctrl_dev
*pctldev
,
1225 unsigned int function
)
1227 return tz1090_functions
[function
].name
;
1230 static int tz1090_pinctrl_get_func_groups(struct pinctrl_dev
*pctldev
,
1231 unsigned int function
,
1232 const char * const **groups
,
1233 unsigned int * const num_groups
)
1235 /* pingroup functions */
1236 *groups
= tz1090_functions
[function
].groups
;
1237 *num_groups
= tz1090_functions
[function
].ngroups
;
1242 * tz1090_pinctrl_select() - update bit in SELECT register
1244 * @pin: Pin number (must be within GPIO range)
1246 static void tz1090_pinctrl_select(struct tz1090_pmx
*pmx
,
1249 u32 reg
, reg_shift
, select
, val
;
1250 unsigned int pmx_index
, pmx_shift
;
1251 unsigned long flags
;
1253 /* uses base 32 instead of base 30 */
1254 pmx_index
= pin
>> 5;
1255 pmx_shift
= pin
& 0x1f;
1257 /* select = !perip || gpio */
1258 select
= ((~pmx
->pin_en
[pmx_index
] |
1259 pmx
->gpio_en
[pmx_index
]) >> pmx_shift
) & 1;
1261 /* find register and bit offset (base 30) */
1262 reg
= REG_PINCTRL_SELECT
+ 4*(pin
/ 30);
1263 reg_shift
= pin
% 30;
1265 /* modify gpio select bit */
1266 __global_lock2(flags
);
1267 val
= pmx_read(pmx
, reg
);
1268 val
&= ~BIT(reg_shift
);
1269 val
|= select
<< reg_shift
;
1270 pmx_write(pmx
, val
, reg
);
1271 __global_unlock2(flags
);
1275 * tz1090_pinctrl_gpio_select() - enable/disable GPIO usage for a pin
1278 * @gpio_select: true to enable pin as GPIO,
1279 * false to leave control to whatever function is enabled
1281 * Records that GPIO usage is enabled/disabled so that enabling a function
1282 * doesn't override the SELECT register bit.
1284 static void tz1090_pinctrl_gpio_select(struct tz1090_pmx
*pmx
,
1288 unsigned int index
, shift
;
1291 if (pin
>= NUM_GPIOS
)
1294 /* uses base 32 instead of base 30 */
1298 spin_lock(&pmx
->lock
);
1300 /* keep a record whether gpio is selected */
1301 gpio_en
= pmx
->gpio_en
[index
];
1302 gpio_en
&= ~BIT(shift
);
1304 gpio_en
|= BIT(shift
);
1305 pmx
->gpio_en
[index
] = gpio_en
;
1307 /* update the select bit */
1308 tz1090_pinctrl_select(pmx
, pin
);
1310 spin_unlock(&pmx
->lock
);
1314 * tz1090_pinctrl_perip_select() - enable/disable peripheral interface for a pin
1317 * @perip_select: true to enable peripheral interface when not GPIO,
1318 * false to leave pin in GPIO mode
1320 * Records that peripheral usage is enabled/disabled so that SELECT register can
1321 * be set appropriately when GPIO is disabled.
1323 static void tz1090_pinctrl_perip_select(struct tz1090_pmx
*pmx
,
1327 unsigned int index
, shift
;
1330 if (pin
>= NUM_GPIOS
)
1333 /* uses base 32 instead of base 30 */
1337 spin_lock(&pmx
->lock
);
1339 /* keep a record whether peripheral is selected */
1340 pin_en
= pmx
->pin_en
[index
];
1341 pin_en
&= ~BIT(shift
);
1343 pin_en
|= BIT(shift
);
1344 pmx
->pin_en
[index
] = pin_en
;
1346 /* update the select bit */
1347 tz1090_pinctrl_select(pmx
, pin
);
1349 spin_unlock(&pmx
->lock
);
1353 * tz1090_pinctrl_enable_mux() - Switch a pin mux group to a function.
1355 * @desc: Pinmux description
1356 * @function: Function to switch to
1358 * Enable a particular function on a pin mux group. Since pin mux descriptions
1359 * are nested this function is recursive.
1361 static int tz1090_pinctrl_enable_mux(struct tz1090_pmx
*pmx
,
1362 const struct tz1090_muxdesc
*desc
,
1363 unsigned int function
)
1366 unsigned long flags
;
1368 unsigned int func
, ret
;
1371 /* find the mux value for this function, searching recursively */
1372 for (mux
= 0, fit
= desc
->funcs
;
1373 mux
< ARRAY_SIZE(desc
->funcs
); ++mux
, ++fit
) {
1375 if (func
== function
)
1378 /* maybe it's a sub-mux */
1379 if (func
< ARRAY_SIZE(tz1090_submux
) && tz1090_submux
[func
]) {
1380 ret
= tz1090_pinctrl_enable_mux(pmx
,
1381 tz1090_submux
[func
],
1391 /* Set up the mux */
1393 mask
= (BIT(desc
->width
) - 1) << desc
->bit
;
1394 __global_lock2(flags
);
1395 reg
= pmx_read(pmx
, desc
->reg
);
1397 reg
|= (mux
<< desc
->bit
) & mask
;
1398 pmx_write(pmx
, reg
, desc
->reg
);
1399 __global_unlock2(flags
);
1406 * tz1090_pinctrl_enable() - Enable a function on a pin group.
1407 * @pctldev: Pin control data
1408 * @function: Function index to enable
1409 * @group: Group index to enable
1411 * Enable a particular function on a group of pins. The per GPIO pin pseudo pin
1412 * groups can be used (in which case the pin will be enabled in peripheral mode
1413 * and if it belongs to a pin mux group the mux will be switched if it isn't
1414 * already in use. Some convenience pin groups can also be used in which case
1415 * the effect is the same as enabling the function on each individual pin in the
1418 static int tz1090_pinctrl_set_mux(struct pinctrl_dev
*pctldev
,
1419 unsigned int function
, unsigned int group
)
1421 struct tz1090_pmx
*pmx
= pinctrl_dev_get_drvdata(pctldev
);
1422 struct tz1090_pingroup
*grp
;
1424 unsigned int pin_num
, mux_group
, i
, npins
;
1425 const unsigned int *pins
;
1427 /* group of pins? */
1428 if (group
< ARRAY_SIZE(tz1090_groups
)) {
1429 grp
= &tz1090_groups
[group
];
1433 * All pins in the group must belong to the same mux group,
1434 * which allows us to just use the mux group of the first pin.
1435 * By explicitly listing permitted pingroups for each function
1436 * the pinmux core should ensure this is always the case.
1439 pin_num
= group
- ARRAY_SIZE(tz1090_groups
);
1443 mux_group
= tz1090_mux_pins
[*pins
];
1445 /* no mux group, but can still be individually muxed to peripheral */
1446 if (mux_group
>= TZ1090_MUX_GROUP_MAX
) {
1447 if (function
== TZ1090_MUX_PERIP
)
1452 /* mux group already set to a different function? */
1453 grp
= &tz1090_mux_groups
[mux_group
];
1454 if (grp
->func_count
&& grp
->func
!= function
) {
1455 dev_err(pctldev
->dev
,
1456 "%s: can't mux pin(s) to '%s', group already muxed to '%s'\n",
1457 __func__
, tz1090_functions
[function
].name
,
1458 tz1090_functions
[grp
->func
].name
);
1462 dev_dbg(pctldev
->dev
, "%s: muxing %u pin(s) in '%s' to '%s'\n",
1463 __func__
, npins
, grp
->name
, tz1090_functions
[function
].name
);
1465 /* if first pin in mux group to be enabled, enable the group mux */
1466 if (!grp
->func_count
) {
1467 grp
->func
= function
;
1468 ret
= tz1090_pinctrl_enable_mux(pmx
, &grp
->mux
, function
);
1472 /* add pins to ref count and mux individually to peripheral */
1473 grp
->func_count
+= npins
;
1475 for (i
= 0; i
< npins
; ++i
)
1476 tz1090_pinctrl_perip_select(pmx
, pins
[i
], true);
1482 * tz1090_pinctrl_gpio_request_enable() - Put pin in GPIO mode.
1483 * @pctldev: Pin control data
1484 * @range: GPIO range
1487 * Puts a particular pin into GPIO mode, disabling peripheral control until it's
1490 static int tz1090_pinctrl_gpio_request_enable(struct pinctrl_dev
*pctldev
,
1491 struct pinctrl_gpio_range
*range
,
1494 struct tz1090_pmx
*pmx
= pinctrl_dev_get_drvdata(pctldev
);
1495 tz1090_pinctrl_gpio_select(pmx
, pin
, true);
1500 * tz1090_pinctrl_gpio_disable_free() - Take pin out of GPIO mode.
1501 * @pctldev: Pin control data
1502 * @range: GPIO range
1505 * Take a particular pin out of GPIO mode. If the pin is enabled for a
1506 * peripheral it will return to peripheral mode.
1508 static void tz1090_pinctrl_gpio_disable_free(struct pinctrl_dev
*pctldev
,
1509 struct pinctrl_gpio_range
*range
,
1512 struct tz1090_pmx
*pmx
= pinctrl_dev_get_drvdata(pctldev
);
1513 tz1090_pinctrl_gpio_select(pmx
, pin
, false);
1516 static struct pinmux_ops tz1090_pinmux_ops
= {
1517 .get_functions_count
= tz1090_pinctrl_get_funcs_count
,
1518 .get_function_name
= tz1090_pinctrl_get_func_name
,
1519 .get_function_groups
= tz1090_pinctrl_get_func_groups
,
1520 .set_mux
= tz1090_pinctrl_set_mux
,
1521 .gpio_request_enable
= tz1090_pinctrl_gpio_request_enable
,
1522 .gpio_disable_free
= tz1090_pinctrl_gpio_disable_free
,
1526 * Pin config operations
1529 struct tz1090_pinconf_pullup
{
1530 unsigned char index
;
1531 unsigned char shift
;
1534 /* The mapping of pin to pull up/down register index and shift */
1535 static struct tz1090_pinconf_pullup tz1090_pinconf_pullup
[] = {
1536 {5, 22}, /* 0 - TZ1090_PIN_SDIO_CLK */
1537 {0, 14}, /* 1 - TZ1090_PIN_SDIO_CMD */
1538 {0, 6}, /* 2 - TZ1090_PIN_SDIO_D0 */
1539 {0, 8}, /* 3 - TZ1090_PIN_SDIO_D1 */
1540 {0, 10}, /* 4 - TZ1090_PIN_SDIO_D2 */
1541 {0, 12}, /* 5 - TZ1090_PIN_SDIO_D3 */
1542 {0, 2}, /* 6 - TZ1090_PIN_SDH_CD */
1543 {0, 4}, /* 7 - TZ1090_PIN_SDH_WP */
1544 {0, 16}, /* 8 - TZ1090_PIN_SPI0_MCLK */
1545 {0, 18}, /* 9 - TZ1090_PIN_SPI0_CS0 */
1546 {0, 20}, /* 10 - TZ1090_PIN_SPI0_CS1 */
1547 {0, 22}, /* 11 - TZ1090_PIN_SPI0_CS2 */
1548 {0, 24}, /* 12 - TZ1090_PIN_SPI0_DOUT */
1549 {0, 26}, /* 13 - TZ1090_PIN_SPI0_DIN */
1550 {0, 28}, /* 14 - TZ1090_PIN_SPI1_MCLK */
1551 {0, 30}, /* 15 - TZ1090_PIN_SPI1_CS0 */
1552 {1, 0}, /* 16 - TZ1090_PIN_SPI1_CS1 */
1553 {1, 2}, /* 17 - TZ1090_PIN_SPI1_CS2 */
1554 {1, 4}, /* 18 - TZ1090_PIN_SPI1_DOUT */
1555 {1, 6}, /* 19 - TZ1090_PIN_SPI1_DIN */
1556 {1, 8}, /* 20 - TZ1090_PIN_UART0_RXD */
1557 {1, 10}, /* 21 - TZ1090_PIN_UART0_TXD */
1558 {1, 12}, /* 22 - TZ1090_PIN_UART0_CTS */
1559 {1, 14}, /* 23 - TZ1090_PIN_UART0_RTS */
1560 {1, 16}, /* 24 - TZ1090_PIN_UART1_RXD */
1561 {1, 18}, /* 25 - TZ1090_PIN_UART1_TXD */
1562 {1, 20}, /* 26 - TZ1090_PIN_SCB0_SDAT */
1563 {1, 22}, /* 27 - TZ1090_PIN_SCB0_SCLK */
1564 {1, 24}, /* 28 - TZ1090_PIN_SCB1_SDAT */
1565 {1, 26}, /* 29 - TZ1090_PIN_SCB1_SCLK */
1567 {1, 28}, /* 30 - TZ1090_PIN_SCB2_SDAT */
1568 {1, 30}, /* 31 - TZ1090_PIN_SCB2_SCLK */
1569 {2, 0}, /* 32 - TZ1090_PIN_I2S_MCLK */
1570 {2, 2}, /* 33 - TZ1090_PIN_I2S_BCLK_OUT */
1571 {2, 4}, /* 34 - TZ1090_PIN_I2S_LRCLK_OUT */
1572 {2, 6}, /* 35 - TZ1090_PIN_I2S_DOUT0 */
1573 {2, 8}, /* 36 - TZ1090_PIN_I2S_DOUT1 */
1574 {2, 10}, /* 37 - TZ1090_PIN_I2S_DOUT2 */
1575 {2, 12}, /* 38 - TZ1090_PIN_I2S_DIN */
1576 {4, 12}, /* 39 - TZ1090_PIN_PDM_A */
1577 {4, 14}, /* 40 - TZ1090_PIN_PDM_B */
1578 {4, 18}, /* 41 - TZ1090_PIN_PDM_C */
1579 {4, 20}, /* 42 - TZ1090_PIN_PDM_D */
1580 {2, 14}, /* 43 - TZ1090_PIN_TFT_RED0 */
1581 {2, 16}, /* 44 - TZ1090_PIN_TFT_RED1 */
1582 {2, 18}, /* 45 - TZ1090_PIN_TFT_RED2 */
1583 {2, 20}, /* 46 - TZ1090_PIN_TFT_RED3 */
1584 {2, 22}, /* 47 - TZ1090_PIN_TFT_RED4 */
1585 {2, 24}, /* 48 - TZ1090_PIN_TFT_RED5 */
1586 {2, 26}, /* 49 - TZ1090_PIN_TFT_RED6 */
1587 {2, 28}, /* 50 - TZ1090_PIN_TFT_RED7 */
1588 {2, 30}, /* 51 - TZ1090_PIN_TFT_GREEN0 */
1589 {3, 0}, /* 52 - TZ1090_PIN_TFT_GREEN1 */
1590 {3, 2}, /* 53 - TZ1090_PIN_TFT_GREEN2 */
1591 {3, 4}, /* 54 - TZ1090_PIN_TFT_GREEN3 */
1592 {3, 6}, /* 55 - TZ1090_PIN_TFT_GREEN4 */
1593 {3, 8}, /* 56 - TZ1090_PIN_TFT_GREEN5 */
1594 {3, 10}, /* 57 - TZ1090_PIN_TFT_GREEN6 */
1595 {3, 12}, /* 58 - TZ1090_PIN_TFT_GREEN7 */
1596 {3, 14}, /* 59 - TZ1090_PIN_TFT_BLUE0 */
1598 {3, 16}, /* 60 - TZ1090_PIN_TFT_BLUE1 */
1599 {3, 18}, /* 61 - TZ1090_PIN_TFT_BLUE2 */
1600 {3, 20}, /* 62 - TZ1090_PIN_TFT_BLUE3 */
1601 {3, 22}, /* 63 - TZ1090_PIN_TFT_BLUE4 */
1602 {3, 24}, /* 64 - TZ1090_PIN_TFT_BLUE5 */
1603 {3, 26}, /* 65 - TZ1090_PIN_TFT_BLUE6 */
1604 {3, 28}, /* 66 - TZ1090_PIN_TFT_BLUE7 */
1605 {3, 30}, /* 67 - TZ1090_PIN_TFT_VDDEN_GD */
1606 {4, 0}, /* 68 - TZ1090_PIN_TFT_PANELCLK */
1607 {4, 2}, /* 69 - TZ1090_PIN_TFT_BLANK_LS */
1608 {4, 4}, /* 70 - TZ1090_PIN_TFT_VSYNC_NS */
1609 {4, 6}, /* 71 - TZ1090_PIN_TFT_HSYNC_NR */
1610 {4, 8}, /* 72 - TZ1090_PIN_TFT_VD12ACB */
1611 {4, 10}, /* 73 - TZ1090_PIN_TFT_PWRSAVE */
1612 {4, 24}, /* 74 - TZ1090_PIN_TX_ON */
1613 {4, 26}, /* 75 - TZ1090_PIN_RX_ON */
1614 {4, 28}, /* 76 - TZ1090_PIN_PLL_ON */
1615 {4, 30}, /* 77 - TZ1090_PIN_PA_ON */
1616 {5, 0}, /* 78 - TZ1090_PIN_RX_HP */
1617 {5, 6}, /* 79 - TZ1090_PIN_GAIN0 */
1618 {5, 8}, /* 80 - TZ1090_PIN_GAIN1 */
1619 {5, 10}, /* 81 - TZ1090_PIN_GAIN2 */
1620 {5, 12}, /* 82 - TZ1090_PIN_GAIN3 */
1621 {5, 14}, /* 83 - TZ1090_PIN_GAIN4 */
1622 {5, 16}, /* 84 - TZ1090_PIN_GAIN5 */
1623 {5, 18}, /* 85 - TZ1090_PIN_GAIN6 */
1624 {5, 20}, /* 86 - TZ1090_PIN_GAIN7 */
1625 {5, 2}, /* 87 - TZ1090_PIN_ANT_SEL0 */
1626 {5, 4}, /* 88 - TZ1090_PIN_ANT_SEL1 */
1627 {0, 0}, /* 89 - TZ1090_PIN_SDH_CLK_IN */
1629 {5, 24}, /* 90 - TZ1090_PIN_TCK */
1630 {5, 26}, /* 91 - TZ1090_PIN_TRST */
1631 {5, 28}, /* 92 - TZ1090_PIN_TDI */
1632 {5, 30}, /* 93 - TZ1090_PIN_TDO */
1633 {6, 0}, /* 94 - TZ1090_PIN_TMS */
1634 {4, 16}, /* 95 - TZ1090_PIN_CLK_OUT0 */
1635 {4, 22}, /* 96 - TZ1090_PIN_CLK_OUT1 */
1638 static int tz1090_pinconf_reg(struct pinctrl_dev
*pctldev
,
1640 enum pin_config_param param
,
1642 u32
*reg
, u32
*width
, u32
*mask
, u32
*shift
,
1645 struct tz1090_pinconf_pullup
*pu
;
1647 /* All supported pins have controllable input bias */
1649 case PIN_CONFIG_BIAS_DISABLE
:
1650 case PIN_CONFIG_BIAS_HIGH_IMPEDANCE
:
1651 *val
= REG_PU_PD_TRISTATE
;
1653 case PIN_CONFIG_BIAS_PULL_UP
:
1654 *val
= REG_PU_PD_UP
;
1656 case PIN_CONFIG_BIAS_PULL_DOWN
:
1657 *val
= REG_PU_PD_DOWN
;
1659 case PIN_CONFIG_BIAS_BUS_HOLD
:
1660 *val
= REG_PU_PD_REPEATER
;
1666 /* Only input bias parameters supported */
1667 pu
= &tz1090_pinconf_pullup
[pin
];
1668 *reg
= REG_PINCTRL_PU_PD
+ 4*pu
->index
;
1672 /* Calculate field information */
1673 *mask
= (BIT(*width
) - 1) << *shift
;
1678 static int tz1090_pinconf_get(struct pinctrl_dev
*pctldev
,
1679 unsigned int pin
, unsigned long *config
)
1681 struct tz1090_pmx
*pmx
= pinctrl_dev_get_drvdata(pctldev
);
1682 enum pin_config_param param
= pinconf_to_config_param(*config
);
1684 u32 reg
, width
, mask
, shift
, val
, tmp
, arg
;
1686 /* Get register information */
1687 ret
= tz1090_pinconf_reg(pctldev
, pin
, param
, true,
1688 ®
, &width
, &mask
, &shift
, &val
);
1692 /* Extract field from register */
1693 tmp
= pmx_read(pmx
, reg
);
1694 arg
= ((tmp
& mask
) >> shift
) == val
;
1696 /* Config not active */
1700 /* And pack config */
1701 *config
= pinconf_to_config_packed(param
, arg
);
1706 static int tz1090_pinconf_set(struct pinctrl_dev
*pctldev
,
1707 unsigned int pin
, unsigned long *configs
,
1708 unsigned num_configs
)
1710 struct tz1090_pmx
*pmx
= pinctrl_dev_get_drvdata(pctldev
);
1711 enum pin_config_param param
;
1714 u32 reg
, width
, mask
, shift
, val
, tmp
;
1715 unsigned long flags
;
1718 for (i
= 0; i
< num_configs
; i
++) {
1719 param
= pinconf_to_config_param(configs
[i
]);
1720 arg
= pinconf_to_config_argument(configs
[i
]);
1722 dev_dbg(pctldev
->dev
, "%s(pin=%s, config=%#lx)\n",
1723 __func__
, tz1090_pins
[pin
].name
, configs
[i
]);
1725 /* Get register information */
1726 ret
= tz1090_pinconf_reg(pctldev
, pin
, param
, true,
1727 ®
, &width
, &mask
, &shift
, &val
);
1731 /* Unpack argument and range check it */
1733 dev_dbg(pctldev
->dev
, "%s: arg %u out of range\n",
1738 /* Write register field */
1739 __global_lock2(flags
);
1740 tmp
= pmx_read(pmx
, reg
);
1743 tmp
|= val
<< shift
;
1744 pmx_write(pmx
, tmp
, reg
);
1745 __global_unlock2(flags
);
1746 } /* for each config */
1751 static const int tz1090_boolean_map
[] = {
1756 static const int tz1090_dr_map
[] = {
1763 static int tz1090_pinconf_group_reg(struct pinctrl_dev
*pctldev
,
1764 const struct tz1090_pingroup
*g
,
1765 enum pin_config_param param
,
1767 u32
*reg
, u32
*width
, u32
*mask
, u32
*shift
,
1770 /* Drive configuration applies in groups, but not to all groups. */
1773 dev_dbg(pctldev
->dev
,
1774 "%s: group %s has no drive control\n",
1779 /* Find information about drive parameter's register */
1781 case PIN_CONFIG_INPUT_SCHMITT_ENABLE
:
1782 *reg
= REG_PINCTRL_SCHMITT
;
1784 *map
= tz1090_boolean_map
;
1786 case PIN_CONFIG_DRIVE_STRENGTH
:
1787 *reg
= REG_PINCTRL_DR
;
1789 *map
= tz1090_dr_map
;
1795 /* Calculate field information */
1796 *shift
= g
->slw_bit
* *width
;
1797 *mask
= (BIT(*width
) - 1) << *shift
;
1802 static int tz1090_pinconf_group_get(struct pinctrl_dev
*pctldev
,
1804 unsigned long *config
)
1806 struct tz1090_pmx
*pmx
= pinctrl_dev_get_drvdata(pctldev
);
1807 const struct tz1090_pingroup
*g
;
1808 enum pin_config_param param
= pinconf_to_config_param(*config
);
1811 u32 reg
, width
, mask
, shift
, val
;
1814 if (group
>= ARRAY_SIZE(tz1090_groups
)) {
1815 pin
= group
- ARRAY_SIZE(tz1090_groups
);
1816 return tz1090_pinconf_get(pctldev
, pin
, config
);
1819 g
= &tz1090_groups
[group
];
1820 if (g
->npins
== 1) {
1822 ret
= tz1090_pinconf_get(pctldev
, pin
, config
);
1823 if (ret
!= -ENOTSUPP
)
1827 /* Get register information */
1828 ret
= tz1090_pinconf_group_reg(pctldev
, g
, param
, true,
1829 ®
, &width
, &mask
, &shift
, &map
);
1833 /* Extract field from register */
1834 val
= pmx_read(pmx
, reg
);
1835 arg
= map
[(val
& mask
) >> shift
];
1839 /* And pack config */
1840 *config
= pinconf_to_config_packed(param
, arg
);
1845 static int tz1090_pinconf_group_set(struct pinctrl_dev
*pctldev
,
1846 unsigned int group
, unsigned long *configs
,
1847 unsigned num_configs
)
1849 struct tz1090_pmx
*pmx
= pinctrl_dev_get_drvdata(pctldev
);
1850 const struct tz1090_pingroup
*g
;
1851 enum pin_config_param param
;
1852 unsigned int arg
, pin
, i
;
1853 const unsigned int *pit
;
1855 u32 reg
, width
, mask
, shift
, val
;
1856 unsigned long flags
;
1860 if (group
>= ARRAY_SIZE(tz1090_groups
)) {
1861 pin
= group
- ARRAY_SIZE(tz1090_groups
);
1862 return tz1090_pinconf_set(pctldev
, pin
, configs
, num_configs
);
1865 g
= &tz1090_groups
[group
];
1866 if (g
->npins
== 1) {
1868 ret
= tz1090_pinconf_set(pctldev
, pin
, configs
, num_configs
);
1869 if (ret
!= -ENOTSUPP
)
1873 for (j
= 0; j
< num_configs
; j
++) {
1874 param
= pinconf_to_config_param(configs
[j
]);
1876 dev_dbg(pctldev
->dev
, "%s(group=%s, config=%#lx)\n",
1877 __func__
, g
->name
, configs
[j
]);
1879 /* Get register information */
1880 ret
= tz1090_pinconf_group_reg(pctldev
, g
, param
, true, ®
,
1881 &width
, &mask
, &shift
, &map
);
1884 * Maybe we're trying to set a per-pin configuration
1885 * of a group, so do the pins one by one. This is
1886 * mainly as a convenience.
1888 for (i
= 0, pit
= g
->pins
; i
< g
->npins
; ++i
, ++pit
) {
1889 ret
= tz1090_pinconf_set(pctldev
, *pit
, configs
,
1897 /* Unpack argument and map it to register value */
1898 arg
= pinconf_to_config_argument(configs
[j
]);
1899 for (i
= 0; i
< BIT(width
); ++i
) {
1900 if (map
[i
] == arg
|| (map
[i
] == -EINVAL
&& !arg
)) {
1901 /* Write register field */
1902 __global_lock2(flags
);
1903 val
= pmx_read(pmx
, reg
);
1906 pmx_write(pmx
, val
, reg
);
1907 __global_unlock2(flags
);
1912 dev_dbg(pctldev
->dev
, "%s: arg %u not supported\n",
1918 } /* for each config */
1923 static struct pinconf_ops tz1090_pinconf_ops
= {
1925 .pin_config_get
= tz1090_pinconf_get
,
1926 .pin_config_set
= tz1090_pinconf_set
,
1927 .pin_config_group_get
= tz1090_pinconf_group_get
,
1928 .pin_config_group_set
= tz1090_pinconf_group_set
,
1929 .pin_config_config_dbg_show
= pinconf_generic_dump_config
,
1933 * Pin control driver setup
1936 static struct pinctrl_desc tz1090_pinctrl_desc
= {
1937 .pctlops
= &tz1090_pinctrl_ops
,
1938 .pmxops
= &tz1090_pinmux_ops
,
1939 .confops
= &tz1090_pinconf_ops
,
1940 .owner
= THIS_MODULE
,
1943 static int tz1090_pinctrl_probe(struct platform_device
*pdev
)
1945 struct tz1090_pmx
*pmx
;
1946 struct resource
*res
;
1948 pmx
= devm_kzalloc(&pdev
->dev
, sizeof(*pmx
), GFP_KERNEL
);
1950 dev_err(&pdev
->dev
, "Can't alloc tz1090_pmx\n");
1953 pmx
->dev
= &pdev
->dev
;
1954 spin_lock_init(&pmx
->lock
);
1956 tz1090_pinctrl_desc
.name
= dev_name(&pdev
->dev
);
1957 tz1090_pinctrl_desc
.pins
= tz1090_pins
;
1958 tz1090_pinctrl_desc
.npins
= ARRAY_SIZE(tz1090_pins
);
1960 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
1961 pmx
->regs
= devm_ioremap_resource(&pdev
->dev
, res
);
1962 if (IS_ERR(pmx
->regs
))
1963 return PTR_ERR(pmx
->regs
);
1965 pmx
->pctl
= devm_pinctrl_register(&pdev
->dev
, &tz1090_pinctrl_desc
,
1967 if (IS_ERR(pmx
->pctl
)) {
1968 dev_err(&pdev
->dev
, "Couldn't register pinctrl driver\n");
1969 return PTR_ERR(pmx
->pctl
);
1972 platform_set_drvdata(pdev
, pmx
);
1974 dev_info(&pdev
->dev
, "TZ1090 pinctrl driver initialised\n");
1979 static const struct of_device_id tz1090_pinctrl_of_match
[] = {
1980 { .compatible
= "img,tz1090-pinctrl", },
1984 static struct platform_driver tz1090_pinctrl_driver
= {
1986 .name
= "tz1090-pinctrl",
1987 .of_match_table
= tz1090_pinctrl_of_match
,
1989 .probe
= tz1090_pinctrl_probe
,
1992 static int __init
tz1090_pinctrl_init(void)
1994 tz1090_init_mux_pins();
1995 return platform_driver_register(&tz1090_pinctrl_driver
);
1997 arch_initcall(tz1090_pinctrl_init
);
1999 static void __exit
tz1090_pinctrl_exit(void)
2001 platform_driver_unregister(&tz1090_pinctrl_driver
);
2003 module_exit(tz1090_pinctrl_exit
);
2005 MODULE_AUTHOR("Imagination Technologies Ltd.");
2006 MODULE_DESCRIPTION("Toumaz Xenif TZ1090 pinctrl driver");
2007 MODULE_LICENSE("GPL v2");
2008 MODULE_DEVICE_TABLE(of
, tz1090_pinctrl_of_match
);