xref: /linux/drivers/pinctrl/mvebu/pinctrl-dove.c (revision ba607b6238a1f418c45b9d7f73212bcc6922da53)
106763c74SThomas Petazzoni /*
206763c74SThomas Petazzoni  * Marvell Dove pinctrl driver based on mvebu pinctrl core
306763c74SThomas Petazzoni  *
406763c74SThomas Petazzoni  * Author: Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com>
506763c74SThomas Petazzoni  *
606763c74SThomas Petazzoni  * This program is free software; you can redistribute it and/or modify
706763c74SThomas Petazzoni  * it under the terms of the GNU General Public License as published by
806763c74SThomas Petazzoni  * the Free Software Foundation; either version 2 of the License, or
906763c74SThomas Petazzoni  * (at your option) any later version.
1006763c74SThomas Petazzoni  */
1106763c74SThomas Petazzoni 
1206763c74SThomas Petazzoni #include <linux/err.h>
1306763c74SThomas Petazzoni #include <linux/init.h>
1406763c74SThomas Petazzoni #include <linux/io.h>
1506763c74SThomas Petazzoni #include <linux/module.h>
1606763c74SThomas Petazzoni #include <linux/bitops.h>
1706763c74SThomas Petazzoni #include <linux/platform_device.h>
1806763c74SThomas Petazzoni #include <linux/clk.h>
1906763c74SThomas Petazzoni #include <linux/of.h>
2006763c74SThomas Petazzoni #include <linux/of_device.h>
2106763c74SThomas Petazzoni #include <linux/pinctrl/pinctrl.h>
2206763c74SThomas Petazzoni 
2306763c74SThomas Petazzoni #include "pinctrl-mvebu.h"
2406763c74SThomas Petazzoni 
2578f9f3b1SSebastian Hesselbarth #define DOVE_SB_REGS_VIRT_BASE		IOMEM(0xfde00000)
2678f9f3b1SSebastian Hesselbarth #define DOVE_MPP_VIRT_BASE		(DOVE_SB_REGS_VIRT_BASE + 0xd0200)
2706763c74SThomas Petazzoni #define DOVE_PMU_MPP_GENERAL_CTRL	(DOVE_MPP_VIRT_BASE + 0x10)
2806763c74SThomas Petazzoni #define  DOVE_AU0_AC97_SEL		BIT(16)
2978f9f3b1SSebastian Hesselbarth #define DOVE_GLOBAL_CONFIG_1		(DOVE_SB_REGS_VIRT_BASE + 0xe802C)
3006763c74SThomas Petazzoni #define  DOVE_TWSI_ENABLE_OPTION1	BIT(7)
3178f9f3b1SSebastian Hesselbarth #define DOVE_GLOBAL_CONFIG_2		(DOVE_SB_REGS_VIRT_BASE + 0xe8030)
3206763c74SThomas Petazzoni #define  DOVE_TWSI_ENABLE_OPTION2	BIT(20)
3306763c74SThomas Petazzoni #define  DOVE_TWSI_ENABLE_OPTION3	BIT(21)
3406763c74SThomas Petazzoni #define  DOVE_TWSI_OPTION3_GPIO		BIT(22)
3578f9f3b1SSebastian Hesselbarth #define DOVE_SSP_CTRL_STATUS_1		(DOVE_SB_REGS_VIRT_BASE + 0xe8034)
3606763c74SThomas Petazzoni #define  DOVE_SSP_ON_AU1		BIT(0)
3778f9f3b1SSebastian Hesselbarth #define DOVE_MPP_GENERAL_VIRT_BASE	(DOVE_SB_REGS_VIRT_BASE + 0xe803c)
3806763c74SThomas Petazzoni #define  DOVE_AU1_SPDIFO_GPIO_EN	BIT(1)
3906763c74SThomas Petazzoni #define  DOVE_NAND_GPIO_EN		BIT(0)
4078f9f3b1SSebastian Hesselbarth #define DOVE_GPIO_LO_VIRT_BASE		(DOVE_SB_REGS_VIRT_BASE + 0xd0400)
4106763c74SThomas Petazzoni #define DOVE_MPP_CTRL4_VIRT_BASE	(DOVE_GPIO_LO_VIRT_BASE + 0x40)
4206763c74SThomas Petazzoni #define  DOVE_SPI_GPIO_SEL		BIT(5)
4306763c74SThomas Petazzoni #define  DOVE_UART1_GPIO_SEL		BIT(4)
4406763c74SThomas Petazzoni #define  DOVE_AU1_GPIO_SEL		BIT(3)
4506763c74SThomas Petazzoni #define  DOVE_CAM_GPIO_SEL		BIT(2)
4606763c74SThomas Petazzoni #define  DOVE_SD1_GPIO_SEL		BIT(1)
4706763c74SThomas Petazzoni #define  DOVE_SD0_GPIO_SEL		BIT(0)
4806763c74SThomas Petazzoni 
4906763c74SThomas Petazzoni #define MPPS_PER_REG	8
5006763c74SThomas Petazzoni #define MPP_BITS	4
5106763c74SThomas Petazzoni #define MPP_MASK	0xf
5206763c74SThomas Petazzoni 
5306763c74SThomas Petazzoni #define CONFIG_PMU	BIT(4)
5406763c74SThomas Petazzoni 
5506763c74SThomas Petazzoni static int dove_pmu_mpp_ctrl_get(struct mvebu_mpp_ctrl *ctrl,
5606763c74SThomas Petazzoni 				 unsigned long *config)
5706763c74SThomas Petazzoni {
5806763c74SThomas Petazzoni 	unsigned off = (ctrl->pid / MPPS_PER_REG) * MPP_BITS;
5906763c74SThomas Petazzoni 	unsigned shift = (ctrl->pid % MPPS_PER_REG) * MPP_BITS;
6006763c74SThomas Petazzoni 	unsigned long pmu = readl(DOVE_PMU_MPP_GENERAL_CTRL);
6106763c74SThomas Petazzoni 	unsigned long mpp = readl(DOVE_MPP_VIRT_BASE + off);
6206763c74SThomas Petazzoni 
6306763c74SThomas Petazzoni 	if (pmu & (1 << ctrl->pid))
6406763c74SThomas Petazzoni 		*config = CONFIG_PMU;
6506763c74SThomas Petazzoni 	else
6606763c74SThomas Petazzoni 		*config = (mpp >> shift) & MPP_MASK;
6706763c74SThomas Petazzoni 	return 0;
6806763c74SThomas Petazzoni }
6906763c74SThomas Petazzoni 
7006763c74SThomas Petazzoni static int dove_pmu_mpp_ctrl_set(struct mvebu_mpp_ctrl *ctrl,
7106763c74SThomas Petazzoni 				 unsigned long config)
7206763c74SThomas Petazzoni {
7306763c74SThomas Petazzoni 	unsigned off = (ctrl->pid / MPPS_PER_REG) * MPP_BITS;
7406763c74SThomas Petazzoni 	unsigned shift = (ctrl->pid % MPPS_PER_REG) * MPP_BITS;
7506763c74SThomas Petazzoni 	unsigned long pmu = readl(DOVE_PMU_MPP_GENERAL_CTRL);
7606763c74SThomas Petazzoni 	unsigned long mpp = readl(DOVE_MPP_VIRT_BASE + off);
7706763c74SThomas Petazzoni 
7806763c74SThomas Petazzoni 	if (config == CONFIG_PMU)
7906763c74SThomas Petazzoni 		writel(pmu | (1 << ctrl->pid), DOVE_PMU_MPP_GENERAL_CTRL);
8006763c74SThomas Petazzoni 	else {
8106763c74SThomas Petazzoni 		writel(pmu & ~(1 << ctrl->pid), DOVE_PMU_MPP_GENERAL_CTRL);
8206763c74SThomas Petazzoni 		mpp &= ~(MPP_MASK << shift);
8306763c74SThomas Petazzoni 		mpp |= config << shift;
8406763c74SThomas Petazzoni 		writel(mpp, DOVE_MPP_VIRT_BASE + off);
8506763c74SThomas Petazzoni 	}
8606763c74SThomas Petazzoni 	return 0;
8706763c74SThomas Petazzoni }
8806763c74SThomas Petazzoni 
8906763c74SThomas Petazzoni static int dove_mpp4_ctrl_get(struct mvebu_mpp_ctrl *ctrl,
9006763c74SThomas Petazzoni 			      unsigned long *config)
9106763c74SThomas Petazzoni {
9206763c74SThomas Petazzoni 	unsigned long mpp4 = readl(DOVE_MPP_CTRL4_VIRT_BASE);
9306763c74SThomas Petazzoni 	unsigned long mask;
9406763c74SThomas Petazzoni 
9506763c74SThomas Petazzoni 	switch (ctrl->pid) {
9606763c74SThomas Petazzoni 	case 24: /* mpp_camera */
9706763c74SThomas Petazzoni 		mask = DOVE_CAM_GPIO_SEL;
9806763c74SThomas Petazzoni 		break;
9906763c74SThomas Petazzoni 	case 40: /* mpp_sdio0 */
10006763c74SThomas Petazzoni 		mask = DOVE_SD0_GPIO_SEL;
10106763c74SThomas Petazzoni 		break;
10206763c74SThomas Petazzoni 	case 46: /* mpp_sdio1 */
10306763c74SThomas Petazzoni 		mask = DOVE_SD1_GPIO_SEL;
10406763c74SThomas Petazzoni 		break;
10506763c74SThomas Petazzoni 	case 58: /* mpp_spi0 */
10606763c74SThomas Petazzoni 		mask = DOVE_SPI_GPIO_SEL;
10706763c74SThomas Petazzoni 		break;
10806763c74SThomas Petazzoni 	case 62: /* mpp_uart1 */
10906763c74SThomas Petazzoni 		mask = DOVE_UART1_GPIO_SEL;
11006763c74SThomas Petazzoni 		break;
11106763c74SThomas Petazzoni 	default:
11206763c74SThomas Petazzoni 		return -EINVAL;
11306763c74SThomas Petazzoni 	}
11406763c74SThomas Petazzoni 
11506763c74SThomas Petazzoni 	*config = ((mpp4 & mask) != 0);
11606763c74SThomas Petazzoni 
11706763c74SThomas Petazzoni 	return 0;
11806763c74SThomas Petazzoni }
11906763c74SThomas Petazzoni 
12006763c74SThomas Petazzoni static int dove_mpp4_ctrl_set(struct mvebu_mpp_ctrl *ctrl,
12106763c74SThomas Petazzoni 			      unsigned long config)
12206763c74SThomas Petazzoni {
12306763c74SThomas Petazzoni 	unsigned long mpp4 = readl(DOVE_MPP_CTRL4_VIRT_BASE);
12406763c74SThomas Petazzoni 	unsigned long mask;
12506763c74SThomas Petazzoni 
12606763c74SThomas Petazzoni 	switch (ctrl->pid) {
12706763c74SThomas Petazzoni 	case 24: /* mpp_camera */
12806763c74SThomas Petazzoni 		mask = DOVE_CAM_GPIO_SEL;
12906763c74SThomas Petazzoni 		break;
13006763c74SThomas Petazzoni 	case 40: /* mpp_sdio0 */
13106763c74SThomas Petazzoni 		mask = DOVE_SD0_GPIO_SEL;
13206763c74SThomas Petazzoni 		break;
13306763c74SThomas Petazzoni 	case 46: /* mpp_sdio1 */
13406763c74SThomas Petazzoni 		mask = DOVE_SD1_GPIO_SEL;
13506763c74SThomas Petazzoni 		break;
13606763c74SThomas Petazzoni 	case 58: /* mpp_spi0 */
13706763c74SThomas Petazzoni 		mask = DOVE_SPI_GPIO_SEL;
13806763c74SThomas Petazzoni 		break;
13906763c74SThomas Petazzoni 	case 62: /* mpp_uart1 */
14006763c74SThomas Petazzoni 		mask = DOVE_UART1_GPIO_SEL;
14106763c74SThomas Petazzoni 		break;
14206763c74SThomas Petazzoni 	default:
14306763c74SThomas Petazzoni 		return -EINVAL;
14406763c74SThomas Petazzoni 	}
14506763c74SThomas Petazzoni 
14606763c74SThomas Petazzoni 	mpp4 &= ~mask;
14706763c74SThomas Petazzoni 	if (config)
14806763c74SThomas Petazzoni 		mpp4 |= mask;
14906763c74SThomas Petazzoni 
15006763c74SThomas Petazzoni 	writel(mpp4, DOVE_MPP_CTRL4_VIRT_BASE);
15106763c74SThomas Petazzoni 
15206763c74SThomas Petazzoni 	return 0;
15306763c74SThomas Petazzoni }
15406763c74SThomas Petazzoni 
15506763c74SThomas Petazzoni static int dove_nand_ctrl_get(struct mvebu_mpp_ctrl *ctrl,
15606763c74SThomas Petazzoni 			      unsigned long *config)
15706763c74SThomas Petazzoni {
15806763c74SThomas Petazzoni 	unsigned long gmpp = readl(DOVE_MPP_GENERAL_VIRT_BASE);
15906763c74SThomas Petazzoni 
16006763c74SThomas Petazzoni 	*config = ((gmpp & DOVE_NAND_GPIO_EN) != 0);
16106763c74SThomas Petazzoni 
16206763c74SThomas Petazzoni 	return 0;
16306763c74SThomas Petazzoni }
16406763c74SThomas Petazzoni 
16506763c74SThomas Petazzoni static int dove_nand_ctrl_set(struct mvebu_mpp_ctrl *ctrl,
16606763c74SThomas Petazzoni 			      unsigned long config)
16706763c74SThomas Petazzoni {
16806763c74SThomas Petazzoni 	unsigned long gmpp = readl(DOVE_MPP_GENERAL_VIRT_BASE);
16906763c74SThomas Petazzoni 
17006763c74SThomas Petazzoni 	gmpp &= ~DOVE_NAND_GPIO_EN;
17106763c74SThomas Petazzoni 	if (config)
17206763c74SThomas Petazzoni 		gmpp |= DOVE_NAND_GPIO_EN;
17306763c74SThomas Petazzoni 
17406763c74SThomas Petazzoni 	writel(gmpp, DOVE_MPP_GENERAL_VIRT_BASE);
17506763c74SThomas Petazzoni 
17606763c74SThomas Petazzoni 	return 0;
17706763c74SThomas Petazzoni }
17806763c74SThomas Petazzoni 
17906763c74SThomas Petazzoni static int dove_audio0_ctrl_get(struct mvebu_mpp_ctrl *ctrl,
18006763c74SThomas Petazzoni 				unsigned long *config)
18106763c74SThomas Petazzoni {
18206763c74SThomas Petazzoni 	unsigned long pmu = readl(DOVE_PMU_MPP_GENERAL_CTRL);
18306763c74SThomas Petazzoni 
18406763c74SThomas Petazzoni 	*config = ((pmu & DOVE_AU0_AC97_SEL) != 0);
18506763c74SThomas Petazzoni 
18606763c74SThomas Petazzoni 	return 0;
18706763c74SThomas Petazzoni }
18806763c74SThomas Petazzoni 
18906763c74SThomas Petazzoni static int dove_audio0_ctrl_set(struct mvebu_mpp_ctrl *ctrl,
19006763c74SThomas Petazzoni 				unsigned long config)
19106763c74SThomas Petazzoni {
19206763c74SThomas Petazzoni 	unsigned long pmu = readl(DOVE_PMU_MPP_GENERAL_CTRL);
19306763c74SThomas Petazzoni 
19406763c74SThomas Petazzoni 	pmu &= ~DOVE_AU0_AC97_SEL;
19506763c74SThomas Petazzoni 	if (config)
19606763c74SThomas Petazzoni 		pmu |= DOVE_AU0_AC97_SEL;
19706763c74SThomas Petazzoni 	writel(pmu, DOVE_PMU_MPP_GENERAL_CTRL);
19806763c74SThomas Petazzoni 
19906763c74SThomas Petazzoni 	return 0;
20006763c74SThomas Petazzoni }
20106763c74SThomas Petazzoni 
20206763c74SThomas Petazzoni static int dove_audio1_ctrl_get(struct mvebu_mpp_ctrl *ctrl,
20306763c74SThomas Petazzoni 				unsigned long *config)
20406763c74SThomas Petazzoni {
20506763c74SThomas Petazzoni 	unsigned long mpp4 = readl(DOVE_MPP_CTRL4_VIRT_BASE);
20606763c74SThomas Petazzoni 	unsigned long sspc1 = readl(DOVE_SSP_CTRL_STATUS_1);
20706763c74SThomas Petazzoni 	unsigned long gmpp = readl(DOVE_MPP_GENERAL_VIRT_BASE);
20806763c74SThomas Petazzoni 	unsigned long gcfg2 = readl(DOVE_GLOBAL_CONFIG_2);
20906763c74SThomas Petazzoni 
21006763c74SThomas Petazzoni 	*config = 0;
21106763c74SThomas Petazzoni 	if (mpp4 & DOVE_AU1_GPIO_SEL)
21206763c74SThomas Petazzoni 		*config |= BIT(3);
21306763c74SThomas Petazzoni 	if (sspc1 & DOVE_SSP_ON_AU1)
21406763c74SThomas Petazzoni 		*config |= BIT(2);
21506763c74SThomas Petazzoni 	if (gmpp & DOVE_AU1_SPDIFO_GPIO_EN)
21606763c74SThomas Petazzoni 		*config |= BIT(1);
21706763c74SThomas Petazzoni 	if (gcfg2 & DOVE_TWSI_OPTION3_GPIO)
21806763c74SThomas Petazzoni 		*config |= BIT(0);
21906763c74SThomas Petazzoni 
22006763c74SThomas Petazzoni 	/* SSP/TWSI only if I2S1 not set*/
22106763c74SThomas Petazzoni 	if ((*config & BIT(3)) == 0)
22206763c74SThomas Petazzoni 		*config &= ~(BIT(2) | BIT(0));
22306763c74SThomas Petazzoni 	/* TWSI only if SPDIFO not set*/
22406763c74SThomas Petazzoni 	if ((*config & BIT(1)) == 0)
22506763c74SThomas Petazzoni 		*config &= ~BIT(0);
22606763c74SThomas Petazzoni 	return 0;
22706763c74SThomas Petazzoni }
22806763c74SThomas Petazzoni 
22906763c74SThomas Petazzoni static int dove_audio1_ctrl_set(struct mvebu_mpp_ctrl *ctrl,
23006763c74SThomas Petazzoni 				unsigned long config)
23106763c74SThomas Petazzoni {
23206763c74SThomas Petazzoni 	unsigned long mpp4 = readl(DOVE_MPP_CTRL4_VIRT_BASE);
23306763c74SThomas Petazzoni 	unsigned long sspc1 = readl(DOVE_SSP_CTRL_STATUS_1);
23406763c74SThomas Petazzoni 	unsigned long gmpp = readl(DOVE_MPP_GENERAL_VIRT_BASE);
23506763c74SThomas Petazzoni 	unsigned long gcfg2 = readl(DOVE_GLOBAL_CONFIG_2);
23606763c74SThomas Petazzoni 
23763ace077SAxel Lin 	/*
23863ace077SAxel Lin 	 * clear all audio1 related bits before configure
23963ace077SAxel Lin 	 */
24063ace077SAxel Lin 	gcfg2 &= ~DOVE_TWSI_OPTION3_GPIO;
24163ace077SAxel Lin 	gmpp &= ~DOVE_AU1_SPDIFO_GPIO_EN;
24263ace077SAxel Lin 	sspc1 &= ~DOVE_SSP_ON_AU1;
24363ace077SAxel Lin 	mpp4 &= ~DOVE_AU1_GPIO_SEL;
24463ace077SAxel Lin 
24506763c74SThomas Petazzoni 	if (config & BIT(0))
24606763c74SThomas Petazzoni 		gcfg2 |= DOVE_TWSI_OPTION3_GPIO;
24706763c74SThomas Petazzoni 	if (config & BIT(1))
24806763c74SThomas Petazzoni 		gmpp |= DOVE_AU1_SPDIFO_GPIO_EN;
24906763c74SThomas Petazzoni 	if (config & BIT(2))
25006763c74SThomas Petazzoni 		sspc1 |= DOVE_SSP_ON_AU1;
25106763c74SThomas Petazzoni 	if (config & BIT(3))
25206763c74SThomas Petazzoni 		mpp4 |= DOVE_AU1_GPIO_SEL;
25306763c74SThomas Petazzoni 
25406763c74SThomas Petazzoni 	writel(mpp4, DOVE_MPP_CTRL4_VIRT_BASE);
25506763c74SThomas Petazzoni 	writel(sspc1, DOVE_SSP_CTRL_STATUS_1);
25606763c74SThomas Petazzoni 	writel(gmpp, DOVE_MPP_GENERAL_VIRT_BASE);
25706763c74SThomas Petazzoni 	writel(gcfg2, DOVE_GLOBAL_CONFIG_2);
25806763c74SThomas Petazzoni 
25906763c74SThomas Petazzoni 	return 0;
26006763c74SThomas Petazzoni }
26106763c74SThomas Petazzoni 
26206763c74SThomas Petazzoni /* mpp[52:57] gpio pins depend heavily on current config;
26306763c74SThomas Petazzoni  * gpio_req does not try to mux in gpio capabilities to not
26406763c74SThomas Petazzoni  * break other functions. If you require all mpps as gpio
26506763c74SThomas Petazzoni  * enforce gpio setting by pinctrl mapping.
26606763c74SThomas Petazzoni  */
26706763c74SThomas Petazzoni static int dove_audio1_ctrl_gpio_req(struct mvebu_mpp_ctrl *ctrl, u8 pid)
26806763c74SThomas Petazzoni {
26906763c74SThomas Petazzoni 	unsigned long config;
27006763c74SThomas Petazzoni 
27106763c74SThomas Petazzoni 	dove_audio1_ctrl_get(ctrl, &config);
27206763c74SThomas Petazzoni 
27306763c74SThomas Petazzoni 	switch (config) {
27406763c74SThomas Petazzoni 	case 0x02: /* i2s1 : gpio[56:57] */
27506763c74SThomas Petazzoni 	case 0x0e: /* ssp  : gpio[56:57] */
27606763c74SThomas Petazzoni 		if (pid >= 56)
27706763c74SThomas Petazzoni 			return 0;
27806763c74SThomas Petazzoni 		return -ENOTSUPP;
27906763c74SThomas Petazzoni 	case 0x08: /* spdifo : gpio[52:55] */
28006763c74SThomas Petazzoni 	case 0x0b: /* twsi   : gpio[52:55] */
28106763c74SThomas Petazzoni 		if (pid <= 55)
28206763c74SThomas Petazzoni 			return 0;
28306763c74SThomas Petazzoni 		return -ENOTSUPP;
28406763c74SThomas Petazzoni 	case 0x0a: /* all gpio */
28506763c74SThomas Petazzoni 		return 0;
28606763c74SThomas Petazzoni 	/* 0x00 : i2s1/spdifo : no gpio */
28706763c74SThomas Petazzoni 	/* 0x0c : ssp/spdifo  : no gpio */
28806763c74SThomas Petazzoni 	/* 0x0f : ssp/twsi    : no gpio */
28906763c74SThomas Petazzoni 	}
29006763c74SThomas Petazzoni 	return -ENOTSUPP;
29106763c74SThomas Petazzoni }
29206763c74SThomas Petazzoni 
29306763c74SThomas Petazzoni /* mpp[52:57] has gpio pins capable of in and out */
29406763c74SThomas Petazzoni static int dove_audio1_ctrl_gpio_dir(struct mvebu_mpp_ctrl *ctrl, u8 pid,
29506763c74SThomas Petazzoni 				bool input)
29606763c74SThomas Petazzoni {
29706763c74SThomas Petazzoni 	if (pid < 52 || pid > 57)
29806763c74SThomas Petazzoni 		return -ENOTSUPP;
29906763c74SThomas Petazzoni 	return 0;
30006763c74SThomas Petazzoni }
30106763c74SThomas Petazzoni 
30206763c74SThomas Petazzoni static int dove_twsi_ctrl_get(struct mvebu_mpp_ctrl *ctrl,
30306763c74SThomas Petazzoni 			      unsigned long *config)
30406763c74SThomas Petazzoni {
30506763c74SThomas Petazzoni 	unsigned long gcfg1 = readl(DOVE_GLOBAL_CONFIG_1);
30606763c74SThomas Petazzoni 	unsigned long gcfg2 = readl(DOVE_GLOBAL_CONFIG_2);
30706763c74SThomas Petazzoni 
30806763c74SThomas Petazzoni 	*config = 0;
30906763c74SThomas Petazzoni 	if (gcfg1 & DOVE_TWSI_ENABLE_OPTION1)
31006763c74SThomas Petazzoni 		*config = 1;
31106763c74SThomas Petazzoni 	else if (gcfg2 & DOVE_TWSI_ENABLE_OPTION2)
31206763c74SThomas Petazzoni 		*config = 2;
31306763c74SThomas Petazzoni 	else if (gcfg2 & DOVE_TWSI_ENABLE_OPTION3)
31406763c74SThomas Petazzoni 		*config = 3;
31506763c74SThomas Petazzoni 
31606763c74SThomas Petazzoni 	return 0;
31706763c74SThomas Petazzoni }
31806763c74SThomas Petazzoni 
31906763c74SThomas Petazzoni static int dove_twsi_ctrl_set(struct mvebu_mpp_ctrl *ctrl,
32006763c74SThomas Petazzoni 				unsigned long config)
32106763c74SThomas Petazzoni {
32206763c74SThomas Petazzoni 	unsigned long gcfg1 = readl(DOVE_GLOBAL_CONFIG_1);
32306763c74SThomas Petazzoni 	unsigned long gcfg2 = readl(DOVE_GLOBAL_CONFIG_2);
32406763c74SThomas Petazzoni 
32506763c74SThomas Petazzoni 	gcfg1 &= ~DOVE_TWSI_ENABLE_OPTION1;
32606763c74SThomas Petazzoni 	gcfg2 &= ~(DOVE_TWSI_ENABLE_OPTION2 | DOVE_TWSI_ENABLE_OPTION2);
32706763c74SThomas Petazzoni 
32806763c74SThomas Petazzoni 	switch (config) {
32906763c74SThomas Petazzoni 	case 1:
33006763c74SThomas Petazzoni 		gcfg1 |= DOVE_TWSI_ENABLE_OPTION1;
33106763c74SThomas Petazzoni 		break;
33206763c74SThomas Petazzoni 	case 2:
33306763c74SThomas Petazzoni 		gcfg2 |= DOVE_TWSI_ENABLE_OPTION2;
33406763c74SThomas Petazzoni 		break;
33506763c74SThomas Petazzoni 	case 3:
33606763c74SThomas Petazzoni 		gcfg2 |= DOVE_TWSI_ENABLE_OPTION3;
33706763c74SThomas Petazzoni 		break;
33806763c74SThomas Petazzoni 	}
33906763c74SThomas Petazzoni 
34006763c74SThomas Petazzoni 	writel(gcfg1, DOVE_GLOBAL_CONFIG_1);
34106763c74SThomas Petazzoni 	writel(gcfg2, DOVE_GLOBAL_CONFIG_2);
34206763c74SThomas Petazzoni 
34306763c74SThomas Petazzoni 	return 0;
34406763c74SThomas Petazzoni }
34506763c74SThomas Petazzoni 
34606763c74SThomas Petazzoni static struct mvebu_mpp_ctrl dove_mpp_controls[] = {
34706763c74SThomas Petazzoni 	MPP_FUNC_CTRL(0, 0, "mpp0", dove_pmu_mpp_ctrl),
34806763c74SThomas Petazzoni 	MPP_FUNC_CTRL(1, 1, "mpp1", dove_pmu_mpp_ctrl),
34906763c74SThomas Petazzoni 	MPP_FUNC_CTRL(2, 2, "mpp2", dove_pmu_mpp_ctrl),
35006763c74SThomas Petazzoni 	MPP_FUNC_CTRL(3, 3, "mpp3", dove_pmu_mpp_ctrl),
35106763c74SThomas Petazzoni 	MPP_FUNC_CTRL(4, 4, "mpp4", dove_pmu_mpp_ctrl),
35206763c74SThomas Petazzoni 	MPP_FUNC_CTRL(5, 5, "mpp5", dove_pmu_mpp_ctrl),
35306763c74SThomas Petazzoni 	MPP_FUNC_CTRL(6, 6, "mpp6", dove_pmu_mpp_ctrl),
35406763c74SThomas Petazzoni 	MPP_FUNC_CTRL(7, 7, "mpp7", dove_pmu_mpp_ctrl),
35506763c74SThomas Petazzoni 	MPP_FUNC_CTRL(8, 8, "mpp8", dove_pmu_mpp_ctrl),
35606763c74SThomas Petazzoni 	MPP_FUNC_CTRL(9, 9, "mpp9", dove_pmu_mpp_ctrl),
35706763c74SThomas Petazzoni 	MPP_FUNC_CTRL(10, 10, "mpp10", dove_pmu_mpp_ctrl),
35806763c74SThomas Petazzoni 	MPP_FUNC_CTRL(11, 11, "mpp11", dove_pmu_mpp_ctrl),
35906763c74SThomas Petazzoni 	MPP_FUNC_CTRL(12, 12, "mpp12", dove_pmu_mpp_ctrl),
36006763c74SThomas Petazzoni 	MPP_FUNC_CTRL(13, 13, "mpp13", dove_pmu_mpp_ctrl),
36106763c74SThomas Petazzoni 	MPP_FUNC_CTRL(14, 14, "mpp14", dove_pmu_mpp_ctrl),
36206763c74SThomas Petazzoni 	MPP_FUNC_CTRL(15, 15, "mpp15", dove_pmu_mpp_ctrl),
36306763c74SThomas Petazzoni 	MPP_REG_CTRL(16, 23),
36406763c74SThomas Petazzoni 	MPP_FUNC_CTRL(24, 39, "mpp_camera", dove_mpp4_ctrl),
36506763c74SThomas Petazzoni 	MPP_FUNC_CTRL(40, 45, "mpp_sdio0", dove_mpp4_ctrl),
36606763c74SThomas Petazzoni 	MPP_FUNC_CTRL(46, 51, "mpp_sdio1", dove_mpp4_ctrl),
36706763c74SThomas Petazzoni 	MPP_FUNC_GPIO_CTRL(52, 57, "mpp_audio1", dove_audio1_ctrl),
36806763c74SThomas Petazzoni 	MPP_FUNC_CTRL(58, 61, "mpp_spi0", dove_mpp4_ctrl),
36906763c74SThomas Petazzoni 	MPP_FUNC_CTRL(62, 63, "mpp_uart1", dove_mpp4_ctrl),
37006763c74SThomas Petazzoni 	MPP_FUNC_CTRL(64, 71, "mpp_nand", dove_nand_ctrl),
37106763c74SThomas Petazzoni 	MPP_FUNC_CTRL(72, 72, "audio0", dove_audio0_ctrl),
37206763c74SThomas Petazzoni 	MPP_FUNC_CTRL(73, 73, "twsi", dove_twsi_ctrl),
37306763c74SThomas Petazzoni };
37406763c74SThomas Petazzoni 
37506763c74SThomas Petazzoni static struct mvebu_mpp_mode dove_mpp_modes[] = {
37606763c74SThomas Petazzoni 	MPP_MODE(0,
37706763c74SThomas Petazzoni 		MPP_FUNCTION(0x00, "gpio", NULL),
37806763c74SThomas Petazzoni 		MPP_FUNCTION(0x02, "uart2", "rts"),
37906763c74SThomas Petazzoni 		MPP_FUNCTION(0x03, "sdio0", "cd"),
38006763c74SThomas Petazzoni 		MPP_FUNCTION(0x0f, "lcd0", "pwm"),
38106763c74SThomas Petazzoni 		MPP_FUNCTION(0x10, "pmu", NULL)),
38206763c74SThomas Petazzoni 	MPP_MODE(1,
38306763c74SThomas Petazzoni 		MPP_FUNCTION(0x00, "gpio", NULL),
38406763c74SThomas Petazzoni 		MPP_FUNCTION(0x02, "uart2", "cts"),
38506763c74SThomas Petazzoni 		MPP_FUNCTION(0x03, "sdio0", "wp"),
38606763c74SThomas Petazzoni 		MPP_FUNCTION(0x0f, "lcd1", "pwm"),
38706763c74SThomas Petazzoni 		MPP_FUNCTION(0x10, "pmu", NULL)),
38806763c74SThomas Petazzoni 	MPP_MODE(2,
38906763c74SThomas Petazzoni 		MPP_FUNCTION(0x00, "gpio", NULL),
39006763c74SThomas Petazzoni 		MPP_FUNCTION(0x01, "sata", "prsnt"),
39106763c74SThomas Petazzoni 		MPP_FUNCTION(0x02, "uart2", "txd"),
39206763c74SThomas Petazzoni 		MPP_FUNCTION(0x03, "sdio0", "buspwr"),
39306763c74SThomas Petazzoni 		MPP_FUNCTION(0x04, "uart1", "rts"),
39406763c74SThomas Petazzoni 		MPP_FUNCTION(0x10, "pmu", NULL)),
39506763c74SThomas Petazzoni 	MPP_MODE(3,
39606763c74SThomas Petazzoni 		MPP_FUNCTION(0x00, "gpio", NULL),
39706763c74SThomas Petazzoni 		MPP_FUNCTION(0x01, "sata", "act"),
39806763c74SThomas Petazzoni 		MPP_FUNCTION(0x02, "uart2", "rxd"),
39906763c74SThomas Petazzoni 		MPP_FUNCTION(0x03, "sdio0", "ledctrl"),
40006763c74SThomas Petazzoni 		MPP_FUNCTION(0x04, "uart1", "cts"),
40106763c74SThomas Petazzoni 		MPP_FUNCTION(0x0f, "lcd-spi", "cs1"),
40206763c74SThomas Petazzoni 		MPP_FUNCTION(0x10, "pmu", NULL)),
40306763c74SThomas Petazzoni 	MPP_MODE(4,
40406763c74SThomas Petazzoni 		MPP_FUNCTION(0x00, "gpio", NULL),
40506763c74SThomas Petazzoni 		MPP_FUNCTION(0x02, "uart3", "rts"),
40606763c74SThomas Petazzoni 		MPP_FUNCTION(0x03, "sdio1", "cd"),
40706763c74SThomas Petazzoni 		MPP_FUNCTION(0x04, "spi1", "miso"),
40806763c74SThomas Petazzoni 		MPP_FUNCTION(0x10, "pmu", NULL)),
40906763c74SThomas Petazzoni 	MPP_MODE(5,
41006763c74SThomas Petazzoni 		MPP_FUNCTION(0x00, "gpio", NULL),
41106763c74SThomas Petazzoni 		MPP_FUNCTION(0x02, "uart3", "cts"),
41206763c74SThomas Petazzoni 		MPP_FUNCTION(0x03, "sdio1", "wp"),
41306763c74SThomas Petazzoni 		MPP_FUNCTION(0x04, "spi1", "cs"),
41406763c74SThomas Petazzoni 		MPP_FUNCTION(0x10, "pmu", NULL)),
41506763c74SThomas Petazzoni 	MPP_MODE(6,
41606763c74SThomas Petazzoni 		MPP_FUNCTION(0x00, "gpio", NULL),
41706763c74SThomas Petazzoni 		MPP_FUNCTION(0x02, "uart3", "txd"),
41806763c74SThomas Petazzoni 		MPP_FUNCTION(0x03, "sdio1", "buspwr"),
41906763c74SThomas Petazzoni 		MPP_FUNCTION(0x04, "spi1", "mosi"),
42006763c74SThomas Petazzoni 		MPP_FUNCTION(0x10, "pmu", NULL)),
42106763c74SThomas Petazzoni 	MPP_MODE(7,
42206763c74SThomas Petazzoni 		MPP_FUNCTION(0x00, "gpio", NULL),
42306763c74SThomas Petazzoni 		MPP_FUNCTION(0x02, "uart3", "rxd"),
42406763c74SThomas Petazzoni 		MPP_FUNCTION(0x03, "sdio1", "ledctrl"),
42506763c74SThomas Petazzoni 		MPP_FUNCTION(0x04, "spi1", "sck"),
42606763c74SThomas Petazzoni 		MPP_FUNCTION(0x10, "pmu", NULL)),
42706763c74SThomas Petazzoni 	MPP_MODE(8,
42806763c74SThomas Petazzoni 		MPP_FUNCTION(0x00, "gpio", NULL),
42906763c74SThomas Petazzoni 		MPP_FUNCTION(0x01, "watchdog", "rstout"),
43006763c74SThomas Petazzoni 		MPP_FUNCTION(0x10, "pmu", NULL)),
43106763c74SThomas Petazzoni 	MPP_MODE(9,
43206763c74SThomas Petazzoni 		MPP_FUNCTION(0x00, "gpio", NULL),
43306763c74SThomas Petazzoni 		MPP_FUNCTION(0x05, "pex1", "clkreq"),
43406763c74SThomas Petazzoni 		MPP_FUNCTION(0x10, "pmu", NULL)),
43506763c74SThomas Petazzoni 	MPP_MODE(10,
43606763c74SThomas Petazzoni 		MPP_FUNCTION(0x00, "gpio", NULL),
43706763c74SThomas Petazzoni 		MPP_FUNCTION(0x05, "ssp", "sclk"),
43806763c74SThomas Petazzoni 		MPP_FUNCTION(0x10, "pmu", NULL)),
43906763c74SThomas Petazzoni 	MPP_MODE(11,
44006763c74SThomas Petazzoni 		MPP_FUNCTION(0x00, "gpio", NULL),
44106763c74SThomas Petazzoni 		MPP_FUNCTION(0x01, "sata", "prsnt"),
44206763c74SThomas Petazzoni 		MPP_FUNCTION(0x02, "sata-1", "act"),
44306763c74SThomas Petazzoni 		MPP_FUNCTION(0x03, "sdio0", "ledctrl"),
44406763c74SThomas Petazzoni 		MPP_FUNCTION(0x04, "sdio1", "ledctrl"),
44506763c74SThomas Petazzoni 		MPP_FUNCTION(0x05, "pex0", "clkreq"),
44606763c74SThomas Petazzoni 		MPP_FUNCTION(0x10, "pmu", NULL)),
44706763c74SThomas Petazzoni 	MPP_MODE(12,
44806763c74SThomas Petazzoni 		MPP_FUNCTION(0x00, "gpio", NULL),
44906763c74SThomas Petazzoni 		MPP_FUNCTION(0x01, "sata", "act"),
45006763c74SThomas Petazzoni 		MPP_FUNCTION(0x02, "uart2", "rts"),
45106763c74SThomas Petazzoni 		MPP_FUNCTION(0x03, "audio0", "extclk"),
45206763c74SThomas Petazzoni 		MPP_FUNCTION(0x04, "sdio1", "cd"),
45306763c74SThomas Petazzoni 		MPP_FUNCTION(0x10, "pmu", NULL)),
45406763c74SThomas Petazzoni 	MPP_MODE(13,
45506763c74SThomas Petazzoni 		MPP_FUNCTION(0x00, "gpio", NULL),
45606763c74SThomas Petazzoni 		MPP_FUNCTION(0x02, "uart2", "cts"),
45706763c74SThomas Petazzoni 		MPP_FUNCTION(0x03, "audio1", "extclk"),
45806763c74SThomas Petazzoni 		MPP_FUNCTION(0x04, "sdio1", "wp"),
45906763c74SThomas Petazzoni 		MPP_FUNCTION(0x05, "ssp", "extclk"),
46006763c74SThomas Petazzoni 		MPP_FUNCTION(0x10, "pmu", NULL)),
46106763c74SThomas Petazzoni 	MPP_MODE(14,
46206763c74SThomas Petazzoni 		MPP_FUNCTION(0x00, "gpio", NULL),
46306763c74SThomas Petazzoni 		MPP_FUNCTION(0x02, "uart2", "txd"),
46406763c74SThomas Petazzoni 		MPP_FUNCTION(0x04, "sdio1", "buspwr"),
46506763c74SThomas Petazzoni 		MPP_FUNCTION(0x05, "ssp", "rxd"),
46606763c74SThomas Petazzoni 		MPP_FUNCTION(0x10, "pmu", NULL)),
46706763c74SThomas Petazzoni 	MPP_MODE(15,
46806763c74SThomas Petazzoni 		MPP_FUNCTION(0x00, "gpio", NULL),
46906763c74SThomas Petazzoni 		MPP_FUNCTION(0x02, "uart2", "rxd"),
47006763c74SThomas Petazzoni 		MPP_FUNCTION(0x04, "sdio1", "ledctrl"),
47106763c74SThomas Petazzoni 		MPP_FUNCTION(0x05, "ssp", "sfrm"),
47206763c74SThomas Petazzoni 		MPP_FUNCTION(0x10, "pmu", NULL)),
47306763c74SThomas Petazzoni 	MPP_MODE(16,
47406763c74SThomas Petazzoni 		MPP_FUNCTION(0x00, "gpio", NULL),
47506763c74SThomas Petazzoni 		MPP_FUNCTION(0x02, "uart3", "rts"),
47606763c74SThomas Petazzoni 		MPP_FUNCTION(0x03, "sdio0", "cd"),
47706763c74SThomas Petazzoni 		MPP_FUNCTION(0x04, "lcd-spi", "cs1"),
47806763c74SThomas Petazzoni 		MPP_FUNCTION(0x05, "ac97", "sdi1")),
47906763c74SThomas Petazzoni 	MPP_MODE(17,
48006763c74SThomas Petazzoni 		MPP_FUNCTION(0x00, "gpio", NULL),
48106763c74SThomas Petazzoni 		MPP_FUNCTION(0x01, "ac97-1", "sysclko"),
48206763c74SThomas Petazzoni 		MPP_FUNCTION(0x02, "uart3", "cts"),
48306763c74SThomas Petazzoni 		MPP_FUNCTION(0x03, "sdio0", "wp"),
48406763c74SThomas Petazzoni 		MPP_FUNCTION(0x04, "twsi", "sda"),
48506763c74SThomas Petazzoni 		MPP_FUNCTION(0x05, "ac97", "sdi2")),
48606763c74SThomas Petazzoni 	MPP_MODE(18,
48706763c74SThomas Petazzoni 		MPP_FUNCTION(0x00, "gpio", NULL),
48806763c74SThomas Petazzoni 		MPP_FUNCTION(0x02, "uart3", "txd"),
48906763c74SThomas Petazzoni 		MPP_FUNCTION(0x03, "sdio0", "buspwr"),
49006763c74SThomas Petazzoni 		MPP_FUNCTION(0x04, "lcd0", "pwm"),
49106763c74SThomas Petazzoni 		MPP_FUNCTION(0x05, "ac97", "sdi3")),
49206763c74SThomas Petazzoni 	MPP_MODE(19,
49306763c74SThomas Petazzoni 		MPP_FUNCTION(0x00, "gpio", NULL),
49406763c74SThomas Petazzoni 		MPP_FUNCTION(0x02, "uart3", "rxd"),
49506763c74SThomas Petazzoni 		MPP_FUNCTION(0x03, "sdio0", "ledctrl"),
49606763c74SThomas Petazzoni 		MPP_FUNCTION(0x04, "twsi", "sck")),
49706763c74SThomas Petazzoni 	MPP_MODE(20,
49806763c74SThomas Petazzoni 		MPP_FUNCTION(0x00, "gpio", NULL),
49906763c74SThomas Petazzoni 		MPP_FUNCTION(0x01, "ac97", "sysclko"),
50006763c74SThomas Petazzoni 		MPP_FUNCTION(0x02, "lcd-spi", "miso"),
50106763c74SThomas Petazzoni 		MPP_FUNCTION(0x03, "sdio1", "cd"),
50206763c74SThomas Petazzoni 		MPP_FUNCTION(0x05, "sdio0", "cd"),
50306763c74SThomas Petazzoni 		MPP_FUNCTION(0x06, "spi1", "miso")),
50406763c74SThomas Petazzoni 	MPP_MODE(21,
50506763c74SThomas Petazzoni 		MPP_FUNCTION(0x00, "gpio", NULL),
50606763c74SThomas Petazzoni 		MPP_FUNCTION(0x01, "uart1", "rts"),
50706763c74SThomas Petazzoni 		MPP_FUNCTION(0x02, "lcd-spi", "cs0"),
50806763c74SThomas Petazzoni 		MPP_FUNCTION(0x03, "sdio1", "wp"),
50906763c74SThomas Petazzoni 		MPP_FUNCTION(0x04, "ssp", "sfrm"),
51006763c74SThomas Petazzoni 		MPP_FUNCTION(0x05, "sdio0", "wp"),
51106763c74SThomas Petazzoni 		MPP_FUNCTION(0x06, "spi1", "cs")),
51206763c74SThomas Petazzoni 	MPP_MODE(22,
51306763c74SThomas Petazzoni 		MPP_FUNCTION(0x00, "gpio", NULL),
51406763c74SThomas Petazzoni 		MPP_FUNCTION(0x01, "uart1", "cts"),
51506763c74SThomas Petazzoni 		MPP_FUNCTION(0x02, "lcd-spi", "mosi"),
51606763c74SThomas Petazzoni 		MPP_FUNCTION(0x03, "sdio1", "buspwr"),
51706763c74SThomas Petazzoni 		MPP_FUNCTION(0x04, "ssp", "txd"),
51806763c74SThomas Petazzoni 		MPP_FUNCTION(0x05, "sdio0", "buspwr"),
51906763c74SThomas Petazzoni 		MPP_FUNCTION(0x06, "spi1", "mosi")),
52006763c74SThomas Petazzoni 	MPP_MODE(23,
52106763c74SThomas Petazzoni 		MPP_FUNCTION(0x00, "gpio", NULL),
52206763c74SThomas Petazzoni 		MPP_FUNCTION(0x02, "lcd-spi", "sck"),
52306763c74SThomas Petazzoni 		MPP_FUNCTION(0x03, "sdio1", "ledctrl"),
52406763c74SThomas Petazzoni 		MPP_FUNCTION(0x04, "ssp", "sclk"),
52506763c74SThomas Petazzoni 		MPP_FUNCTION(0x05, "sdio0", "ledctrl"),
52606763c74SThomas Petazzoni 		MPP_FUNCTION(0x06, "spi1", "sck")),
52706763c74SThomas Petazzoni 	MPP_MODE(24,
52806763c74SThomas Petazzoni 		MPP_FUNCTION(0x00, "camera", NULL),
52906763c74SThomas Petazzoni 		MPP_FUNCTION(0x01, "gpio", NULL)),
53006763c74SThomas Petazzoni 	MPP_MODE(40,
53106763c74SThomas Petazzoni 		MPP_FUNCTION(0x00, "sdio0", NULL),
53206763c74SThomas Petazzoni 		MPP_FUNCTION(0x01, "gpio", NULL)),
53306763c74SThomas Petazzoni 	MPP_MODE(46,
53406763c74SThomas Petazzoni 		MPP_FUNCTION(0x00, "sdio1", NULL),
53506763c74SThomas Petazzoni 		MPP_FUNCTION(0x01, "gpio", NULL)),
53606763c74SThomas Petazzoni 	MPP_MODE(52,
53706763c74SThomas Petazzoni 		MPP_FUNCTION(0x00, "i2s1/spdifo", NULL),
53806763c74SThomas Petazzoni 		MPP_FUNCTION(0x02, "i2s1", NULL),
53906763c74SThomas Petazzoni 		MPP_FUNCTION(0x08, "spdifo", NULL),
54006763c74SThomas Petazzoni 		MPP_FUNCTION(0x0a, "gpio", NULL),
54106763c74SThomas Petazzoni 		MPP_FUNCTION(0x0b, "twsi", NULL),
54206763c74SThomas Petazzoni 		MPP_FUNCTION(0x0c, "ssp/spdifo", NULL),
54306763c74SThomas Petazzoni 		MPP_FUNCTION(0x0e, "ssp", NULL),
54406763c74SThomas Petazzoni 		MPP_FUNCTION(0x0f, "ssp/twsi", NULL)),
54506763c74SThomas Petazzoni 	MPP_MODE(58,
54606763c74SThomas Petazzoni 		MPP_FUNCTION(0x00, "spi0", NULL),
54706763c74SThomas Petazzoni 		MPP_FUNCTION(0x01, "gpio", NULL)),
54806763c74SThomas Petazzoni 	MPP_MODE(62,
54906763c74SThomas Petazzoni 		MPP_FUNCTION(0x00, "uart1", NULL),
55006763c74SThomas Petazzoni 		MPP_FUNCTION(0x01, "gpio", NULL)),
55106763c74SThomas Petazzoni 	MPP_MODE(64,
55206763c74SThomas Petazzoni 		MPP_FUNCTION(0x00, "nand", NULL),
55306763c74SThomas Petazzoni 		MPP_FUNCTION(0x01, "gpo", NULL)),
55406763c74SThomas Petazzoni 	MPP_MODE(72,
55506763c74SThomas Petazzoni 		MPP_FUNCTION(0x00, "i2s", NULL),
55606763c74SThomas Petazzoni 		MPP_FUNCTION(0x01, "ac97", NULL)),
55706763c74SThomas Petazzoni 	MPP_MODE(73,
55806763c74SThomas Petazzoni 		MPP_FUNCTION(0x00, "twsi-none", NULL),
55906763c74SThomas Petazzoni 		MPP_FUNCTION(0x01, "twsi-opt1", NULL),
56006763c74SThomas Petazzoni 		MPP_FUNCTION(0x02, "twsi-opt2", NULL),
56106763c74SThomas Petazzoni 		MPP_FUNCTION(0x03, "twsi-opt3", NULL)),
56206763c74SThomas Petazzoni };
56306763c74SThomas Petazzoni 
56406763c74SThomas Petazzoni static struct pinctrl_gpio_range dove_mpp_gpio_ranges[] = {
56506763c74SThomas Petazzoni 	MPP_GPIO_RANGE(0,  0,  0, 32),
56606763c74SThomas Petazzoni 	MPP_GPIO_RANGE(1, 32, 32, 32),
56706763c74SThomas Petazzoni 	MPP_GPIO_RANGE(2, 64, 64,  8),
56806763c74SThomas Petazzoni };
56906763c74SThomas Petazzoni 
57006763c74SThomas Petazzoni static struct mvebu_pinctrl_soc_info dove_pinctrl_info = {
57106763c74SThomas Petazzoni 	.controls = dove_mpp_controls,
57206763c74SThomas Petazzoni 	.ncontrols = ARRAY_SIZE(dove_mpp_controls),
57306763c74SThomas Petazzoni 	.modes = dove_mpp_modes,
57406763c74SThomas Petazzoni 	.nmodes = ARRAY_SIZE(dove_mpp_modes),
57506763c74SThomas Petazzoni 	.gpioranges = dove_mpp_gpio_ranges,
57606763c74SThomas Petazzoni 	.ngpioranges = ARRAY_SIZE(dove_mpp_gpio_ranges),
57706763c74SThomas Petazzoni 	.variant = 0,
57806763c74SThomas Petazzoni };
57906763c74SThomas Petazzoni 
58006763c74SThomas Petazzoni static struct clk *clk;
58106763c74SThomas Petazzoni 
58206763c74SThomas Petazzoni static struct of_device_id dove_pinctrl_of_match[] __devinitdata = {
58306763c74SThomas Petazzoni 	{ .compatible = "marvell,dove-pinctrl", .data = &dove_pinctrl_info },
58406763c74SThomas Petazzoni 	{ }
58506763c74SThomas Petazzoni };
58606763c74SThomas Petazzoni 
58706763c74SThomas Petazzoni static int __devinit dove_pinctrl_probe(struct platform_device *pdev)
58806763c74SThomas Petazzoni {
58906763c74SThomas Petazzoni 	const struct of_device_id *match =
59006763c74SThomas Petazzoni 		of_match_device(dove_pinctrl_of_match, &pdev->dev);
59106763c74SThomas Petazzoni 	pdev->dev.platform_data = match->data;
59206763c74SThomas Petazzoni 
59306763c74SThomas Petazzoni 	/*
59406763c74SThomas Petazzoni 	 * General MPP Configuration Register is part of pdma registers.
59506763c74SThomas Petazzoni 	 * grab clk to make sure it is ticking.
59606763c74SThomas Petazzoni 	 */
59706763c74SThomas Petazzoni 	clk = devm_clk_get(&pdev->dev, NULL);
598*ba607b62SSebastian Hesselbarth 	if (IS_ERR(clk)) {
599*ba607b62SSebastian Hesselbarth 		dev_err(&pdev->dev, "Unable to get pdma clock");
600*ba607b62SSebastian Hesselbarth 		return PTR_RET(clk);
601*ba607b62SSebastian Hesselbarth 	}
60206763c74SThomas Petazzoni 	clk_prepare_enable(clk);
60306763c74SThomas Petazzoni 
60406763c74SThomas Petazzoni 	return mvebu_pinctrl_probe(pdev);
60506763c74SThomas Petazzoni }
60606763c74SThomas Petazzoni 
60706763c74SThomas Petazzoni static int __devexit dove_pinctrl_remove(struct platform_device *pdev)
60806763c74SThomas Petazzoni {
60906763c74SThomas Petazzoni 	int ret;
61006763c74SThomas Petazzoni 
61106763c74SThomas Petazzoni 	ret = mvebu_pinctrl_remove(pdev);
61206763c74SThomas Petazzoni 	if (!IS_ERR(clk))
61306763c74SThomas Petazzoni 		clk_disable_unprepare(clk);
61406763c74SThomas Petazzoni 	return ret;
61506763c74SThomas Petazzoni }
61606763c74SThomas Petazzoni 
61706763c74SThomas Petazzoni static struct platform_driver dove_pinctrl_driver = {
61806763c74SThomas Petazzoni 	.driver = {
61906763c74SThomas Petazzoni 		.name = "dove-pinctrl",
62006763c74SThomas Petazzoni 		.owner = THIS_MODULE,
62106763c74SThomas Petazzoni 		.of_match_table = of_match_ptr(dove_pinctrl_of_match),
62206763c74SThomas Petazzoni 	},
62306763c74SThomas Petazzoni 	.probe = dove_pinctrl_probe,
62406763c74SThomas Petazzoni 	.remove = __devexit_p(dove_pinctrl_remove),
62506763c74SThomas Petazzoni };
62606763c74SThomas Petazzoni 
62706763c74SThomas Petazzoni module_platform_driver(dove_pinctrl_driver);
62806763c74SThomas Petazzoni 
62906763c74SThomas Petazzoni MODULE_AUTHOR("Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com>");
63006763c74SThomas Petazzoni MODULE_DESCRIPTION("Marvell Dove pinctrl driver");
63106763c74SThomas Petazzoni MODULE_LICENSE("GPL v2");
632