xref: /linux/drivers/pinctrl/cirrus/pinctrl-lochnagar.c (revision 0ea5c948cb64bab5bc7a5516774eb8536f05aa0d)
10548448bSCharles Keepax // SPDX-License-Identifier: GPL-2.0
20548448bSCharles Keepax /*
30548448bSCharles Keepax  * Lochnagar pin and GPIO control
40548448bSCharles Keepax  *
50548448bSCharles Keepax  * Copyright (c) 2017-2018 Cirrus Logic, Inc. and
60548448bSCharles Keepax  *                         Cirrus Logic International Semiconductor Ltd.
70548448bSCharles Keepax  *
80548448bSCharles Keepax  * Author: Charles Keepax <ckeepax@opensource.cirrus.com>
90548448bSCharles Keepax  */
100548448bSCharles Keepax 
110548448bSCharles Keepax #include <linux/err.h>
120548448bSCharles Keepax #include <linux/errno.h>
130548448bSCharles Keepax #include <linux/gpio/driver.h>
140548448bSCharles Keepax #include <linux/module.h>
150548448bSCharles Keepax #include <linux/of.h>
160548448bSCharles Keepax #include <linux/platform_device.h>
170548448bSCharles Keepax #include <linux/regmap.h>
18b2fd05c7SAndy Shevchenko 
19b2fd05c7SAndy Shevchenko #include <linux/pinctrl/consumer.h>
20b2fd05c7SAndy Shevchenko #include <linux/pinctrl/pinconf-generic.h>
21b2fd05c7SAndy Shevchenko #include <linux/pinctrl/pinconf.h>
220548448bSCharles Keepax #include <linux/pinctrl/pinctrl.h>
230548448bSCharles Keepax #include <linux/pinctrl/pinmux.h>
240548448bSCharles Keepax 
250548448bSCharles Keepax #include <linux/mfd/lochnagar.h>
260548448bSCharles Keepax #include <linux/mfd/lochnagar1_regs.h>
270548448bSCharles Keepax #include <linux/mfd/lochnagar2_regs.h>
280548448bSCharles Keepax 
290548448bSCharles Keepax #include <dt-bindings/pinctrl/lochnagar.h>
300548448bSCharles Keepax 
310548448bSCharles Keepax #include "../pinctrl-utils.h"
320548448bSCharles Keepax 
330548448bSCharles Keepax #define LN2_NUM_GPIO_CHANNELS	16
340548448bSCharles Keepax 
350548448bSCharles Keepax #define LN_CDC_AIF1_STR		"codec-aif1"
360548448bSCharles Keepax #define LN_CDC_AIF2_STR		"codec-aif2"
370548448bSCharles Keepax #define LN_CDC_AIF3_STR		"codec-aif3"
380548448bSCharles Keepax #define LN_DSP_AIF1_STR		"dsp-aif1"
390548448bSCharles Keepax #define LN_DSP_AIF2_STR		"dsp-aif2"
400548448bSCharles Keepax #define LN_PSIA1_STR		"psia1"
410548448bSCharles Keepax #define LN_PSIA2_STR		"psia2"
420548448bSCharles Keepax #define LN_GF_AIF1_STR		"gf-aif1"
430548448bSCharles Keepax #define LN_GF_AIF2_STR		"gf-aif2"
440548448bSCharles Keepax #define LN_GF_AIF3_STR		"gf-aif3"
450548448bSCharles Keepax #define LN_GF_AIF4_STR		"gf-aif4"
460548448bSCharles Keepax #define LN_SPDIF_AIF_STR	"spdif-aif"
470548448bSCharles Keepax #define LN_USB_AIF1_STR		"usb-aif1"
480548448bSCharles Keepax #define LN_USB_AIF2_STR		"usb-aif2"
490548448bSCharles Keepax #define LN_ADAT_AIF_STR		"adat-aif"
500548448bSCharles Keepax #define LN_SOUNDCARD_AIF_STR	"soundcard-aif"
510548448bSCharles Keepax 
520548448bSCharles Keepax #define LN_PIN_GPIO(REV, ID, NAME, REG, SHIFT, INVERT) \
530548448bSCharles Keepax static const struct lochnagar_pin lochnagar##REV##_##ID##_pin = { \
540548448bSCharles Keepax 	.name = NAME, .type = LN_PTYPE_GPIO, .reg = LOCHNAGAR##REV##_##REG, \
550548448bSCharles Keepax 	.shift = LOCHNAGAR##REV##_##SHIFT##_SHIFT, .invert = INVERT, \
560548448bSCharles Keepax }
570548448bSCharles Keepax 
580548448bSCharles Keepax #define LN_PIN_SAIF(REV, ID, NAME) \
590548448bSCharles Keepax static const struct lochnagar_pin lochnagar##REV##_##ID##_pin = \
600548448bSCharles Keepax 	{ .name = NAME, .type = LN_PTYPE_AIF, }
610548448bSCharles Keepax 
620548448bSCharles Keepax #define LN_PIN_AIF(REV, ID) \
630548448bSCharles Keepax 	LN_PIN_SAIF(REV, ID##_BCLK,  LN_##ID##_STR"-bclk"); \
640548448bSCharles Keepax 	LN_PIN_SAIF(REV, ID##_LRCLK, LN_##ID##_STR"-lrclk"); \
650548448bSCharles Keepax 	LN_PIN_SAIF(REV, ID##_RXDAT, LN_##ID##_STR"-rxdat"); \
660548448bSCharles Keepax 	LN_PIN_SAIF(REV, ID##_TXDAT, LN_##ID##_STR"-txdat")
670548448bSCharles Keepax 
680548448bSCharles Keepax #define LN1_PIN_GPIO(ID, NAME, REG, SHIFT, INVERT) \
690548448bSCharles Keepax 	LN_PIN_GPIO(1, ID, NAME, REG, SHIFT, INVERT)
700548448bSCharles Keepax 
710548448bSCharles Keepax #define LN1_PIN_MUX(ID, NAME) \
720548448bSCharles Keepax static const struct lochnagar_pin lochnagar1_##ID##_pin = \
730548448bSCharles Keepax 	{ .name = NAME, .type = LN_PTYPE_MUX, .reg = LOCHNAGAR1_##ID, }
740548448bSCharles Keepax 
750548448bSCharles Keepax #define LN1_PIN_AIF(ID) LN_PIN_AIF(1, ID)
760548448bSCharles Keepax 
770548448bSCharles Keepax #define LN2_PIN_GPIO(ID, NAME, REG, SHIFT, INVERT) \
780548448bSCharles Keepax 	LN_PIN_GPIO(2, ID, NAME, REG, SHIFT, INVERT)
790548448bSCharles Keepax 
800548448bSCharles Keepax #define LN2_PIN_MUX(ID, NAME) \
810548448bSCharles Keepax static const struct lochnagar_pin lochnagar2_##ID##_pin = \
820548448bSCharles Keepax 	{ .name = NAME, .type = LN_PTYPE_MUX, .reg = LOCHNAGAR2_GPIO_##ID, }
830548448bSCharles Keepax 
840548448bSCharles Keepax #define LN2_PIN_AIF(ID) LN_PIN_AIF(2, ID)
850548448bSCharles Keepax 
860548448bSCharles Keepax #define LN2_PIN_GAI(ID) \
870548448bSCharles Keepax 	LN2_PIN_MUX(ID##_BCLK,  LN_##ID##_STR"-bclk"); \
880548448bSCharles Keepax 	LN2_PIN_MUX(ID##_LRCLK, LN_##ID##_STR"-lrclk"); \
890548448bSCharles Keepax 	LN2_PIN_MUX(ID##_RXDAT, LN_##ID##_STR"-rxdat"); \
900548448bSCharles Keepax 	LN2_PIN_MUX(ID##_TXDAT, LN_##ID##_STR"-txdat")
910548448bSCharles Keepax 
920548448bSCharles Keepax #define LN_PIN(REV, ID) [LOCHNAGAR##REV##_PIN_##ID] = { \
930548448bSCharles Keepax 	.number = LOCHNAGAR##REV##_PIN_##ID, \
940548448bSCharles Keepax 	.name = lochnagar##REV##_##ID##_pin.name, \
950548448bSCharles Keepax 	.drv_data = (void *)&lochnagar##REV##_##ID##_pin, \
960548448bSCharles Keepax }
970548448bSCharles Keepax 
980548448bSCharles Keepax #define LN1_PIN(ID) LN_PIN(1, ID)
990548448bSCharles Keepax #define LN2_PIN(ID) LN_PIN(2, ID)
1000548448bSCharles Keepax 
1010548448bSCharles Keepax #define LN_PINS(REV, ID) \
1020548448bSCharles Keepax 	LN_PIN(REV, ID##_BCLK), LN_PIN(REV, ID##_LRCLK), \
1030548448bSCharles Keepax 	LN_PIN(REV, ID##_RXDAT), LN_PIN(REV, ID##_TXDAT)
1040548448bSCharles Keepax 
1050548448bSCharles Keepax #define LN1_PINS(ID) LN_PINS(1, ID)
1060548448bSCharles Keepax #define LN2_PINS(ID) LN_PINS(2, ID)
1070548448bSCharles Keepax 
1080548448bSCharles Keepax enum {
1090548448bSCharles Keepax 	LOCHNAGAR1_PIN_GF_GPIO2 = LOCHNAGAR1_PIN_NUM_GPIOS,
1100548448bSCharles Keepax 	LOCHNAGAR1_PIN_GF_GPIO3,
1110548448bSCharles Keepax 	LOCHNAGAR1_PIN_GF_GPIO7,
1120548448bSCharles Keepax 	LOCHNAGAR1_PIN_LED1,
1130548448bSCharles Keepax 	LOCHNAGAR1_PIN_LED2,
1140548448bSCharles Keepax 	LOCHNAGAR1_PIN_CDC_AIF1_BCLK,
1150548448bSCharles Keepax 	LOCHNAGAR1_PIN_CDC_AIF1_LRCLK,
1160548448bSCharles Keepax 	LOCHNAGAR1_PIN_CDC_AIF1_RXDAT,
1170548448bSCharles Keepax 	LOCHNAGAR1_PIN_CDC_AIF1_TXDAT,
1180548448bSCharles Keepax 	LOCHNAGAR1_PIN_CDC_AIF2_BCLK,
1190548448bSCharles Keepax 	LOCHNAGAR1_PIN_CDC_AIF2_LRCLK,
1200548448bSCharles Keepax 	LOCHNAGAR1_PIN_CDC_AIF2_RXDAT,
1210548448bSCharles Keepax 	LOCHNAGAR1_PIN_CDC_AIF2_TXDAT,
1220548448bSCharles Keepax 	LOCHNAGAR1_PIN_CDC_AIF3_BCLK,
1230548448bSCharles Keepax 	LOCHNAGAR1_PIN_CDC_AIF3_LRCLK,
1240548448bSCharles Keepax 	LOCHNAGAR1_PIN_CDC_AIF3_RXDAT,
1250548448bSCharles Keepax 	LOCHNAGAR1_PIN_CDC_AIF3_TXDAT,
1260548448bSCharles Keepax 	LOCHNAGAR1_PIN_DSP_AIF1_BCLK,
1270548448bSCharles Keepax 	LOCHNAGAR1_PIN_DSP_AIF1_LRCLK,
1280548448bSCharles Keepax 	LOCHNAGAR1_PIN_DSP_AIF1_RXDAT,
1290548448bSCharles Keepax 	LOCHNAGAR1_PIN_DSP_AIF1_TXDAT,
1300548448bSCharles Keepax 	LOCHNAGAR1_PIN_DSP_AIF2_BCLK,
1310548448bSCharles Keepax 	LOCHNAGAR1_PIN_DSP_AIF2_LRCLK,
1320548448bSCharles Keepax 	LOCHNAGAR1_PIN_DSP_AIF2_RXDAT,
1330548448bSCharles Keepax 	LOCHNAGAR1_PIN_DSP_AIF2_TXDAT,
1340548448bSCharles Keepax 	LOCHNAGAR1_PIN_PSIA1_BCLK,
1350548448bSCharles Keepax 	LOCHNAGAR1_PIN_PSIA1_LRCLK,
1360548448bSCharles Keepax 	LOCHNAGAR1_PIN_PSIA1_RXDAT,
1370548448bSCharles Keepax 	LOCHNAGAR1_PIN_PSIA1_TXDAT,
1380548448bSCharles Keepax 	LOCHNAGAR1_PIN_PSIA2_BCLK,
1390548448bSCharles Keepax 	LOCHNAGAR1_PIN_PSIA2_LRCLK,
1400548448bSCharles Keepax 	LOCHNAGAR1_PIN_PSIA2_RXDAT,
1410548448bSCharles Keepax 	LOCHNAGAR1_PIN_PSIA2_TXDAT,
1420548448bSCharles Keepax 	LOCHNAGAR1_PIN_SPDIF_AIF_BCLK,
1430548448bSCharles Keepax 	LOCHNAGAR1_PIN_SPDIF_AIF_LRCLK,
1440548448bSCharles Keepax 	LOCHNAGAR1_PIN_SPDIF_AIF_RXDAT,
1450548448bSCharles Keepax 	LOCHNAGAR1_PIN_SPDIF_AIF_TXDAT,
1460548448bSCharles Keepax 	LOCHNAGAR1_PIN_GF_AIF3_BCLK,
1470548448bSCharles Keepax 	LOCHNAGAR1_PIN_GF_AIF3_RXDAT,
1480548448bSCharles Keepax 	LOCHNAGAR1_PIN_GF_AIF3_LRCLK,
1490548448bSCharles Keepax 	LOCHNAGAR1_PIN_GF_AIF3_TXDAT,
1500548448bSCharles Keepax 	LOCHNAGAR1_PIN_GF_AIF4_BCLK,
1510548448bSCharles Keepax 	LOCHNAGAR1_PIN_GF_AIF4_RXDAT,
1520548448bSCharles Keepax 	LOCHNAGAR1_PIN_GF_AIF4_LRCLK,
1530548448bSCharles Keepax 	LOCHNAGAR1_PIN_GF_AIF4_TXDAT,
1540548448bSCharles Keepax 	LOCHNAGAR1_PIN_GF_AIF1_BCLK,
1550548448bSCharles Keepax 	LOCHNAGAR1_PIN_GF_AIF1_RXDAT,
1560548448bSCharles Keepax 	LOCHNAGAR1_PIN_GF_AIF1_LRCLK,
1570548448bSCharles Keepax 	LOCHNAGAR1_PIN_GF_AIF1_TXDAT,
1580548448bSCharles Keepax 	LOCHNAGAR1_PIN_GF_AIF2_BCLK,
1590548448bSCharles Keepax 	LOCHNAGAR1_PIN_GF_AIF2_RXDAT,
1600548448bSCharles Keepax 	LOCHNAGAR1_PIN_GF_AIF2_LRCLK,
1610548448bSCharles Keepax 	LOCHNAGAR1_PIN_GF_AIF2_TXDAT,
1620548448bSCharles Keepax 
1630548448bSCharles Keepax 	LOCHNAGAR2_PIN_SPDIF_AIF_BCLK = LOCHNAGAR2_PIN_NUM_GPIOS,
1640548448bSCharles Keepax 	LOCHNAGAR2_PIN_SPDIF_AIF_LRCLK,
1650548448bSCharles Keepax 	LOCHNAGAR2_PIN_SPDIF_AIF_RXDAT,
1660548448bSCharles Keepax 	LOCHNAGAR2_PIN_SPDIF_AIF_TXDAT,
1670548448bSCharles Keepax 	LOCHNAGAR2_PIN_USB_AIF1_BCLK,
1680548448bSCharles Keepax 	LOCHNAGAR2_PIN_USB_AIF1_LRCLK,
1690548448bSCharles Keepax 	LOCHNAGAR2_PIN_USB_AIF1_RXDAT,
1700548448bSCharles Keepax 	LOCHNAGAR2_PIN_USB_AIF1_TXDAT,
1710548448bSCharles Keepax 	LOCHNAGAR2_PIN_USB_AIF2_BCLK,
1720548448bSCharles Keepax 	LOCHNAGAR2_PIN_USB_AIF2_LRCLK,
1730548448bSCharles Keepax 	LOCHNAGAR2_PIN_USB_AIF2_RXDAT,
1740548448bSCharles Keepax 	LOCHNAGAR2_PIN_USB_AIF2_TXDAT,
1750548448bSCharles Keepax 	LOCHNAGAR2_PIN_ADAT_AIF_BCLK,
1760548448bSCharles Keepax 	LOCHNAGAR2_PIN_ADAT_AIF_LRCLK,
1770548448bSCharles Keepax 	LOCHNAGAR2_PIN_ADAT_AIF_RXDAT,
1780548448bSCharles Keepax 	LOCHNAGAR2_PIN_ADAT_AIF_TXDAT,
1790548448bSCharles Keepax 	LOCHNAGAR2_PIN_SOUNDCARD_AIF_BCLK,
1800548448bSCharles Keepax 	LOCHNAGAR2_PIN_SOUNDCARD_AIF_LRCLK,
1810548448bSCharles Keepax 	LOCHNAGAR2_PIN_SOUNDCARD_AIF_RXDAT,
1820548448bSCharles Keepax 	LOCHNAGAR2_PIN_SOUNDCARD_AIF_TXDAT,
1830548448bSCharles Keepax };
1840548448bSCharles Keepax 
1850548448bSCharles Keepax enum lochnagar_pin_type {
1860548448bSCharles Keepax 	LN_PTYPE_GPIO,
1870548448bSCharles Keepax 	LN_PTYPE_MUX,
1880548448bSCharles Keepax 	LN_PTYPE_AIF,
1890548448bSCharles Keepax 	LN_PTYPE_COUNT,
1900548448bSCharles Keepax };
1910548448bSCharles Keepax 
1920548448bSCharles Keepax struct lochnagar_pin {
1930548448bSCharles Keepax 	const char name[20];
1940548448bSCharles Keepax 
1950548448bSCharles Keepax 	enum lochnagar_pin_type type;
1960548448bSCharles Keepax 
1970548448bSCharles Keepax 	unsigned int reg;
1980548448bSCharles Keepax 	int shift;
1990548448bSCharles Keepax 	bool invert;
2000548448bSCharles Keepax };
2010548448bSCharles Keepax 
2020548448bSCharles Keepax LN1_PIN_GPIO(CDC_RESET,    "codec-reset",    RST,      CDC_RESET,    1);
2030548448bSCharles Keepax LN1_PIN_GPIO(DSP_RESET,    "dsp-reset",      RST,      DSP_RESET,    1);
2040548448bSCharles Keepax LN1_PIN_GPIO(CDC_CIF1MODE, "codec-cif1mode", I2C_CTRL, CDC_CIF_MODE, 0);
2050548448bSCharles Keepax LN1_PIN_MUX(GF_GPIO2,      "gf-gpio2");
2060548448bSCharles Keepax LN1_PIN_MUX(GF_GPIO3,      "gf-gpio3");
2070548448bSCharles Keepax LN1_PIN_MUX(GF_GPIO7,      "gf-gpio7");
2080548448bSCharles Keepax LN1_PIN_MUX(LED1,          "led1");
2090548448bSCharles Keepax LN1_PIN_MUX(LED2,          "led2");
2100548448bSCharles Keepax LN1_PIN_AIF(CDC_AIF1);
2110548448bSCharles Keepax LN1_PIN_AIF(CDC_AIF2);
2120548448bSCharles Keepax LN1_PIN_AIF(CDC_AIF3);
2130548448bSCharles Keepax LN1_PIN_AIF(DSP_AIF1);
2140548448bSCharles Keepax LN1_PIN_AIF(DSP_AIF2);
2150548448bSCharles Keepax LN1_PIN_AIF(PSIA1);
2160548448bSCharles Keepax LN1_PIN_AIF(PSIA2);
2170548448bSCharles Keepax LN1_PIN_AIF(SPDIF_AIF);
2180548448bSCharles Keepax LN1_PIN_AIF(GF_AIF1);
2190548448bSCharles Keepax LN1_PIN_AIF(GF_AIF2);
2200548448bSCharles Keepax LN1_PIN_AIF(GF_AIF3);
2210548448bSCharles Keepax LN1_PIN_AIF(GF_AIF4);
2220548448bSCharles Keepax 
2230548448bSCharles Keepax LN2_PIN_GPIO(CDC_RESET,    "codec-reset",    MINICARD_RESETS, CDC_RESET,     1);
2240548448bSCharles Keepax LN2_PIN_GPIO(DSP_RESET,    "dsp-reset",      MINICARD_RESETS, DSP_RESET,     1);
2250548448bSCharles Keepax LN2_PIN_GPIO(CDC_CIF1MODE, "codec-cif1mode", COMMS_CTRL4,     CDC_CIF1MODE,  0);
2260548448bSCharles Keepax LN2_PIN_GPIO(CDC_LDOENA,   "codec-ldoena",   POWER_CTRL,      PWR_ENA,       0);
2270548448bSCharles Keepax LN2_PIN_GPIO(SPDIF_HWMODE, "spdif-hwmode",   SPDIF_CTRL,      SPDIF_HWMODE,  0);
2280548448bSCharles Keepax LN2_PIN_GPIO(SPDIF_RESET,  "spdif-reset",    SPDIF_CTRL,      SPDIF_RESET,   1);
2290548448bSCharles Keepax LN2_PIN_MUX(FPGA_GPIO1,    "fpga-gpio1");
2300548448bSCharles Keepax LN2_PIN_MUX(FPGA_GPIO2,    "fpga-gpio2");
2310548448bSCharles Keepax LN2_PIN_MUX(FPGA_GPIO3,    "fpga-gpio3");
2320548448bSCharles Keepax LN2_PIN_MUX(FPGA_GPIO4,    "fpga-gpio4");
2330548448bSCharles Keepax LN2_PIN_MUX(FPGA_GPIO5,    "fpga-gpio5");
2340548448bSCharles Keepax LN2_PIN_MUX(FPGA_GPIO6,    "fpga-gpio6");
2350548448bSCharles Keepax LN2_PIN_MUX(CDC_GPIO1,     "codec-gpio1");
2360548448bSCharles Keepax LN2_PIN_MUX(CDC_GPIO2,     "codec-gpio2");
2370548448bSCharles Keepax LN2_PIN_MUX(CDC_GPIO3,     "codec-gpio3");
2380548448bSCharles Keepax LN2_PIN_MUX(CDC_GPIO4,     "codec-gpio4");
2390548448bSCharles Keepax LN2_PIN_MUX(CDC_GPIO5,     "codec-gpio5");
2400548448bSCharles Keepax LN2_PIN_MUX(CDC_GPIO6,     "codec-gpio6");
2410548448bSCharles Keepax LN2_PIN_MUX(CDC_GPIO7,     "codec-gpio7");
2420548448bSCharles Keepax LN2_PIN_MUX(CDC_GPIO8,     "codec-gpio8");
2430548448bSCharles Keepax LN2_PIN_MUX(DSP_GPIO1,     "dsp-gpio1");
2440548448bSCharles Keepax LN2_PIN_MUX(DSP_GPIO2,     "dsp-gpio2");
2450548448bSCharles Keepax LN2_PIN_MUX(DSP_GPIO3,     "dsp-gpio3");
2460548448bSCharles Keepax LN2_PIN_MUX(DSP_GPIO4,     "dsp-gpio4");
2470548448bSCharles Keepax LN2_PIN_MUX(DSP_GPIO5,     "dsp-gpio5");
2480548448bSCharles Keepax LN2_PIN_MUX(DSP_GPIO6,     "dsp-gpio6");
2490548448bSCharles Keepax LN2_PIN_MUX(GF_GPIO2,      "gf-gpio2");
2500548448bSCharles Keepax LN2_PIN_MUX(GF_GPIO3,      "gf-gpio3");
2510548448bSCharles Keepax LN2_PIN_MUX(GF_GPIO7,      "gf-gpio7");
2520548448bSCharles Keepax LN2_PIN_MUX(DSP_UART1_RX,  "dsp-uart1-rx");
2530548448bSCharles Keepax LN2_PIN_MUX(DSP_UART1_TX,  "dsp-uart1-tx");
2540548448bSCharles Keepax LN2_PIN_MUX(DSP_UART2_RX,  "dsp-uart2-rx");
2550548448bSCharles Keepax LN2_PIN_MUX(DSP_UART2_TX,  "dsp-uart2-tx");
2560548448bSCharles Keepax LN2_PIN_MUX(GF_UART2_RX,   "gf-uart2-rx");
2570548448bSCharles Keepax LN2_PIN_MUX(GF_UART2_TX,   "gf-uart2-tx");
2580548448bSCharles Keepax LN2_PIN_MUX(USB_UART_RX,   "usb-uart-rx");
2590548448bSCharles Keepax LN2_PIN_MUX(CDC_PDMCLK1,   "codec-pdmclk1");
2600548448bSCharles Keepax LN2_PIN_MUX(CDC_PDMDAT1,   "codec-pdmdat1");
2610548448bSCharles Keepax LN2_PIN_MUX(CDC_PDMCLK2,   "codec-pdmclk2");
2620548448bSCharles Keepax LN2_PIN_MUX(CDC_PDMDAT2,   "codec-pdmdat2");
2630548448bSCharles Keepax LN2_PIN_MUX(CDC_DMICCLK1,  "codec-dmicclk1");
2640548448bSCharles Keepax LN2_PIN_MUX(CDC_DMICDAT1,  "codec-dmicdat1");
2650548448bSCharles Keepax LN2_PIN_MUX(CDC_DMICCLK2,  "codec-dmicclk2");
2660548448bSCharles Keepax LN2_PIN_MUX(CDC_DMICDAT2,  "codec-dmicdat2");
2670548448bSCharles Keepax LN2_PIN_MUX(CDC_DMICCLK3,  "codec-dmicclk3");
2680548448bSCharles Keepax LN2_PIN_MUX(CDC_DMICDAT3,  "codec-dmicdat3");
2690548448bSCharles Keepax LN2_PIN_MUX(CDC_DMICCLK4,  "codec-dmicclk4");
2700548448bSCharles Keepax LN2_PIN_MUX(CDC_DMICDAT4,  "codec-dmicdat4");
2710548448bSCharles Keepax LN2_PIN_MUX(DSP_DMICCLK1,  "dsp-dmicclk1");
2720548448bSCharles Keepax LN2_PIN_MUX(DSP_DMICDAT1,  "dsp-dmicdat1");
2730548448bSCharles Keepax LN2_PIN_MUX(DSP_DMICCLK2,  "dsp-dmicclk2");
2740548448bSCharles Keepax LN2_PIN_MUX(DSP_DMICDAT2,  "dsp-dmicdat2");
2750548448bSCharles Keepax LN2_PIN_MUX(I2C2_SCL,      "i2c2-scl");
2760548448bSCharles Keepax LN2_PIN_MUX(I2C2_SDA,      "i2c2-sda");
2770548448bSCharles Keepax LN2_PIN_MUX(I2C3_SCL,      "i2c3-scl");
2780548448bSCharles Keepax LN2_PIN_MUX(I2C3_SDA,      "i2c3-sda");
2790548448bSCharles Keepax LN2_PIN_MUX(I2C4_SCL,      "i2c4-scl");
2800548448bSCharles Keepax LN2_PIN_MUX(I2C4_SDA,      "i2c4-sda");
2810548448bSCharles Keepax LN2_PIN_MUX(DSP_STANDBY,   "dsp-standby");
2820548448bSCharles Keepax LN2_PIN_MUX(CDC_MCLK1,     "codec-mclk1");
2830548448bSCharles Keepax LN2_PIN_MUX(CDC_MCLK2,     "codec-mclk2");
2840548448bSCharles Keepax LN2_PIN_MUX(DSP_CLKIN,     "dsp-clkin");
2850548448bSCharles Keepax LN2_PIN_MUX(PSIA1_MCLK,    "psia1-mclk");
2860548448bSCharles Keepax LN2_PIN_MUX(PSIA2_MCLK,    "psia2-mclk");
2870548448bSCharles Keepax LN2_PIN_MUX(GF_GPIO1,      "gf-gpio1");
2880548448bSCharles Keepax LN2_PIN_MUX(GF_GPIO5,      "gf-gpio5");
2890548448bSCharles Keepax LN2_PIN_MUX(DSP_GPIO20,    "dsp-gpio20");
2900548448bSCharles Keepax LN2_PIN_GAI(CDC_AIF1);
2910548448bSCharles Keepax LN2_PIN_GAI(CDC_AIF2);
2920548448bSCharles Keepax LN2_PIN_GAI(CDC_AIF3);
2930548448bSCharles Keepax LN2_PIN_GAI(DSP_AIF1);
2940548448bSCharles Keepax LN2_PIN_GAI(DSP_AIF2);
2950548448bSCharles Keepax LN2_PIN_GAI(PSIA1);
2960548448bSCharles Keepax LN2_PIN_GAI(PSIA2);
2970548448bSCharles Keepax LN2_PIN_GAI(GF_AIF1);
2980548448bSCharles Keepax LN2_PIN_GAI(GF_AIF2);
2990548448bSCharles Keepax LN2_PIN_GAI(GF_AIF3);
3000548448bSCharles Keepax LN2_PIN_GAI(GF_AIF4);
3010548448bSCharles Keepax LN2_PIN_AIF(SPDIF_AIF);
3020548448bSCharles Keepax LN2_PIN_AIF(USB_AIF1);
3030548448bSCharles Keepax LN2_PIN_AIF(USB_AIF2);
3040548448bSCharles Keepax LN2_PIN_AIF(ADAT_AIF);
3050548448bSCharles Keepax LN2_PIN_AIF(SOUNDCARD_AIF);
3060548448bSCharles Keepax 
3070548448bSCharles Keepax static const struct pinctrl_pin_desc lochnagar1_pins[] = {
3080548448bSCharles Keepax 	LN1_PIN(CDC_RESET),      LN1_PIN(DSP_RESET),    LN1_PIN(CDC_CIF1MODE),
3090548448bSCharles Keepax 	LN1_PIN(GF_GPIO2),       LN1_PIN(GF_GPIO3),     LN1_PIN(GF_GPIO7),
3100548448bSCharles Keepax 	LN1_PIN(LED1),           LN1_PIN(LED2),
3110548448bSCharles Keepax 	LN1_PINS(CDC_AIF1),      LN1_PINS(CDC_AIF2),    LN1_PINS(CDC_AIF3),
3120548448bSCharles Keepax 	LN1_PINS(DSP_AIF1),      LN1_PINS(DSP_AIF2),
3130548448bSCharles Keepax 	LN1_PINS(PSIA1),         LN1_PINS(PSIA2),
3140548448bSCharles Keepax 	LN1_PINS(SPDIF_AIF),
3150548448bSCharles Keepax 	LN1_PINS(GF_AIF1),       LN1_PINS(GF_AIF2),
3160548448bSCharles Keepax 	LN1_PINS(GF_AIF3),       LN1_PINS(GF_AIF4),
3170548448bSCharles Keepax };
3180548448bSCharles Keepax 
3190548448bSCharles Keepax static const struct pinctrl_pin_desc lochnagar2_pins[] = {
3200548448bSCharles Keepax 	LN2_PIN(CDC_RESET),      LN2_PIN(DSP_RESET),    LN2_PIN(CDC_CIF1MODE),
3210548448bSCharles Keepax 	LN2_PIN(CDC_LDOENA),
3220548448bSCharles Keepax 	LN2_PIN(SPDIF_HWMODE),   LN2_PIN(SPDIF_RESET),
3230548448bSCharles Keepax 	LN2_PIN(FPGA_GPIO1),     LN2_PIN(FPGA_GPIO2),   LN2_PIN(FPGA_GPIO3),
3240548448bSCharles Keepax 	LN2_PIN(FPGA_GPIO4),     LN2_PIN(FPGA_GPIO5),   LN2_PIN(FPGA_GPIO6),
3250548448bSCharles Keepax 	LN2_PIN(CDC_GPIO1),      LN2_PIN(CDC_GPIO2),    LN2_PIN(CDC_GPIO3),
3260548448bSCharles Keepax 	LN2_PIN(CDC_GPIO4),      LN2_PIN(CDC_GPIO5),    LN2_PIN(CDC_GPIO6),
3270548448bSCharles Keepax 	LN2_PIN(CDC_GPIO7),      LN2_PIN(CDC_GPIO8),
3280548448bSCharles Keepax 	LN2_PIN(DSP_GPIO1),      LN2_PIN(DSP_GPIO2),    LN2_PIN(DSP_GPIO3),
3290548448bSCharles Keepax 	LN2_PIN(DSP_GPIO4),      LN2_PIN(DSP_GPIO5),    LN2_PIN(DSP_GPIO6),
3300548448bSCharles Keepax 	LN2_PIN(DSP_GPIO20),
3310548448bSCharles Keepax 	LN2_PIN(GF_GPIO1),       LN2_PIN(GF_GPIO2),     LN2_PIN(GF_GPIO3),
3320548448bSCharles Keepax 	LN2_PIN(GF_GPIO5),       LN2_PIN(GF_GPIO7),
3330548448bSCharles Keepax 	LN2_PINS(CDC_AIF1),      LN2_PINS(CDC_AIF2),    LN2_PINS(CDC_AIF3),
3340548448bSCharles Keepax 	LN2_PINS(DSP_AIF1),      LN2_PINS(DSP_AIF2),
3350548448bSCharles Keepax 	LN2_PINS(PSIA1),         LN2_PINS(PSIA2),
3360548448bSCharles Keepax 	LN2_PINS(GF_AIF1),       LN2_PINS(GF_AIF2),
3370548448bSCharles Keepax 	LN2_PINS(GF_AIF3),       LN2_PINS(GF_AIF4),
3380548448bSCharles Keepax 	LN2_PIN(DSP_UART1_RX),   LN2_PIN(DSP_UART1_TX),
3390548448bSCharles Keepax 	LN2_PIN(DSP_UART2_RX),   LN2_PIN(DSP_UART2_TX),
3400548448bSCharles Keepax 	LN2_PIN(GF_UART2_RX),    LN2_PIN(GF_UART2_TX),
3410548448bSCharles Keepax 	LN2_PIN(USB_UART_RX),
3420548448bSCharles Keepax 	LN2_PIN(CDC_PDMCLK1),    LN2_PIN(CDC_PDMDAT1),
3430548448bSCharles Keepax 	LN2_PIN(CDC_PDMCLK2),    LN2_PIN(CDC_PDMDAT2),
3440548448bSCharles Keepax 	LN2_PIN(CDC_DMICCLK1),   LN2_PIN(CDC_DMICDAT1),
3450548448bSCharles Keepax 	LN2_PIN(CDC_DMICCLK2),   LN2_PIN(CDC_DMICDAT2),
3460548448bSCharles Keepax 	LN2_PIN(CDC_DMICCLK3),   LN2_PIN(CDC_DMICDAT3),
3470548448bSCharles Keepax 	LN2_PIN(CDC_DMICCLK4),   LN2_PIN(CDC_DMICDAT4),
3480548448bSCharles Keepax 	LN2_PIN(DSP_DMICCLK1),   LN2_PIN(DSP_DMICDAT1),
3490548448bSCharles Keepax 	LN2_PIN(DSP_DMICCLK2),   LN2_PIN(DSP_DMICDAT2),
3500548448bSCharles Keepax 	LN2_PIN(I2C2_SCL),       LN2_PIN(I2C2_SDA),
3510548448bSCharles Keepax 	LN2_PIN(I2C3_SCL),       LN2_PIN(I2C3_SDA),
3520548448bSCharles Keepax 	LN2_PIN(I2C4_SCL),       LN2_PIN(I2C4_SDA),
3530548448bSCharles Keepax 	LN2_PIN(DSP_STANDBY),
3540548448bSCharles Keepax 	LN2_PIN(CDC_MCLK1),      LN2_PIN(CDC_MCLK2),
3550548448bSCharles Keepax 	LN2_PIN(DSP_CLKIN),
3560548448bSCharles Keepax 	LN2_PIN(PSIA1_MCLK),     LN2_PIN(PSIA2_MCLK),
3570548448bSCharles Keepax 	LN2_PINS(SPDIF_AIF),
3580548448bSCharles Keepax 	LN2_PINS(USB_AIF1),      LN2_PINS(USB_AIF2),
3590548448bSCharles Keepax 	LN2_PINS(ADAT_AIF),
3600548448bSCharles Keepax 	LN2_PINS(SOUNDCARD_AIF),
3610548448bSCharles Keepax };
3620548448bSCharles Keepax 
3630548448bSCharles Keepax #define LN_AIF_PINS(REV, ID) \
3640548448bSCharles Keepax 	LOCHNAGAR##REV##_PIN_##ID##_BCLK, \
3650548448bSCharles Keepax 	LOCHNAGAR##REV##_PIN_##ID##_LRCLK, \
3660548448bSCharles Keepax 	LOCHNAGAR##REV##_PIN_##ID##_TXDAT, \
3670548448bSCharles Keepax 	LOCHNAGAR##REV##_PIN_##ID##_RXDAT,
3680548448bSCharles Keepax 
3690548448bSCharles Keepax #define LN1_AIF(ID, CTRL) \
3700548448bSCharles Keepax static const struct lochnagar_aif lochnagar1_##ID##_aif = { \
3710548448bSCharles Keepax 	.name = LN_##ID##_STR, \
3720548448bSCharles Keepax 	.pins = { LN_AIF_PINS(1, ID) }, \
3730548448bSCharles Keepax 	.src_reg = LOCHNAGAR1_##ID##_SEL, \
3740548448bSCharles Keepax 	.src_mask = LOCHNAGAR1_SRC_MASK, \
3750548448bSCharles Keepax 	.ctrl_reg = LOCHNAGAR1_##CTRL, \
3760548448bSCharles Keepax 	.ena_mask = LOCHNAGAR1_##ID##_ENA_MASK, \
3770548448bSCharles Keepax 	.master_mask = LOCHNAGAR1_##ID##_LRCLK_DIR_MASK | \
3780548448bSCharles Keepax 		       LOCHNAGAR1_##ID##_BCLK_DIR_MASK, \
3790548448bSCharles Keepax }
3800548448bSCharles Keepax 
3810548448bSCharles Keepax #define LN2_AIF(ID) \
3820548448bSCharles Keepax static const struct lochnagar_aif lochnagar2_##ID##_aif = { \
3830548448bSCharles Keepax 	.name = LN_##ID##_STR, \
3840548448bSCharles Keepax 	.pins = { LN_AIF_PINS(2, ID) }, \
3850548448bSCharles Keepax 	.src_reg = LOCHNAGAR2_##ID##_CTRL,  \
3860548448bSCharles Keepax 	.src_mask = LOCHNAGAR2_AIF_SRC_MASK, \
3870548448bSCharles Keepax 	.ctrl_reg = LOCHNAGAR2_##ID##_CTRL, \
3880548448bSCharles Keepax 	.ena_mask = LOCHNAGAR2_AIF_ENA_MASK, \
3890548448bSCharles Keepax 	.master_mask = LOCHNAGAR2_AIF_LRCLK_DIR_MASK | \
3900548448bSCharles Keepax 		       LOCHNAGAR2_AIF_BCLK_DIR_MASK, \
3910548448bSCharles Keepax }
3920548448bSCharles Keepax 
3930548448bSCharles Keepax struct lochnagar_aif {
3940548448bSCharles Keepax 	const char name[16];
3950548448bSCharles Keepax 
3960548448bSCharles Keepax 	unsigned int pins[4];
3970548448bSCharles Keepax 
3980548448bSCharles Keepax 	u16 src_reg;
3990548448bSCharles Keepax 	u16 src_mask;
4000548448bSCharles Keepax 
4010548448bSCharles Keepax 	u16 ctrl_reg;
4020548448bSCharles Keepax 	u16 ena_mask;
4030548448bSCharles Keepax 	u16 master_mask;
4040548448bSCharles Keepax };
4050548448bSCharles Keepax 
4060548448bSCharles Keepax LN1_AIF(CDC_AIF1,      CDC_AIF_CTRL1);
4070548448bSCharles Keepax LN1_AIF(CDC_AIF2,      CDC_AIF_CTRL1);
4080548448bSCharles Keepax LN1_AIF(CDC_AIF3,      CDC_AIF_CTRL2);
4090548448bSCharles Keepax LN1_AIF(DSP_AIF1,      DSP_AIF);
4100548448bSCharles Keepax LN1_AIF(DSP_AIF2,      DSP_AIF);
4110548448bSCharles Keepax LN1_AIF(PSIA1,         PSIA_AIF);
4120548448bSCharles Keepax LN1_AIF(PSIA2,         PSIA_AIF);
4130548448bSCharles Keepax LN1_AIF(GF_AIF1,       GF_AIF1);
4140548448bSCharles Keepax LN1_AIF(GF_AIF2,       GF_AIF2);
4150548448bSCharles Keepax LN1_AIF(GF_AIF3,       GF_AIF1);
4160548448bSCharles Keepax LN1_AIF(GF_AIF4,       GF_AIF2);
4170548448bSCharles Keepax LN1_AIF(SPDIF_AIF,     EXT_AIF_CTRL);
4180548448bSCharles Keepax 
4190548448bSCharles Keepax LN2_AIF(CDC_AIF1);
4200548448bSCharles Keepax LN2_AIF(CDC_AIF2);
4210548448bSCharles Keepax LN2_AIF(CDC_AIF3);
4220548448bSCharles Keepax LN2_AIF(DSP_AIF1);
4230548448bSCharles Keepax LN2_AIF(DSP_AIF2);
4240548448bSCharles Keepax LN2_AIF(PSIA1);
4250548448bSCharles Keepax LN2_AIF(PSIA2);
4260548448bSCharles Keepax LN2_AIF(GF_AIF1);
4270548448bSCharles Keepax LN2_AIF(GF_AIF2);
4280548448bSCharles Keepax LN2_AIF(GF_AIF3);
4290548448bSCharles Keepax LN2_AIF(GF_AIF4);
4300548448bSCharles Keepax LN2_AIF(SPDIF_AIF);
4310548448bSCharles Keepax LN2_AIF(USB_AIF1);
4320548448bSCharles Keepax LN2_AIF(USB_AIF2);
4330548448bSCharles Keepax LN2_AIF(ADAT_AIF);
4340548448bSCharles Keepax LN2_AIF(SOUNDCARD_AIF);
4350548448bSCharles Keepax 
4360548448bSCharles Keepax #define LN2_OP_AIF	0x00
4370548448bSCharles Keepax #define LN2_OP_GPIO	0xFE
4380548448bSCharles Keepax 
4390548448bSCharles Keepax #define LN_FUNC(NAME, TYPE, OP) \
4400548448bSCharles Keepax 	{ .name = NAME, .type = LN_FTYPE_##TYPE, .op = OP }
4410548448bSCharles Keepax 
4420548448bSCharles Keepax #define LN_FUNC_PIN(REV, ID, OP) \
4430548448bSCharles Keepax 	LN_FUNC(lochnagar##REV##_##ID##_pin.name, PIN, OP)
4440548448bSCharles Keepax 
4450548448bSCharles Keepax #define LN1_FUNC_PIN(ID, OP) LN_FUNC_PIN(1, ID, OP)
4460548448bSCharles Keepax #define LN2_FUNC_PIN(ID, OP) LN_FUNC_PIN(2, ID, OP)
4470548448bSCharles Keepax 
4480548448bSCharles Keepax #define LN_FUNC_AIF(REV, ID, OP) \
4490548448bSCharles Keepax 	LN_FUNC(lochnagar##REV##_##ID##_aif.name, AIF, OP)
4500548448bSCharles Keepax 
4510548448bSCharles Keepax #define LN1_FUNC_AIF(ID, OP) LN_FUNC_AIF(1, ID, OP)
4520548448bSCharles Keepax #define LN2_FUNC_AIF(ID, OP) LN_FUNC_AIF(2, ID, OP)
4530548448bSCharles Keepax 
4540548448bSCharles Keepax #define LN2_FUNC_GAI(ID, OP, BOP, LROP, RXOP, TXOP) \
4550548448bSCharles Keepax 	LN2_FUNC_AIF(ID, OP), \
4560548448bSCharles Keepax 	LN_FUNC(lochnagar2_##ID##_BCLK_pin.name, PIN, BOP), \
4570548448bSCharles Keepax 	LN_FUNC(lochnagar2_##ID##_LRCLK_pin.name, PIN, LROP), \
4580548448bSCharles Keepax 	LN_FUNC(lochnagar2_##ID##_RXDAT_pin.name, PIN, RXOP), \
4590548448bSCharles Keepax 	LN_FUNC(lochnagar2_##ID##_TXDAT_pin.name, PIN, TXOP)
4600548448bSCharles Keepax 
4610548448bSCharles Keepax enum lochnagar_func_type {
4620548448bSCharles Keepax 	LN_FTYPE_PIN,
4630548448bSCharles Keepax 	LN_FTYPE_AIF,
4640548448bSCharles Keepax 	LN_FTYPE_COUNT,
4650548448bSCharles Keepax };
4660548448bSCharles Keepax 
4670548448bSCharles Keepax struct lochnagar_func {
4680548448bSCharles Keepax 	const char * const name;
4690548448bSCharles Keepax 
4700548448bSCharles Keepax 	enum lochnagar_func_type type;
4710548448bSCharles Keepax 
4720548448bSCharles Keepax 	u8 op;
4730548448bSCharles Keepax };
4740548448bSCharles Keepax 
4750548448bSCharles Keepax static const struct lochnagar_func lochnagar1_funcs[] = {
4760548448bSCharles Keepax 	LN_FUNC("dsp-gpio1",       PIN, 0x01),
4770548448bSCharles Keepax 	LN_FUNC("dsp-gpio2",       PIN, 0x02),
4780548448bSCharles Keepax 	LN_FUNC("dsp-gpio3",       PIN, 0x03),
4790548448bSCharles Keepax 	LN_FUNC("codec-gpio1",     PIN, 0x04),
4800548448bSCharles Keepax 	LN_FUNC("codec-gpio2",     PIN, 0x05),
4810548448bSCharles Keepax 	LN_FUNC("codec-gpio3",     PIN, 0x06),
4820548448bSCharles Keepax 	LN_FUNC("codec-gpio4",     PIN, 0x07),
4830548448bSCharles Keepax 	LN_FUNC("codec-gpio5",     PIN, 0x08),
4840548448bSCharles Keepax 	LN_FUNC("codec-gpio6",     PIN, 0x09),
4850548448bSCharles Keepax 	LN_FUNC("codec-gpio7",     PIN, 0x0A),
4860548448bSCharles Keepax 	LN_FUNC("codec-gpio8",     PIN, 0x0B),
4870548448bSCharles Keepax 	LN1_FUNC_PIN(GF_GPIO2,          0x0C),
4880548448bSCharles Keepax 	LN1_FUNC_PIN(GF_GPIO3,          0x0D),
4890548448bSCharles Keepax 	LN1_FUNC_PIN(GF_GPIO7,          0x0E),
4900548448bSCharles Keepax 
4910548448bSCharles Keepax 	LN1_FUNC_AIF(SPDIF_AIF,         0x01),
4920548448bSCharles Keepax 	LN1_FUNC_AIF(PSIA1,             0x02),
4930548448bSCharles Keepax 	LN1_FUNC_AIF(PSIA2,             0x03),
4940548448bSCharles Keepax 	LN1_FUNC_AIF(CDC_AIF1,          0x04),
4950548448bSCharles Keepax 	LN1_FUNC_AIF(CDC_AIF2,          0x05),
4960548448bSCharles Keepax 	LN1_FUNC_AIF(CDC_AIF3,          0x06),
4970548448bSCharles Keepax 	LN1_FUNC_AIF(DSP_AIF1,          0x07),
4980548448bSCharles Keepax 	LN1_FUNC_AIF(DSP_AIF2,          0x08),
4990548448bSCharles Keepax 	LN1_FUNC_AIF(GF_AIF3,           0x09),
5000548448bSCharles Keepax 	LN1_FUNC_AIF(GF_AIF4,           0x0A),
5010548448bSCharles Keepax 	LN1_FUNC_AIF(GF_AIF1,           0x0B),
5020548448bSCharles Keepax 	LN1_FUNC_AIF(GF_AIF2,           0x0C),
5030548448bSCharles Keepax };
5040548448bSCharles Keepax 
5050548448bSCharles Keepax static const struct lochnagar_func lochnagar2_funcs[] = {
5060548448bSCharles Keepax 	LN_FUNC("aif",             PIN, LN2_OP_AIF),
5070548448bSCharles Keepax 	LN2_FUNC_PIN(FPGA_GPIO1,        0x01),
5080548448bSCharles Keepax 	LN2_FUNC_PIN(FPGA_GPIO2,        0x02),
5090548448bSCharles Keepax 	LN2_FUNC_PIN(FPGA_GPIO3,        0x03),
5100548448bSCharles Keepax 	LN2_FUNC_PIN(FPGA_GPIO4,        0x04),
5110548448bSCharles Keepax 	LN2_FUNC_PIN(FPGA_GPIO5,        0x05),
5120548448bSCharles Keepax 	LN2_FUNC_PIN(FPGA_GPIO6,        0x06),
5130548448bSCharles Keepax 	LN2_FUNC_PIN(CDC_GPIO1,         0x07),
5140548448bSCharles Keepax 	LN2_FUNC_PIN(CDC_GPIO2,         0x08),
5150548448bSCharles Keepax 	LN2_FUNC_PIN(CDC_GPIO3,         0x09),
5160548448bSCharles Keepax 	LN2_FUNC_PIN(CDC_GPIO4,         0x0A),
5170548448bSCharles Keepax 	LN2_FUNC_PIN(CDC_GPIO5,         0x0B),
5180548448bSCharles Keepax 	LN2_FUNC_PIN(CDC_GPIO6,         0x0C),
5190548448bSCharles Keepax 	LN2_FUNC_PIN(CDC_GPIO7,         0x0D),
5200548448bSCharles Keepax 	LN2_FUNC_PIN(CDC_GPIO8,         0x0E),
5210548448bSCharles Keepax 	LN2_FUNC_PIN(DSP_GPIO1,         0x0F),
5220548448bSCharles Keepax 	LN2_FUNC_PIN(DSP_GPIO2,         0x10),
5230548448bSCharles Keepax 	LN2_FUNC_PIN(DSP_GPIO3,         0x11),
5240548448bSCharles Keepax 	LN2_FUNC_PIN(DSP_GPIO4,         0x12),
5250548448bSCharles Keepax 	LN2_FUNC_PIN(DSP_GPIO5,         0x13),
5260548448bSCharles Keepax 	LN2_FUNC_PIN(DSP_GPIO6,         0x14),
5270548448bSCharles Keepax 	LN2_FUNC_PIN(GF_GPIO2,          0x15),
5280548448bSCharles Keepax 	LN2_FUNC_PIN(GF_GPIO3,          0x16),
5290548448bSCharles Keepax 	LN2_FUNC_PIN(GF_GPIO7,          0x17),
5300548448bSCharles Keepax 	LN2_FUNC_PIN(GF_GPIO1,          0x18),
5310548448bSCharles Keepax 	LN2_FUNC_PIN(GF_GPIO5,          0x19),
5320548448bSCharles Keepax 	LN2_FUNC_PIN(DSP_GPIO20,        0x1A),
5330548448bSCharles Keepax 	LN_FUNC("codec-clkout",    PIN, 0x20),
5340548448bSCharles Keepax 	LN_FUNC("dsp-clkout",      PIN, 0x21),
5350548448bSCharles Keepax 	LN_FUNC("pmic-32k",        PIN, 0x22),
5360548448bSCharles Keepax 	LN_FUNC("spdif-clkout",    PIN, 0x23),
5370548448bSCharles Keepax 	LN_FUNC("clk-12m288",      PIN, 0x24),
5380548448bSCharles Keepax 	LN_FUNC("clk-11m2986",     PIN, 0x25),
5390548448bSCharles Keepax 	LN_FUNC("clk-24m576",      PIN, 0x26),
5400548448bSCharles Keepax 	LN_FUNC("clk-22m5792",     PIN, 0x27),
5410548448bSCharles Keepax 	LN_FUNC("xmos-mclk",       PIN, 0x29),
5420548448bSCharles Keepax 	LN_FUNC("gf-clkout1",      PIN, 0x2A),
5430548448bSCharles Keepax 	LN_FUNC("gf-mclk1",        PIN, 0x2B),
5440548448bSCharles Keepax 	LN_FUNC("gf-mclk3",        PIN, 0x2C),
5450548448bSCharles Keepax 	LN_FUNC("gf-mclk2",        PIN, 0x2D),
5460548448bSCharles Keepax 	LN_FUNC("gf-clkout2",      PIN, 0x2E),
5470548448bSCharles Keepax 	LN2_FUNC_PIN(CDC_MCLK1,         0x2F),
5480548448bSCharles Keepax 	LN2_FUNC_PIN(CDC_MCLK2,         0x30),
5490548448bSCharles Keepax 	LN2_FUNC_PIN(DSP_CLKIN,         0x31),
5500548448bSCharles Keepax 	LN2_FUNC_PIN(PSIA1_MCLK,        0x32),
5510548448bSCharles Keepax 	LN2_FUNC_PIN(PSIA2_MCLK,        0x33),
5520548448bSCharles Keepax 	LN_FUNC("spdif-mclk",      PIN, 0x34),
5530548448bSCharles Keepax 	LN_FUNC("codec-irq",       PIN, 0x42),
5540548448bSCharles Keepax 	LN2_FUNC_PIN(CDC_RESET,         0x43),
5550548448bSCharles Keepax 	LN2_FUNC_PIN(DSP_RESET,         0x44),
5560548448bSCharles Keepax 	LN_FUNC("dsp-irq",         PIN, 0x45),
5570548448bSCharles Keepax 	LN2_FUNC_PIN(DSP_STANDBY,       0x46),
5580548448bSCharles Keepax 	LN2_FUNC_PIN(CDC_PDMCLK1,       0x90),
5590548448bSCharles Keepax 	LN2_FUNC_PIN(CDC_PDMDAT1,       0x91),
5600548448bSCharles Keepax 	LN2_FUNC_PIN(CDC_PDMCLK2,       0x92),
5610548448bSCharles Keepax 	LN2_FUNC_PIN(CDC_PDMDAT2,       0x93),
5620548448bSCharles Keepax 	LN2_FUNC_PIN(CDC_DMICCLK1,      0xA0),
5630548448bSCharles Keepax 	LN2_FUNC_PIN(CDC_DMICDAT1,      0xA1),
5640548448bSCharles Keepax 	LN2_FUNC_PIN(CDC_DMICCLK2,      0xA2),
5650548448bSCharles Keepax 	LN2_FUNC_PIN(CDC_DMICDAT2,      0xA3),
5660548448bSCharles Keepax 	LN2_FUNC_PIN(CDC_DMICCLK3,      0xA4),
5670548448bSCharles Keepax 	LN2_FUNC_PIN(CDC_DMICDAT3,      0xA5),
5680548448bSCharles Keepax 	LN2_FUNC_PIN(CDC_DMICCLK4,      0xA6),
5690548448bSCharles Keepax 	LN2_FUNC_PIN(CDC_DMICDAT4,      0xA7),
5700548448bSCharles Keepax 	LN2_FUNC_PIN(DSP_DMICCLK1,      0xA8),
5710548448bSCharles Keepax 	LN2_FUNC_PIN(DSP_DMICDAT1,      0xA9),
5720548448bSCharles Keepax 	LN2_FUNC_PIN(DSP_DMICCLK2,      0xAA),
5730548448bSCharles Keepax 	LN2_FUNC_PIN(DSP_DMICDAT2,      0xAB),
5740548448bSCharles Keepax 	LN2_FUNC_PIN(DSP_UART1_RX,      0xC0),
5750548448bSCharles Keepax 	LN2_FUNC_PIN(DSP_UART1_TX,      0xC1),
5760548448bSCharles Keepax 	LN2_FUNC_PIN(DSP_UART2_RX,      0xC2),
5770548448bSCharles Keepax 	LN2_FUNC_PIN(DSP_UART2_TX,      0xC3),
5780548448bSCharles Keepax 	LN2_FUNC_PIN(GF_UART2_RX,       0xC4),
5790548448bSCharles Keepax 	LN2_FUNC_PIN(GF_UART2_TX,       0xC5),
5800548448bSCharles Keepax 	LN2_FUNC_PIN(USB_UART_RX,       0xC6),
5810548448bSCharles Keepax 	LN_FUNC("usb-uart-tx",     PIN, 0xC7),
5820548448bSCharles Keepax 	LN2_FUNC_PIN(I2C2_SCL,          0xE0),
5830548448bSCharles Keepax 	LN2_FUNC_PIN(I2C2_SDA,          0xE1),
5840548448bSCharles Keepax 	LN2_FUNC_PIN(I2C3_SCL,          0xE2),
5850548448bSCharles Keepax 	LN2_FUNC_PIN(I2C3_SDA,          0xE3),
5860548448bSCharles Keepax 	LN2_FUNC_PIN(I2C4_SCL,          0xE4),
5870548448bSCharles Keepax 	LN2_FUNC_PIN(I2C4_SDA,          0xE5),
5880548448bSCharles Keepax 
5890548448bSCharles Keepax 	LN2_FUNC_AIF(SPDIF_AIF,         0x01),
5900548448bSCharles Keepax 	LN2_FUNC_GAI(PSIA1,             0x02, 0x50, 0x51, 0x52, 0x53),
5910548448bSCharles Keepax 	LN2_FUNC_GAI(PSIA2,             0x03, 0x54, 0x55, 0x56, 0x57),
5920548448bSCharles Keepax 	LN2_FUNC_GAI(CDC_AIF1,          0x04, 0x59, 0x5B, 0x5A, 0x58),
5930548448bSCharles Keepax 	LN2_FUNC_GAI(CDC_AIF2,          0x05, 0x5D, 0x5F, 0x5E, 0x5C),
5940548448bSCharles Keepax 	LN2_FUNC_GAI(CDC_AIF3,          0x06, 0x61, 0x62, 0x63, 0x60),
5950548448bSCharles Keepax 	LN2_FUNC_GAI(DSP_AIF1,          0x07, 0x65, 0x67, 0x66, 0x64),
5960548448bSCharles Keepax 	LN2_FUNC_GAI(DSP_AIF2,          0x08, 0x69, 0x6B, 0x6A, 0x68),
5970548448bSCharles Keepax 	LN2_FUNC_GAI(GF_AIF3,           0x09, 0x6D, 0x6F, 0x6C, 0x6E),
5980548448bSCharles Keepax 	LN2_FUNC_GAI(GF_AIF4,           0x0A, 0x71, 0x73, 0x70, 0x72),
5990548448bSCharles Keepax 	LN2_FUNC_GAI(GF_AIF1,           0x0B, 0x75, 0x77, 0x74, 0x76),
6000548448bSCharles Keepax 	LN2_FUNC_GAI(GF_AIF2,           0x0C, 0x79, 0x7B, 0x78, 0x7A),
6010548448bSCharles Keepax 	LN2_FUNC_AIF(USB_AIF1,          0x0D),
6020548448bSCharles Keepax 	LN2_FUNC_AIF(USB_AIF2,          0x0E),
6030548448bSCharles Keepax 	LN2_FUNC_AIF(ADAT_AIF,          0x0F),
6040548448bSCharles Keepax 	LN2_FUNC_AIF(SOUNDCARD_AIF,     0x10),
6050548448bSCharles Keepax };
6060548448bSCharles Keepax 
6070548448bSCharles Keepax #define LN_GROUP_PIN(REV, ID) { \
6080548448bSCharles Keepax 	.name = lochnagar##REV##_##ID##_pin.name, \
6090548448bSCharles Keepax 	.type = LN_FTYPE_PIN, \
6100548448bSCharles Keepax 	.pins = &lochnagar##REV##_pins[LOCHNAGAR##REV##_PIN_##ID].number, \
6110548448bSCharles Keepax 	.npins = 1, \
6120548448bSCharles Keepax 	.priv = &lochnagar##REV##_pins[LOCHNAGAR##REV##_PIN_##ID], \
6130548448bSCharles Keepax }
6140548448bSCharles Keepax 
6150548448bSCharles Keepax #define LN_GROUP_AIF(REV, ID) { \
6160548448bSCharles Keepax 	.name = lochnagar##REV##_##ID##_aif.name, \
6170548448bSCharles Keepax 	.type = LN_FTYPE_AIF, \
6180548448bSCharles Keepax 	.pins = lochnagar##REV##_##ID##_aif.pins, \
6190548448bSCharles Keepax 	.npins = ARRAY_SIZE(lochnagar##REV##_##ID##_aif.pins), \
6200548448bSCharles Keepax 	.priv = &lochnagar##REV##_##ID##_aif, \
6210548448bSCharles Keepax }
6220548448bSCharles Keepax 
6230548448bSCharles Keepax #define LN1_GROUP_PIN(ID) LN_GROUP_PIN(1, ID)
6240548448bSCharles Keepax #define LN2_GROUP_PIN(ID) LN_GROUP_PIN(2, ID)
6250548448bSCharles Keepax 
6260548448bSCharles Keepax #define LN1_GROUP_AIF(ID) LN_GROUP_AIF(1, ID)
6270548448bSCharles Keepax #define LN2_GROUP_AIF(ID) LN_GROUP_AIF(2, ID)
6280548448bSCharles Keepax 
6290548448bSCharles Keepax #define LN2_GROUP_GAI(ID) \
6300548448bSCharles Keepax 	LN2_GROUP_AIF(ID), \
6310548448bSCharles Keepax 	LN2_GROUP_PIN(ID##_BCLK), LN2_GROUP_PIN(ID##_LRCLK), \
6320548448bSCharles Keepax 	LN2_GROUP_PIN(ID##_RXDAT), LN2_GROUP_PIN(ID##_TXDAT)
6330548448bSCharles Keepax 
6340548448bSCharles Keepax struct lochnagar_group {
6350548448bSCharles Keepax 	const char * const name;
6360548448bSCharles Keepax 
6370548448bSCharles Keepax 	enum lochnagar_func_type type;
6380548448bSCharles Keepax 
6390548448bSCharles Keepax 	const unsigned int *pins;
6400548448bSCharles Keepax 	unsigned int npins;
6410548448bSCharles Keepax 
6420548448bSCharles Keepax 	const void *priv;
6430548448bSCharles Keepax };
6440548448bSCharles Keepax 
6450548448bSCharles Keepax static const struct lochnagar_group lochnagar1_groups[] = {
6460548448bSCharles Keepax 	LN1_GROUP_PIN(GF_GPIO2),       LN1_GROUP_PIN(GF_GPIO3),
6470548448bSCharles Keepax 	LN1_GROUP_PIN(GF_GPIO7),
6480548448bSCharles Keepax 	LN1_GROUP_PIN(LED1),           LN1_GROUP_PIN(LED2),
6490548448bSCharles Keepax 	LN1_GROUP_AIF(CDC_AIF1),       LN1_GROUP_AIF(CDC_AIF2),
6500548448bSCharles Keepax 	LN1_GROUP_AIF(CDC_AIF3),
6510548448bSCharles Keepax 	LN1_GROUP_AIF(DSP_AIF1),       LN1_GROUP_AIF(DSP_AIF2),
6520548448bSCharles Keepax 	LN1_GROUP_AIF(PSIA1),          LN1_GROUP_AIF(PSIA2),
6530548448bSCharles Keepax 	LN1_GROUP_AIF(GF_AIF1),        LN1_GROUP_AIF(GF_AIF2),
6540548448bSCharles Keepax 	LN1_GROUP_AIF(GF_AIF3),        LN1_GROUP_AIF(GF_AIF4),
6550548448bSCharles Keepax 	LN1_GROUP_AIF(SPDIF_AIF),
6560548448bSCharles Keepax };
6570548448bSCharles Keepax 
6580548448bSCharles Keepax static const struct lochnagar_group lochnagar2_groups[] = {
6590548448bSCharles Keepax 	LN2_GROUP_PIN(FPGA_GPIO1),     LN2_GROUP_PIN(FPGA_GPIO2),
6600548448bSCharles Keepax 	LN2_GROUP_PIN(FPGA_GPIO3),     LN2_GROUP_PIN(FPGA_GPIO4),
6610548448bSCharles Keepax 	LN2_GROUP_PIN(FPGA_GPIO5),     LN2_GROUP_PIN(FPGA_GPIO6),
6620548448bSCharles Keepax 	LN2_GROUP_PIN(CDC_GPIO1),      LN2_GROUP_PIN(CDC_GPIO2),
6630548448bSCharles Keepax 	LN2_GROUP_PIN(CDC_GPIO3),      LN2_GROUP_PIN(CDC_GPIO4),
6640548448bSCharles Keepax 	LN2_GROUP_PIN(CDC_GPIO5),      LN2_GROUP_PIN(CDC_GPIO6),
6650548448bSCharles Keepax 	LN2_GROUP_PIN(CDC_GPIO7),      LN2_GROUP_PIN(CDC_GPIO8),
6660548448bSCharles Keepax 	LN2_GROUP_PIN(DSP_GPIO1),      LN2_GROUP_PIN(DSP_GPIO2),
6670548448bSCharles Keepax 	LN2_GROUP_PIN(DSP_GPIO3),      LN2_GROUP_PIN(DSP_GPIO4),
6680548448bSCharles Keepax 	LN2_GROUP_PIN(DSP_GPIO5),      LN2_GROUP_PIN(DSP_GPIO6),
6690548448bSCharles Keepax 	LN2_GROUP_PIN(DSP_GPIO20),
6700548448bSCharles Keepax 	LN2_GROUP_PIN(GF_GPIO1),
6710548448bSCharles Keepax 	LN2_GROUP_PIN(GF_GPIO2),       LN2_GROUP_PIN(GF_GPIO5),
6720548448bSCharles Keepax 	LN2_GROUP_PIN(GF_GPIO3),       LN2_GROUP_PIN(GF_GPIO7),
6730548448bSCharles Keepax 	LN2_GROUP_PIN(DSP_UART1_RX),   LN2_GROUP_PIN(DSP_UART1_TX),
6740548448bSCharles Keepax 	LN2_GROUP_PIN(DSP_UART2_RX),   LN2_GROUP_PIN(DSP_UART2_TX),
6750548448bSCharles Keepax 	LN2_GROUP_PIN(GF_UART2_RX),    LN2_GROUP_PIN(GF_UART2_TX),
6760548448bSCharles Keepax 	LN2_GROUP_PIN(USB_UART_RX),
6770548448bSCharles Keepax 	LN2_GROUP_PIN(CDC_PDMCLK1),    LN2_GROUP_PIN(CDC_PDMDAT1),
6780548448bSCharles Keepax 	LN2_GROUP_PIN(CDC_PDMCLK2),    LN2_GROUP_PIN(CDC_PDMDAT2),
6790548448bSCharles Keepax 	LN2_GROUP_PIN(CDC_DMICCLK1),   LN2_GROUP_PIN(CDC_DMICDAT1),
6800548448bSCharles Keepax 	LN2_GROUP_PIN(CDC_DMICCLK2),   LN2_GROUP_PIN(CDC_DMICDAT2),
6810548448bSCharles Keepax 	LN2_GROUP_PIN(CDC_DMICCLK3),   LN2_GROUP_PIN(CDC_DMICDAT3),
6820548448bSCharles Keepax 	LN2_GROUP_PIN(CDC_DMICCLK4),   LN2_GROUP_PIN(CDC_DMICDAT4),
6830548448bSCharles Keepax 	LN2_GROUP_PIN(DSP_DMICCLK1),   LN2_GROUP_PIN(DSP_DMICDAT1),
6840548448bSCharles Keepax 	LN2_GROUP_PIN(DSP_DMICCLK2),   LN2_GROUP_PIN(DSP_DMICDAT2),
6850548448bSCharles Keepax 	LN2_GROUP_PIN(I2C2_SCL),       LN2_GROUP_PIN(I2C2_SDA),
6860548448bSCharles Keepax 	LN2_GROUP_PIN(I2C3_SCL),       LN2_GROUP_PIN(I2C3_SDA),
6870548448bSCharles Keepax 	LN2_GROUP_PIN(I2C4_SCL),       LN2_GROUP_PIN(I2C4_SDA),
6880548448bSCharles Keepax 	LN2_GROUP_PIN(DSP_STANDBY),
6890548448bSCharles Keepax 	LN2_GROUP_PIN(CDC_MCLK1),      LN2_GROUP_PIN(CDC_MCLK2),
6900548448bSCharles Keepax 	LN2_GROUP_PIN(DSP_CLKIN),
6910548448bSCharles Keepax 	LN2_GROUP_PIN(PSIA1_MCLK),     LN2_GROUP_PIN(PSIA2_MCLK),
6920548448bSCharles Keepax 	LN2_GROUP_GAI(CDC_AIF1),       LN2_GROUP_GAI(CDC_AIF2),
6930548448bSCharles Keepax 	LN2_GROUP_GAI(CDC_AIF3),
6940548448bSCharles Keepax 	LN2_GROUP_GAI(DSP_AIF1),       LN2_GROUP_GAI(DSP_AIF2),
6950548448bSCharles Keepax 	LN2_GROUP_GAI(PSIA1),          LN2_GROUP_GAI(PSIA2),
6960548448bSCharles Keepax 	LN2_GROUP_GAI(GF_AIF1),        LN2_GROUP_GAI(GF_AIF2),
6970548448bSCharles Keepax 	LN2_GROUP_GAI(GF_AIF3),        LN2_GROUP_GAI(GF_AIF4),
6980548448bSCharles Keepax 	LN2_GROUP_AIF(SPDIF_AIF),
6990548448bSCharles Keepax 	LN2_GROUP_AIF(USB_AIF1),       LN2_GROUP_AIF(USB_AIF2),
7000548448bSCharles Keepax 	LN2_GROUP_AIF(ADAT_AIF),
7010548448bSCharles Keepax 	LN2_GROUP_AIF(SOUNDCARD_AIF),
7020548448bSCharles Keepax };
7030548448bSCharles Keepax 
7040548448bSCharles Keepax struct lochnagar_func_groups {
7050548448bSCharles Keepax 	const char **groups;
7060548448bSCharles Keepax 	unsigned int ngroups;
7070548448bSCharles Keepax };
7080548448bSCharles Keepax 
7090548448bSCharles Keepax struct lochnagar_pin_priv {
7100548448bSCharles Keepax 	struct lochnagar *lochnagar;
7110548448bSCharles Keepax 	struct device *dev;
7120548448bSCharles Keepax 
7130548448bSCharles Keepax 	const struct lochnagar_func *funcs;
7140548448bSCharles Keepax 	unsigned int nfuncs;
7150548448bSCharles Keepax 
7160548448bSCharles Keepax 	const struct pinctrl_pin_desc *pins;
7170548448bSCharles Keepax 	unsigned int npins;
7180548448bSCharles Keepax 
7190548448bSCharles Keepax 	const struct lochnagar_group *groups;
7200548448bSCharles Keepax 	unsigned int ngroups;
7210548448bSCharles Keepax 
7220548448bSCharles Keepax 	struct lochnagar_func_groups func_groups[LN_FTYPE_COUNT];
7230548448bSCharles Keepax 
7240548448bSCharles Keepax 	struct gpio_chip gpio_chip;
7250548448bSCharles Keepax };
7260548448bSCharles Keepax 
lochnagar_get_groups_count(struct pinctrl_dev * pctldev)7270548448bSCharles Keepax static int lochnagar_get_groups_count(struct pinctrl_dev *pctldev)
7280548448bSCharles Keepax {
7290548448bSCharles Keepax 	struct lochnagar_pin_priv *priv = pinctrl_dev_get_drvdata(pctldev);
7300548448bSCharles Keepax 
7310548448bSCharles Keepax 	return priv->ngroups;
7320548448bSCharles Keepax }
7330548448bSCharles Keepax 
lochnagar_get_group_name(struct pinctrl_dev * pctldev,unsigned int group_idx)7340548448bSCharles Keepax static const char *lochnagar_get_group_name(struct pinctrl_dev *pctldev,
7350548448bSCharles Keepax 					    unsigned int group_idx)
7360548448bSCharles Keepax {
7370548448bSCharles Keepax 	struct lochnagar_pin_priv *priv = pinctrl_dev_get_drvdata(pctldev);
7380548448bSCharles Keepax 
7390548448bSCharles Keepax 	return priv->groups[group_idx].name;
7400548448bSCharles Keepax }
7410548448bSCharles Keepax 
lochnagar_get_group_pins(struct pinctrl_dev * pctldev,unsigned int group_idx,const unsigned int ** pins,unsigned int * num_pins)7420548448bSCharles Keepax static int lochnagar_get_group_pins(struct pinctrl_dev *pctldev,
7430548448bSCharles Keepax 				    unsigned int group_idx,
7440548448bSCharles Keepax 				    const unsigned int **pins,
7450548448bSCharles Keepax 				    unsigned int *num_pins)
7460548448bSCharles Keepax {
7470548448bSCharles Keepax 	struct lochnagar_pin_priv *priv = pinctrl_dev_get_drvdata(pctldev);
7480548448bSCharles Keepax 
7490548448bSCharles Keepax 	*pins = priv->groups[group_idx].pins;
7500548448bSCharles Keepax 	*num_pins = priv->groups[group_idx].npins;
7510548448bSCharles Keepax 
7520548448bSCharles Keepax 	return 0;
7530548448bSCharles Keepax }
7540548448bSCharles Keepax 
7550548448bSCharles Keepax static const struct pinctrl_ops lochnagar_pin_group_ops = {
7560548448bSCharles Keepax 	.get_groups_count = lochnagar_get_groups_count,
7570548448bSCharles Keepax 	.get_group_name = lochnagar_get_group_name,
7580548448bSCharles Keepax 	.get_group_pins = lochnagar_get_group_pins,
7590548448bSCharles Keepax 	.dt_node_to_map = pinconf_generic_dt_node_to_map_all,
7600548448bSCharles Keepax 	.dt_free_map = pinctrl_utils_free_map,
7610548448bSCharles Keepax };
7620548448bSCharles Keepax 
lochnagar_get_funcs_count(struct pinctrl_dev * pctldev)7630548448bSCharles Keepax static int lochnagar_get_funcs_count(struct pinctrl_dev *pctldev)
7640548448bSCharles Keepax {
7650548448bSCharles Keepax 	struct lochnagar_pin_priv *priv = pinctrl_dev_get_drvdata(pctldev);
7660548448bSCharles Keepax 
7670548448bSCharles Keepax 	return priv->nfuncs;
7680548448bSCharles Keepax }
7690548448bSCharles Keepax 
lochnagar_get_func_name(struct pinctrl_dev * pctldev,unsigned int func_idx)7700548448bSCharles Keepax static const char *lochnagar_get_func_name(struct pinctrl_dev *pctldev,
7710548448bSCharles Keepax 					   unsigned int func_idx)
7720548448bSCharles Keepax {
7730548448bSCharles Keepax 	struct lochnagar_pin_priv *priv = pinctrl_dev_get_drvdata(pctldev);
7740548448bSCharles Keepax 
7750548448bSCharles Keepax 	return priv->funcs[func_idx].name;
7760548448bSCharles Keepax }
7770548448bSCharles Keepax 
lochnagar_get_func_groups(struct pinctrl_dev * pctldev,unsigned int func_idx,const char * const ** groups,unsigned int * const num_groups)7780548448bSCharles Keepax static int lochnagar_get_func_groups(struct pinctrl_dev *pctldev,
7790548448bSCharles Keepax 				     unsigned int func_idx,
7800548448bSCharles Keepax 				     const char * const **groups,
7810548448bSCharles Keepax 				     unsigned int * const num_groups)
7820548448bSCharles Keepax {
7830548448bSCharles Keepax 	struct lochnagar_pin_priv *priv = pinctrl_dev_get_drvdata(pctldev);
7840548448bSCharles Keepax 	int func_type;
7850548448bSCharles Keepax 
7860548448bSCharles Keepax 	func_type = priv->funcs[func_idx].type;
7870548448bSCharles Keepax 
7880548448bSCharles Keepax 	*groups = priv->func_groups[func_type].groups;
7890548448bSCharles Keepax 	*num_groups = priv->func_groups[func_type].ngroups;
7900548448bSCharles Keepax 
7910548448bSCharles Keepax 	return 0;
7920548448bSCharles Keepax }
7930548448bSCharles Keepax 
lochnagar2_get_gpio_chan(struct lochnagar_pin_priv * priv,unsigned int op)7940548448bSCharles Keepax static int lochnagar2_get_gpio_chan(struct lochnagar_pin_priv *priv,
7950548448bSCharles Keepax 				    unsigned int op)
7960548448bSCharles Keepax {
7970548448bSCharles Keepax 	struct regmap *regmap = priv->lochnagar->regmap;
7980548448bSCharles Keepax 	unsigned int val;
7990548448bSCharles Keepax 	int free = -1;
8000548448bSCharles Keepax 	int i, ret;
8010548448bSCharles Keepax 
8020548448bSCharles Keepax 	for (i = 0; i < LN2_NUM_GPIO_CHANNELS; i++) {
8030548448bSCharles Keepax 		ret = regmap_read(regmap, LOCHNAGAR2_GPIO_CHANNEL1 + i, &val);
8040548448bSCharles Keepax 		if (ret)
8050548448bSCharles Keepax 			return ret;
8060548448bSCharles Keepax 
8070548448bSCharles Keepax 		val &= LOCHNAGAR2_GPIO_CHANNEL_SRC_MASK;
8080548448bSCharles Keepax 
8090548448bSCharles Keepax 		if (val == op)
8100548448bSCharles Keepax 			return i + 1;
8110548448bSCharles Keepax 
8120548448bSCharles Keepax 		if (free < 0 && !val)
8130548448bSCharles Keepax 			free = i;
8140548448bSCharles Keepax 	}
8150548448bSCharles Keepax 
8160548448bSCharles Keepax 	if (free >= 0) {
8170548448bSCharles Keepax 		ret = regmap_update_bits(regmap,
8180548448bSCharles Keepax 					 LOCHNAGAR2_GPIO_CHANNEL1 + free,
8190548448bSCharles Keepax 					 LOCHNAGAR2_GPIO_CHANNEL_SRC_MASK, op);
8200548448bSCharles Keepax 		if (ret)
8210548448bSCharles Keepax 			return ret;
8220548448bSCharles Keepax 
8230548448bSCharles Keepax 		free++;
8240548448bSCharles Keepax 
8250548448bSCharles Keepax 		dev_dbg(priv->dev, "Set channel %d to 0x%x\n", free, op);
8260548448bSCharles Keepax 
8270548448bSCharles Keepax 		return free;
8280548448bSCharles Keepax 	}
8290548448bSCharles Keepax 
8300548448bSCharles Keepax 	return -ENOSPC;
8310548448bSCharles Keepax }
8320548448bSCharles Keepax 
lochnagar_pin_set_mux(struct lochnagar_pin_priv * priv,const struct lochnagar_pin * pin,unsigned int op)8330548448bSCharles Keepax static int lochnagar_pin_set_mux(struct lochnagar_pin_priv *priv,
8340548448bSCharles Keepax 				 const struct lochnagar_pin *pin,
8350548448bSCharles Keepax 				 unsigned int op)
8360548448bSCharles Keepax {
8370548448bSCharles Keepax 	int ret;
8380548448bSCharles Keepax 
8390548448bSCharles Keepax 	switch (priv->lochnagar->type) {
8400548448bSCharles Keepax 	case LOCHNAGAR1:
8410548448bSCharles Keepax 		break;
8420548448bSCharles Keepax 	default:
8430548448bSCharles Keepax 		ret = lochnagar2_get_gpio_chan(priv, op);
8440548448bSCharles Keepax 		if (ret < 0) {
8450548448bSCharles Keepax 			dev_err(priv->dev, "Failed to get channel for %s: %d\n",
8460548448bSCharles Keepax 				pin->name, ret);
8470548448bSCharles Keepax 			return ret;
8480548448bSCharles Keepax 		}
8490548448bSCharles Keepax 
8500548448bSCharles Keepax 		op = ret;
8510548448bSCharles Keepax 		break;
8520548448bSCharles Keepax 	}
8530548448bSCharles Keepax 
8540548448bSCharles Keepax 	dev_dbg(priv->dev, "Set pin %s to 0x%x\n", pin->name, op);
8550548448bSCharles Keepax 
8560548448bSCharles Keepax 	ret = regmap_write(priv->lochnagar->regmap, pin->reg, op);
8570548448bSCharles Keepax 	if (ret)
8580548448bSCharles Keepax 		dev_err(priv->dev, "Failed to set %s mux: %d\n",
8590548448bSCharles Keepax 			pin->name, ret);
8600548448bSCharles Keepax 
8610548448bSCharles Keepax 	return 0;
8620548448bSCharles Keepax }
8630548448bSCharles Keepax 
lochnagar_aif_set_mux(struct lochnagar_pin_priv * priv,const struct lochnagar_group * group,unsigned int op)8640548448bSCharles Keepax static int lochnagar_aif_set_mux(struct lochnagar_pin_priv *priv,
8650548448bSCharles Keepax 				 const struct lochnagar_group *group,
8660548448bSCharles Keepax 				 unsigned int op)
8670548448bSCharles Keepax {
8680548448bSCharles Keepax 	struct regmap *regmap = priv->lochnagar->regmap;
8690548448bSCharles Keepax 	const struct lochnagar_aif *aif = group->priv;
8700548448bSCharles Keepax 	const struct lochnagar_pin *pin;
8710548448bSCharles Keepax 	int i, ret;
8720548448bSCharles Keepax 
8730548448bSCharles Keepax 	ret = regmap_update_bits(regmap, aif->src_reg, aif->src_mask, op);
8740548448bSCharles Keepax 	if (ret) {
8750548448bSCharles Keepax 		dev_err(priv->dev, "Failed to set %s source: %d\n",
8760548448bSCharles Keepax 			group->name, ret);
8770548448bSCharles Keepax 		return ret;
8780548448bSCharles Keepax 	}
8790548448bSCharles Keepax 
8800548448bSCharles Keepax 	ret = regmap_update_bits(regmap, aif->ctrl_reg,
8810548448bSCharles Keepax 				 aif->ena_mask, aif->ena_mask);
8820548448bSCharles Keepax 	if (ret) {
8830548448bSCharles Keepax 		dev_err(priv->dev, "Failed to set %s enable: %d\n",
8840548448bSCharles Keepax 			group->name, ret);
8850548448bSCharles Keepax 		return ret;
8860548448bSCharles Keepax 	}
8870548448bSCharles Keepax 
8880548448bSCharles Keepax 	for (i = 0; i < group->npins; i++) {
8890548448bSCharles Keepax 		pin = priv->pins[group->pins[i]].drv_data;
8900548448bSCharles Keepax 
8910548448bSCharles Keepax 		if (pin->type != LN_PTYPE_MUX)
8920548448bSCharles Keepax 			continue;
8930548448bSCharles Keepax 
8940548448bSCharles Keepax 		dev_dbg(priv->dev, "Set pin %s to AIF\n", pin->name);
8950548448bSCharles Keepax 
8960548448bSCharles Keepax 		ret = regmap_update_bits(regmap, pin->reg,
8970548448bSCharles Keepax 					 LOCHNAGAR2_GPIO_SRC_MASK,
8980548448bSCharles Keepax 					 LN2_OP_AIF);
8990548448bSCharles Keepax 		if (ret) {
9000548448bSCharles Keepax 			dev_err(priv->dev, "Failed to set %s to AIF: %d\n",
9010548448bSCharles Keepax 				pin->name, ret);
9020548448bSCharles Keepax 			return ret;
9030548448bSCharles Keepax 		}
9040548448bSCharles Keepax 	}
9050548448bSCharles Keepax 
9060548448bSCharles Keepax 	return 0;
9070548448bSCharles Keepax }
9080548448bSCharles Keepax 
lochnagar_set_mux(struct pinctrl_dev * pctldev,unsigned int func_idx,unsigned int group_idx)9090548448bSCharles Keepax static int lochnagar_set_mux(struct pinctrl_dev *pctldev,
9100548448bSCharles Keepax 			     unsigned int func_idx, unsigned int group_idx)
9110548448bSCharles Keepax {
9120548448bSCharles Keepax 	struct lochnagar_pin_priv *priv = pinctrl_dev_get_drvdata(pctldev);
9130548448bSCharles Keepax 	const struct lochnagar_func *func = &priv->funcs[func_idx];
9140548448bSCharles Keepax 	const struct lochnagar_group *group = &priv->groups[group_idx];
9150548448bSCharles Keepax 	const struct lochnagar_pin *pin;
9160548448bSCharles Keepax 
9170548448bSCharles Keepax 	switch (func->type) {
9180548448bSCharles Keepax 	case LN_FTYPE_AIF:
9190548448bSCharles Keepax 		dev_dbg(priv->dev, "Set group %s to %s\n",
9200548448bSCharles Keepax 			group->name, func->name);
9210548448bSCharles Keepax 
9220548448bSCharles Keepax 		return lochnagar_aif_set_mux(priv, group, func->op);
9230548448bSCharles Keepax 	case LN_FTYPE_PIN:
9240548448bSCharles Keepax 		pin = priv->pins[*group->pins].drv_data;
9250548448bSCharles Keepax 
9260548448bSCharles Keepax 		dev_dbg(priv->dev, "Set pin %s to %s\n", pin->name, func->name);
9270548448bSCharles Keepax 
9280548448bSCharles Keepax 		return lochnagar_pin_set_mux(priv, pin, func->op);
9290548448bSCharles Keepax 	default:
9300548448bSCharles Keepax 		return -EINVAL;
9310548448bSCharles Keepax 	}
9320548448bSCharles Keepax }
9330548448bSCharles Keepax 
lochnagar_gpio_request(struct pinctrl_dev * pctldev,struct pinctrl_gpio_range * range,unsigned int offset)9340548448bSCharles Keepax static int lochnagar_gpio_request(struct pinctrl_dev *pctldev,
9350548448bSCharles Keepax 				  struct pinctrl_gpio_range *range,
9360548448bSCharles Keepax 				  unsigned int offset)
9370548448bSCharles Keepax {
9380548448bSCharles Keepax 	struct lochnagar_pin_priv *priv = pinctrl_dev_get_drvdata(pctldev);
9390548448bSCharles Keepax 	struct lochnagar *lochnagar = priv->lochnagar;
9400548448bSCharles Keepax 	const struct lochnagar_pin *pin = priv->pins[offset].drv_data;
9410548448bSCharles Keepax 	int ret;
9420548448bSCharles Keepax 
9430548448bSCharles Keepax 	dev_dbg(priv->dev, "Requesting GPIO %s\n", pin->name);
9440548448bSCharles Keepax 
9450548448bSCharles Keepax 	if (lochnagar->type == LOCHNAGAR1 || pin->type != LN_PTYPE_MUX)
9460548448bSCharles Keepax 		return 0;
9470548448bSCharles Keepax 
9480548448bSCharles Keepax 	ret = lochnagar2_get_gpio_chan(priv, LN2_OP_GPIO);
9490548448bSCharles Keepax 	if (ret < 0) {
9500548448bSCharles Keepax 		dev_err(priv->dev, "Failed to get low channel: %d\n", ret);
9510548448bSCharles Keepax 		return ret;
9520548448bSCharles Keepax 	}
9530548448bSCharles Keepax 
9540548448bSCharles Keepax 	ret = lochnagar2_get_gpio_chan(priv, LN2_OP_GPIO | 0x1);
9550548448bSCharles Keepax 	if (ret < 0) {
9560548448bSCharles Keepax 		dev_err(priv->dev, "Failed to get high channel: %d\n", ret);
9570548448bSCharles Keepax 		return ret;
9580548448bSCharles Keepax 	}
9590548448bSCharles Keepax 
9600548448bSCharles Keepax 	return 0;
9610548448bSCharles Keepax }
9620548448bSCharles Keepax 
lochnagar_gpio_set_direction(struct pinctrl_dev * pctldev,struct pinctrl_gpio_range * range,unsigned int offset,bool input)9630548448bSCharles Keepax static int lochnagar_gpio_set_direction(struct pinctrl_dev *pctldev,
9640548448bSCharles Keepax 					struct pinctrl_gpio_range *range,
9650548448bSCharles Keepax 					unsigned int offset,
9660548448bSCharles Keepax 					bool input)
9670548448bSCharles Keepax {
9680548448bSCharles Keepax 	/* The GPIOs only support output */
9690548448bSCharles Keepax 	if (input)
9700548448bSCharles Keepax 		return -EINVAL;
9710548448bSCharles Keepax 
9720548448bSCharles Keepax 	return 0;
9730548448bSCharles Keepax }
9740548448bSCharles Keepax 
9750548448bSCharles Keepax static const struct pinmux_ops lochnagar_pin_mux_ops = {
9760548448bSCharles Keepax 	.get_functions_count = lochnagar_get_funcs_count,
9770548448bSCharles Keepax 	.get_function_name = lochnagar_get_func_name,
9780548448bSCharles Keepax 	.get_function_groups = lochnagar_get_func_groups,
9790548448bSCharles Keepax 	.set_mux = lochnagar_set_mux,
9800548448bSCharles Keepax 
9810548448bSCharles Keepax 	.gpio_request_enable = lochnagar_gpio_request,
9820548448bSCharles Keepax 	.gpio_set_direction = lochnagar_gpio_set_direction,
9830548448bSCharles Keepax 
9840548448bSCharles Keepax 	.strict = true,
9850548448bSCharles Keepax };
9860548448bSCharles Keepax 
lochnagar_aif_set_master(struct lochnagar_pin_priv * priv,unsigned int group_idx,bool master)9870548448bSCharles Keepax static int lochnagar_aif_set_master(struct lochnagar_pin_priv *priv,
9880548448bSCharles Keepax 				    unsigned int group_idx, bool master)
9890548448bSCharles Keepax {
9900548448bSCharles Keepax 	struct regmap *regmap = priv->lochnagar->regmap;
9910548448bSCharles Keepax 	const struct lochnagar_group *group = &priv->groups[group_idx];
9920548448bSCharles Keepax 	const struct lochnagar_aif *aif = group->priv;
9930548448bSCharles Keepax 	unsigned int val = 0;
9940548448bSCharles Keepax 	int ret;
9950548448bSCharles Keepax 
9960548448bSCharles Keepax 	if (group->type != LN_FTYPE_AIF)
9970548448bSCharles Keepax 		return -EINVAL;
9980548448bSCharles Keepax 
9990548448bSCharles Keepax 	if (!master)
10000548448bSCharles Keepax 		val = aif->master_mask;
10010548448bSCharles Keepax 
10020548448bSCharles Keepax 	dev_dbg(priv->dev, "Set AIF %s to %s\n",
10030548448bSCharles Keepax 		group->name, master ? "master" : "slave");
10040548448bSCharles Keepax 
10050548448bSCharles Keepax 	ret = regmap_update_bits(regmap, aif->ctrl_reg, aif->master_mask, val);
10060548448bSCharles Keepax 	if (ret) {
10070548448bSCharles Keepax 		dev_err(priv->dev, "Failed to set %s mode: %d\n",
10080548448bSCharles Keepax 			group->name, ret);
10090548448bSCharles Keepax 		return ret;
10100548448bSCharles Keepax 	}
10110548448bSCharles Keepax 
10120548448bSCharles Keepax 	return 0;
10130548448bSCharles Keepax }
10140548448bSCharles Keepax 
lochnagar_conf_group_set(struct pinctrl_dev * pctldev,unsigned int group_idx,unsigned long * configs,unsigned int num_configs)10150548448bSCharles Keepax static int lochnagar_conf_group_set(struct pinctrl_dev *pctldev,
10160548448bSCharles Keepax 				    unsigned int group_idx,
10170548448bSCharles Keepax 				    unsigned long *configs,
10180548448bSCharles Keepax 				    unsigned int num_configs)
10190548448bSCharles Keepax {
10200548448bSCharles Keepax 	struct lochnagar_pin_priv *priv = pinctrl_dev_get_drvdata(pctldev);
10210548448bSCharles Keepax 	int i, ret;
10220548448bSCharles Keepax 
10230548448bSCharles Keepax 	for (i = 0; i < num_configs; i++) {
10240548448bSCharles Keepax 		unsigned int param = pinconf_to_config_param(*configs);
10250548448bSCharles Keepax 
10260548448bSCharles Keepax 		switch (param) {
10270548448bSCharles Keepax 		case PIN_CONFIG_OUTPUT_ENABLE:
10280548448bSCharles Keepax 			ret = lochnagar_aif_set_master(priv, group_idx, true);
10290548448bSCharles Keepax 			if (ret)
10300548448bSCharles Keepax 				return ret;
10310548448bSCharles Keepax 			break;
10320548448bSCharles Keepax 		case PIN_CONFIG_INPUT_ENABLE:
10330548448bSCharles Keepax 			ret = lochnagar_aif_set_master(priv, group_idx, false);
10340548448bSCharles Keepax 			if (ret)
10350548448bSCharles Keepax 				return ret;
10360548448bSCharles Keepax 			break;
10370548448bSCharles Keepax 		default:
10380548448bSCharles Keepax 			return -ENOTSUPP;
10390548448bSCharles Keepax 		}
10400548448bSCharles Keepax 
10410548448bSCharles Keepax 		configs++;
10420548448bSCharles Keepax 	}
10430548448bSCharles Keepax 
10440548448bSCharles Keepax 	return 0;
10450548448bSCharles Keepax }
10460548448bSCharles Keepax 
10470548448bSCharles Keepax static const struct pinconf_ops lochnagar_pin_conf_ops = {
10480548448bSCharles Keepax 	.pin_config_group_set = lochnagar_conf_group_set,
10490548448bSCharles Keepax };
10500548448bSCharles Keepax 
10510548448bSCharles Keepax static const struct pinctrl_desc lochnagar_pin_desc = {
10520548448bSCharles Keepax 	.name = "lochnagar-pinctrl",
10530548448bSCharles Keepax 	.owner = THIS_MODULE,
10540548448bSCharles Keepax 
10550548448bSCharles Keepax 	.pctlops = &lochnagar_pin_group_ops,
10560548448bSCharles Keepax 	.pmxops = &lochnagar_pin_mux_ops,
10570548448bSCharles Keepax 	.confops = &lochnagar_pin_conf_ops,
10580548448bSCharles Keepax };
10590548448bSCharles Keepax 
lochnagar_gpio_set(struct gpio_chip * chip,unsigned int offset,int value)10600548448bSCharles Keepax static void lochnagar_gpio_set(struct gpio_chip *chip,
10610548448bSCharles Keepax 			       unsigned int offset, int value)
10620548448bSCharles Keepax {
10630548448bSCharles Keepax 	struct lochnagar_pin_priv *priv = gpiochip_get_data(chip);
10640548448bSCharles Keepax 	struct lochnagar *lochnagar = priv->lochnagar;
10650548448bSCharles Keepax 	const struct lochnagar_pin *pin = priv->pins[offset].drv_data;
10660548448bSCharles Keepax 	int ret;
10670548448bSCharles Keepax 
10680548448bSCharles Keepax 	value = !!value;
10690548448bSCharles Keepax 
10700548448bSCharles Keepax 	dev_dbg(priv->dev, "Set GPIO %s to %s\n",
10710548448bSCharles Keepax 		pin->name, value ? "high" : "low");
10720548448bSCharles Keepax 
10730548448bSCharles Keepax 	switch (pin->type) {
10740548448bSCharles Keepax 	case LN_PTYPE_MUX:
10750548448bSCharles Keepax 		value |= LN2_OP_GPIO;
10760548448bSCharles Keepax 
10770548448bSCharles Keepax 		ret = lochnagar_pin_set_mux(priv, pin, value);
10780548448bSCharles Keepax 		break;
10790548448bSCharles Keepax 	case LN_PTYPE_GPIO:
10800548448bSCharles Keepax 		if (pin->invert)
10810548448bSCharles Keepax 			value = !value;
10820548448bSCharles Keepax 
10830548448bSCharles Keepax 		ret = regmap_update_bits(lochnagar->regmap, pin->reg,
10840548448bSCharles Keepax 					 BIT(pin->shift), value << pin->shift);
10850548448bSCharles Keepax 		break;
10860548448bSCharles Keepax 	default:
10870548448bSCharles Keepax 		ret = -EINVAL;
10880548448bSCharles Keepax 		break;
10890548448bSCharles Keepax 	}
10900548448bSCharles Keepax 
10910548448bSCharles Keepax 	if (ret < 0)
10920548448bSCharles Keepax 		dev_err(chip->parent, "Failed to set %s value: %d\n",
10930548448bSCharles Keepax 			pin->name, ret);
10940548448bSCharles Keepax }
10950548448bSCharles Keepax 
lochnagar_gpio_direction_out(struct gpio_chip * chip,unsigned int offset,int value)10960548448bSCharles Keepax static int lochnagar_gpio_direction_out(struct gpio_chip *chip,
10970548448bSCharles Keepax 					unsigned int offset, int value)
10980548448bSCharles Keepax {
10990548448bSCharles Keepax 	lochnagar_gpio_set(chip, offset, value);
11000548448bSCharles Keepax 
1101*b679d6c0SBartosz Golaszewski 	return pinctrl_gpio_direction_output(chip, offset);
11020548448bSCharles Keepax }
11030548448bSCharles Keepax 
lochnagar_fill_func_groups(struct lochnagar_pin_priv * priv)11040548448bSCharles Keepax static int lochnagar_fill_func_groups(struct lochnagar_pin_priv *priv)
11050548448bSCharles Keepax {
11060548448bSCharles Keepax 	struct lochnagar_func_groups *funcs;
11070548448bSCharles Keepax 	int i;
11080548448bSCharles Keepax 
11090548448bSCharles Keepax 	for (i = 0; i < priv->ngroups; i++)
11100548448bSCharles Keepax 		priv->func_groups[priv->groups[i].type].ngroups++;
11110548448bSCharles Keepax 
11120548448bSCharles Keepax 	for (i = 0; i < LN_FTYPE_COUNT; i++) {
11130548448bSCharles Keepax 		funcs = &priv->func_groups[i];
11140548448bSCharles Keepax 
11150548448bSCharles Keepax 		if (!funcs->ngroups)
11160548448bSCharles Keepax 			continue;
11170548448bSCharles Keepax 
11180548448bSCharles Keepax 		funcs->groups = devm_kcalloc(priv->dev, funcs->ngroups,
11190548448bSCharles Keepax 					     sizeof(*funcs->groups),
11200548448bSCharles Keepax 					     GFP_KERNEL);
11210548448bSCharles Keepax 		if (!funcs->groups)
11220548448bSCharles Keepax 			return -ENOMEM;
11230548448bSCharles Keepax 
11240548448bSCharles Keepax 		funcs->ngroups = 0;
11250548448bSCharles Keepax 	}
11260548448bSCharles Keepax 
11270548448bSCharles Keepax 	for (i = 0; i < priv->ngroups; i++) {
11280548448bSCharles Keepax 		funcs = &priv->func_groups[priv->groups[i].type];
11290548448bSCharles Keepax 
11300548448bSCharles Keepax 		funcs->groups[funcs->ngroups++] = priv->groups[i].name;
11310548448bSCharles Keepax 	}
11320548448bSCharles Keepax 
11330548448bSCharles Keepax 	return 0;
11340548448bSCharles Keepax }
11350548448bSCharles Keepax 
lochnagar_pin_probe(struct platform_device * pdev)11360548448bSCharles Keepax static int lochnagar_pin_probe(struct platform_device *pdev)
11370548448bSCharles Keepax {
11380548448bSCharles Keepax 	struct lochnagar *lochnagar = dev_get_drvdata(pdev->dev.parent);
11390548448bSCharles Keepax 	struct lochnagar_pin_priv *priv;
11400548448bSCharles Keepax 	struct pinctrl_desc *desc;
11410548448bSCharles Keepax 	struct pinctrl_dev *pctl;
11420548448bSCharles Keepax 	struct device *dev = &pdev->dev;
11430548448bSCharles Keepax 	int ret;
11440548448bSCharles Keepax 
11450548448bSCharles Keepax 	priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
11460548448bSCharles Keepax 	if (!priv)
11470548448bSCharles Keepax 		return -ENOMEM;
11480548448bSCharles Keepax 
11490548448bSCharles Keepax 	priv->dev = dev;
11500548448bSCharles Keepax 	priv->lochnagar = lochnagar;
11510548448bSCharles Keepax 
11520548448bSCharles Keepax 	desc = devm_kzalloc(dev, sizeof(*desc), GFP_KERNEL);
11530548448bSCharles Keepax 	if (!desc)
11540548448bSCharles Keepax 		return -ENOMEM;
11550548448bSCharles Keepax 
11560548448bSCharles Keepax 	*desc = lochnagar_pin_desc;
11570548448bSCharles Keepax 
11580548448bSCharles Keepax 	priv->gpio_chip.label = dev_name(dev);
11590548448bSCharles Keepax 	priv->gpio_chip.request = gpiochip_generic_request;
11600548448bSCharles Keepax 	priv->gpio_chip.free = gpiochip_generic_free;
11610548448bSCharles Keepax 	priv->gpio_chip.direction_output = lochnagar_gpio_direction_out;
11620548448bSCharles Keepax 	priv->gpio_chip.set = lochnagar_gpio_set;
11630548448bSCharles Keepax 	priv->gpio_chip.can_sleep = true;
11640548448bSCharles Keepax 	priv->gpio_chip.parent = dev;
11650548448bSCharles Keepax 	priv->gpio_chip.base = -1;
11660548448bSCharles Keepax 
11670548448bSCharles Keepax 	switch (lochnagar->type) {
11680548448bSCharles Keepax 	case LOCHNAGAR1:
11690548448bSCharles Keepax 		priv->funcs = lochnagar1_funcs;
11700548448bSCharles Keepax 		priv->nfuncs = ARRAY_SIZE(lochnagar1_funcs);
11710548448bSCharles Keepax 		priv->pins = lochnagar1_pins;
11720548448bSCharles Keepax 		priv->npins = ARRAY_SIZE(lochnagar1_pins);
11730548448bSCharles Keepax 		priv->groups = lochnagar1_groups;
11740548448bSCharles Keepax 		priv->ngroups = ARRAY_SIZE(lochnagar1_groups);
11750548448bSCharles Keepax 
11760548448bSCharles Keepax 		priv->gpio_chip.ngpio = LOCHNAGAR1_PIN_NUM_GPIOS;
11770548448bSCharles Keepax 		break;
11780548448bSCharles Keepax 	case LOCHNAGAR2:
11790548448bSCharles Keepax 		priv->funcs = lochnagar2_funcs;
11800548448bSCharles Keepax 		priv->nfuncs = ARRAY_SIZE(lochnagar2_funcs);
11810548448bSCharles Keepax 		priv->pins = lochnagar2_pins;
11820548448bSCharles Keepax 		priv->npins = ARRAY_SIZE(lochnagar2_pins);
11830548448bSCharles Keepax 		priv->groups = lochnagar2_groups;
11840548448bSCharles Keepax 		priv->ngroups = ARRAY_SIZE(lochnagar2_groups);
11850548448bSCharles Keepax 
11860548448bSCharles Keepax 		priv->gpio_chip.ngpio = LOCHNAGAR2_PIN_NUM_GPIOS;
11870548448bSCharles Keepax 		break;
11880548448bSCharles Keepax 	default:
11890548448bSCharles Keepax 		dev_err(dev, "Unknown Lochnagar type: %d\n", lochnagar->type);
11900548448bSCharles Keepax 		return -EINVAL;
11910548448bSCharles Keepax 	}
11920548448bSCharles Keepax 
11930548448bSCharles Keepax 	ret = lochnagar_fill_func_groups(priv);
11940548448bSCharles Keepax 	if (ret < 0)
11950548448bSCharles Keepax 		return ret;
11960548448bSCharles Keepax 
11970548448bSCharles Keepax 	desc->pins = priv->pins;
11980548448bSCharles Keepax 	desc->npins = priv->npins;
11990548448bSCharles Keepax 
12000548448bSCharles Keepax 	pctl = devm_pinctrl_register(dev, desc, priv);
12010548448bSCharles Keepax 	if (IS_ERR(pctl)) {
12020548448bSCharles Keepax 		ret = PTR_ERR(pctl);
12030548448bSCharles Keepax 		dev_err(priv->dev, "Failed to register pinctrl: %d\n", ret);
12040548448bSCharles Keepax 		return ret;
12050548448bSCharles Keepax 	}
12060548448bSCharles Keepax 
12070548448bSCharles Keepax 	ret = devm_gpiochip_add_data(dev, &priv->gpio_chip, priv);
12080548448bSCharles Keepax 	if (ret < 0) {
12090548448bSCharles Keepax 		dev_err(&pdev->dev, "Failed to register gpiochip: %d\n", ret);
12100548448bSCharles Keepax 		return ret;
12110548448bSCharles Keepax 	}
12120548448bSCharles Keepax 
12130548448bSCharles Keepax 	return 0;
12140548448bSCharles Keepax }
12150548448bSCharles Keepax 
12160548448bSCharles Keepax static const struct of_device_id lochnagar_of_match[] = {
12170548448bSCharles Keepax 	{ .compatible = "cirrus,lochnagar-pinctrl" },
12180548448bSCharles Keepax 	{}
12190548448bSCharles Keepax };
12200548448bSCharles Keepax MODULE_DEVICE_TABLE(of, lochnagar_of_match);
12210548448bSCharles Keepax 
12220548448bSCharles Keepax static struct platform_driver lochnagar_pin_driver = {
12230548448bSCharles Keepax 	.driver = {
12240548448bSCharles Keepax 		.name = "lochnagar-pinctrl",
12250548448bSCharles Keepax 		.of_match_table = of_match_ptr(lochnagar_of_match),
12260548448bSCharles Keepax 	},
12270548448bSCharles Keepax 
12280548448bSCharles Keepax 	.probe = lochnagar_pin_probe,
12290548448bSCharles Keepax };
12300548448bSCharles Keepax module_platform_driver(lochnagar_pin_driver);
12310548448bSCharles Keepax 
12320548448bSCharles Keepax MODULE_AUTHOR("Charles Keepax <ckeepax@opensource.cirrus.com>");
12330548448bSCharles Keepax MODULE_DESCRIPTION("Pinctrl driver for Cirrus Logic Lochnagar Board");
12340548448bSCharles Keepax MODULE_LICENSE("GPL v2");
1235