Skip to contentSkip to conversation

Add NPCM7xx patches to dev-5.8

PATCH In review Tomer Maimon 2 participants 19 messages Jan 13, 2021 – Jan 15, 2021

Subsystems (8)
lore
Share & tools
lore
author maintainer
#1 lore raw

PATCH v3 1/12 clk: npcm7xx: add read only flag to divider clocks

In reply to Tomer Maimon

Add read only flag to all divider clocks except
SPI3 clock.

---
 drivers/clk/clk-npcm7xx.c | 70 +++++++++++++++++++++------------------
 1 file changed, 38 insertions(+), 32 deletions(-)
drivers/clk/clk-npcm7xx.c +38 -32
index 27a86b7a34db..bf721ec2bbc6 100644
@@ -370,67 +370,73 @@ static const struct npcm7xx_clk_div_fixed_data npcm7xx_divs_fx[] __initconst = {
 
 /* configurable dividers: */
 static const struct npcm7xx_clk_div_data npcm7xx_divs[] __initconst = {
-	{NPCM7XX_CLKDIV1, 28, 3, NPCM7XX_CLK_S_ADC,
-	NPCM7XX_CLK_S_TIMER, CLK_DIVIDER_POWER_OF_TWO, 0, NPCM7XX_CLK_ADC},
+	{NPCM7XX_CLKDIV1, 28, 3, NPCM7XX_CLK_S_ADC, NPCM7XX_CLK_S_TIMER,
+		CLK_DIVIDER_READ_ONLY | CLK_DIVIDER_POWER_OF_TWO, 0,
+		NPCM7XX_CLK_ADC},
 	/*30-28 ADCCKDIV*/
-	{NPCM7XX_CLKDIV1, 26, 2, NPCM7XX_CLK_S_AHB,
-	NPCM7XX_CLK_S_AXI, 0, CLK_IS_CRITICAL, NPCM7XX_CLK_AHB},
+	{NPCM7XX_CLKDIV1, 26, 2, NPCM7XX_CLK_S_AHB, NPCM7XX_CLK_S_AXI,
+		CLK_DIVIDER_READ_ONLY, CLK_IS_CRITICAL, NPCM7XX_CLK_AHB},
 	/*27-26 CLK4DIV*/
 	{NPCM7XX_CLKDIV1, 21, 5, NPCM7XX_CLK_S_TIMER,
-	NPCM7XX_CLK_S_TIM_MUX, 0, 0, NPCM7XX_CLK_TIMER},
+	NPCM7XX_CLK_S_TIM_MUX, CLK_DIVIDER_READ_ONLY, 0, NPCM7XX_CLK_TIMER},
 	/*25-21 TIMCKDIV*/
 	{NPCM7XX_CLKDIV1, 16, 5, NPCM7XX_CLK_S_UART,
-	NPCM7XX_CLK_S_UART_MUX, 0, 0, NPCM7XX_CLK_UART},
+	NPCM7XX_CLK_S_UART_MUX, CLK_DIVIDER_READ_ONLY, 0, NPCM7XX_CLK_UART},
 	/*20-16 UARTDIV*/
 	{NPCM7XX_CLKDIV1, 11, 5, NPCM7XX_CLK_S_MMC,
-	NPCM7XX_CLK_S_SD_MUX, 0, 0, NPCM7XX_CLK_MMC},
+	NPCM7XX_CLK_S_SD_MUX, CLK_DIVIDER_READ_ONLY, 0, NPCM7XX_CLK_MMC},
 	/*15-11 MMCCKDIV*/
 	{NPCM7XX_CLKDIV1, 6, 5, NPCM7XX_CLK_S_SPI3,
 	NPCM7XX_CLK_S_AHB, 0, 0, NPCM7XX_CLK_SPI3},
 	/*10-6 AHB3CKDIV*/
 	{NPCM7XX_CLKDIV1, 2, 4, NPCM7XX_CLK_S_PCI,
-	NPCM7XX_CLK_S_GFX_MUX, 0, 0, NPCM7XX_CLK_PCI},
+	NPCM7XX_CLK_S_GFX_MUX, CLK_DIVIDER_READ_ONLY, 0, NPCM7XX_CLK_PCI},
 	/*5-2 PCICKDIV*/
-	{NPCM7XX_CLKDIV1, 0, 1, NPCM7XX_CLK_S_AXI,
-	NPCM7XX_CLK_S_CPU_MUX, CLK_DIVIDER_POWER_OF_TWO, CLK_IS_CRITICAL,
-	NPCM7XX_CLK_AXI},/*0 CLK2DIV*/
+	{NPCM7XX_CLKDIV1, 0, 1, NPCM7XX_CLK_S_AXI, NPCM7XX_CLK_S_CPU_MUX,
+		CLK_DIVIDER_READ_ONLY | CLK_DIVIDER_POWER_OF_TWO,
+		CLK_IS_CRITICAL, NPCM7XX_CLK_AXI},/*0 CLK2DIV*/
 
-	{NPCM7XX_CLKDIV2, 30, 2, NPCM7XX_CLK_S_APB4,
-	NPCM7XX_CLK_S_AHB, CLK_DIVIDER_POWER_OF_TWO, 0, NPCM7XX_CLK_APB4},
+	{NPCM7XX_CLKDIV2, 30, 2, NPCM7XX_CLK_S_APB4, NPCM7XX_CLK_S_AHB,
+		CLK_DIVIDER_READ_ONLY| CLK_DIVIDER_POWER_OF_TWO, 0,
+		NPCM7XX_CLK_APB4},
 	/*31-30 APB4CKDIV*/
-	{NPCM7XX_CLKDIV2, 28, 2, NPCM7XX_CLK_S_APB3,
-	NPCM7XX_CLK_S_AHB, CLK_DIVIDER_POWER_OF_TWO, 0, NPCM7XX_CLK_APB3},
+	{NPCM7XX_CLKDIV2, 28, 2, NPCM7XX_CLK_S_APB3, NPCM7XX_CLK_S_AHB,
+		CLK_DIVIDER_READ_ONLY| CLK_DIVIDER_POWER_OF_TWO, 0,
+		NPCM7XX_CLK_APB3},
 	/*29-28 APB3CKDIV*/
-	{NPCM7XX_CLKDIV2, 26, 2, NPCM7XX_CLK_S_APB2,
-	NPCM7XX_CLK_S_AHB, CLK_DIVIDER_POWER_OF_TWO, 0, NPCM7XX_CLK_APB2},
+	{NPCM7XX_CLKDIV2, 26, 2, NPCM7XX_CLK_S_APB2, NPCM7XX_CLK_S_AHB,
+		CLK_DIVIDER_READ_ONLY | CLK_DIVIDER_POWER_OF_TWO, 0,
+		NPCM7XX_CLK_APB2},
 	/*27-26 APB2CKDIV*/
-	{NPCM7XX_CLKDIV2, 24, 2, NPCM7XX_CLK_S_APB1,
-	NPCM7XX_CLK_S_AHB, CLK_DIVIDER_POWER_OF_TWO, 0, NPCM7XX_CLK_APB1},
+	{NPCM7XX_CLKDIV2, 24, 2, NPCM7XX_CLK_S_APB1, NPCM7XX_CLK_S_AHB,
+		CLK_DIVIDER_READ_ONLY | CLK_DIVIDER_POWER_OF_TWO, 0,
+		NPCM7XX_CLK_APB1},
 	/*25-24 APB1CKDIV*/
-	{NPCM7XX_CLKDIV2, 22, 2, NPCM7XX_CLK_S_APB5,
-	NPCM7XX_CLK_S_AHB, CLK_DIVIDER_POWER_OF_TWO, 0, NPCM7XX_CLK_APB5},
+	{NPCM7XX_CLKDIV2, 22, 2, NPCM7XX_CLK_S_APB5, NPCM7XX_CLK_S_AHB,
+		CLK_DIVIDER_READ_ONLY | CLK_DIVIDER_POWER_OF_TWO, 0,
+		NPCM7XX_CLK_APB5},
 	/*23-22 APB5CKDIV*/
-	{NPCM7XX_CLKDIV2, 16, 5, NPCM7XX_CLK_S_CLKOUT,
-	NPCM7XX_CLK_S_CLKOUT_MUX, 0, 0, NPCM7XX_CLK_CLKOUT},
+	{NPCM7XX_CLKDIV2, 16, 5, NPCM7XX_CLK_S_CLKOUT, NPCM7XX_CLK_S_CLKOUT_MUX,
+		 CLK_DIVIDER_READ_ONLY, 0, NPCM7XX_CLK_CLKOUT},
 	/*20-16 CLKOUTDIV*/
-	{NPCM7XX_CLKDIV2, 13, 3, NPCM7XX_CLK_S_GFX,
-	NPCM7XX_CLK_S_GFX_MUX, 0, 0, NPCM7XX_CLK_GFX},
+	{NPCM7XX_CLKDIV2, 13, 3, NPCM7XX_CLK_S_GFX, NPCM7XX_CLK_S_GFX_MUX,
+		CLK_DIVIDER_READ_ONLY, 0, NPCM7XX_CLK_GFX},
 	/*15-13 GFXCKDIV*/
-	{NPCM7XX_CLKDIV2, 8, 5, NPCM7XX_CLK_S_USB_BRIDGE,
-	NPCM7XX_CLK_S_SU_MUX, 0, 0, NPCM7XX_CLK_SU},
+	{NPCM7XX_CLKDIV2, 8, 5, NPCM7XX_CLK_S_USB_BRIDGE, NPCM7XX_CLK_S_SU_MUX,
+		CLK_DIVIDER_READ_ONLY, 0, NPCM7XX_CLK_SU},
 	/*12-8 SUCKDIV*/
-	{NPCM7XX_CLKDIV2, 4, 4, NPCM7XX_CLK_S_USB_HOST,
-	NPCM7XX_CLK_S_SU_MUX, 0, 0, NPCM7XX_CLK_SU48},
+	{NPCM7XX_CLKDIV2, 4, 4, NPCM7XX_CLK_S_USB_HOST, NPCM7XX_CLK_S_SU_MUX,
+		CLK_DIVIDER_READ_ONLY, 0, NPCM7XX_CLK_SU48},
 	/*7-4 SU48CKDIV*/
 	{NPCM7XX_CLKDIV2, 0, 4, NPCM7XX_CLK_S_SDHC,
-	NPCM7XX_CLK_S_SD_MUX, 0, 0, NPCM7XX_CLK_SDHC}
+	NPCM7XX_CLK_S_SD_MUX, CLK_DIVIDER_READ_ONLY, 0, NPCM7XX_CLK_SDHC}
 	,/*3-0 SD1CKDIV*/
 
 	{NPCM7XX_CLKDIV3, 6, 5, NPCM7XX_CLK_S_SPI0,
-	NPCM7XX_CLK_S_AHB, 0, 0, NPCM7XX_CLK_SPI0},
+	NPCM7XX_CLK_S_AHB, CLK_DIVIDER_READ_ONLY, 0, NPCM7XX_CLK_SPI0},
 	/*10-6 SPI0CKDV*/
 	{NPCM7XX_CLKDIV3, 1, 5, NPCM7XX_CLK_S_SPIX,
-	NPCM7XX_CLK_S_AHB, 0, 0, NPCM7XX_CLK_SPIX},
+	NPCM7XX_CLK_S_AHB, CLK_DIVIDER_READ_ONLY, 0, NPCM7XX_CLK_SPIX},
 	/*5-1 SPIXCKDV*/
 
 };
Signature · 1 line
2.22.0
author maintainer
#9 lore raw

PATCH v3 5/12 dt-binding: watchdog: Add DT restart priority and reset type

In reply to Tomer Maimon

Add device tree restart priority documentation and three reset types documentation.

---
 .../bindings/watchdog/nuvoton,npcm-wdt.txt    | 34 +++++++++++++++++++
 1 file changed, 34 insertions(+)
Documentation/devicetree/bindings/watchdog/nuvoton,npcm-wdt.txt +34 -0
index 6d593003c933..a3142cb60495 100644
@@ -16,7 +16,36 @@ Required clocking property, have to be one of:
                     timer (usually 25000000).
 
 Optional properties:
+- syscon: a phandle to access GCR registers.
 - timeout-sec : Contains the watchdog timeout in seconds
+- nuvoton,restart-priority - Contains the card restart priority.
+- nuvoton,card-reset-type = "porst|corst|wd0|wd1|wd2|sw1|sw2|sw3|sw4"
+  Contains the card reset type for checking and indicating
+  the last card reset status (WDIOF_CARDRESET)
+
+  If 'nuvoton,card-reset-type' is not specified the default is porst
+
+  Reset types:
+       - porst: Power reset
+       - corst: Core reset
+	   - wdX : Watchdog reset X (X represante 0-2)
+	   - swX : Software reset X (X represante 1-4)
+
+- nuvoton,ext1-reset-type = "porst|corst|wd0|wd1|wd2|sw1|sw2|sw3|sw4"
+  Contains the external 2 reset type for checking and indicating
+  the last external 2 reset status (WDIOF_EXTERN1)
+
+  If 'nuvoton,card-reset-type' is not specified the default is wd0.
+
+  Reset types are the same as in nuvoton,card-reset-type property.
+
+- nuvoton,ext2-reset-type = "porst|corst|wd0|wd1|wd2|sw1|sw2|sw3|sw4"
+  Contains the external 2 reset type for checking and indicating
+  the last external 2 reset status (WDIOF_EXTERN2)
+
+  If 'nuvoton,card-reset-type' is not specified the default is sw1.
+
+  Reset types are the same as in nuvoton,card-reset-type property.
 
 Example:
 
@@ -25,4 +54,9 @@ timer@f000801c {
     interrupts = <GIC_SPI 47 IRQ_TYPE_LEVEL_HIGH>;
     reg = <0xf000801c 0x4>;
     clocks = <&clk NPCM7XX_CLK_TIMER>;
+	syscon = <&gcr>;
+	nuvoton,restart-priority = <155>;
+	nuvoton,card-reset-type = "porst";
+	nuvoton,ext1-reset-type = "wd1";
+	nuvoton,ext2-reset-type = "sw2";
 };
Signature · 1 line
2.22.0
author maintainer
#7 lore raw

PATCH v3 4/12 dts: npcm750: add fuse regmap support node

In reply to Tomer Maimon
---
 arch/arm/boot/dts/nuvoton-common-npcm7xx.dtsi | 6 ++++++
 1 file changed, 6 insertions(+)
arch/arm/boot/dts/nuvoton-common-npcm7xx.dtsi +6 -0
index 7eee4145127f..455a96b23b85 100644
@@ -82,6 +82,12 @@
 			"simple-mfd";
 			reg = <0x801000 0x6C>;
 		};
+		
+		fuse:fuse@18a000 {
+			compatible = "nuvoton,npcm750-fuse", "syscon",
+				"simple-mfd";
+			reg = <0x18a000 0x1000>;
+		};
 
 		scu: scu@3fe000 {
 			compatible = "arm,cortex-a9-scu";
Signature · 1 line
2.22.0
author maintainer
#5 lore raw

PATCH v3 3/12 iio: adc: add calibration support to npcm ADC

In reply to Tomer Maimon

Add calibration to improve accuracy measurement when using internal reference voltage.

the calibration values taken from the FUSE module.

---
 drivers/iio/adc/npcm_adc.c | 178 +++++++++++++++++++++++++++++++++++++
 1 file changed, 178 insertions(+)
drivers/iio/adc/npcm_adc.c +178 -0
index 83bad2d5575d..081378b98fa9 100644
@@ -17,6 +17,8 @@
 #include <linux/reset.h>
 
 struct npcm_adc {
+	u32 R05;
+	u32 R15;
 	bool int_status;
 	u32 adc_sample_hz;
 	struct device *dev;
@@ -51,6 +53,41 @@ struct npcm_adc {
 #define NPCM_RESOLUTION_BITS		10
 #define NPCM_INT_VREF_MV		2000
 
+/* FUSE registers */
+#define NPCM7XX_FST		0x00
+#define NPCM7XX_FADDR		0x04
+#define NPCM7XX_FDATA		0x08
+#define NPCM7XX_FCFG		0x0C
+#define NPCM7XX_FCTL		0x14
+
+/* FST Register Bits */
+#define NPCM7XX_FST_RDY		BIT(0)
+#define NPCM7XX_FST_RDST	BIT(1)
+
+/* FADDR Register Bits */
+#define NPCM7XX_FADDR_BYTEADDR		BIT(0)
+#define NPCM7XX_FADDR_BYTEADDR_MASK	GENMASK(9, 0)
+
+/* FADDR Register Bits */
+#define NPCM7XX_FDATA_DATA		BIT(0)
+#define NPCM7XX_FDATA_CLEAN_VALUE	BIT(1)
+#define NPCM7XX_FDATA_DATA_MASK		GENMASK(7, 0)
+
+/* FCTL Register Bits */
+#define NPCM7XX_FCTL_RDST		BIT(1)
+
+/* ADC Calibration Definition */
+#define NPCM_INT_1500MV		768
+#define NPCM_INT_1000MV		512
+#define NPCM_ADC_MIN_VAL	0
+#define NPCM_ADC_MAX_VAL	1023
+
+#define FUSE_CALIB_ADDR		24
+#define FUSE_CALIB_SIZE		8
+#define DATA_CALIB_SIZE		4
+#define FUSE_READ_SLEEP		500
+#define FUSE_READ_TIMEOUT	1000000
+
 #define NPCM_ADC_CHAN(ch) {					\
 	.type = IIO_VOLTAGE,					\
 	.indexed = 1,						\
@@ -71,6 +108,119 @@ static const struct iio_chan_spec npcm_adc_iio_channels[] = {
 	NPCM_ADC_CHAN(7),
 };
 
+static void npcm750_fuse_read(struct regmap *fuse_regmap, u32 addr, u8 *data)
+{
+	u32 val;
+	u32 fstreg;
+
+	regmap_read_poll_timeout(fuse_regmap, NPCM7XX_FST, fstreg,
+				 fstreg & NPCM7XX_FST_RDY, FUSE_READ_SLEEP,
+				 FUSE_READ_TIMEOUT);
+	regmap_write_bits(fuse_regmap, NPCM7XX_FST,
+			  NPCM7XX_FST_RDST, NPCM7XX_FST_RDST);
+
+	regmap_write_bits(fuse_regmap, NPCM7XX_FADDR,
+			  NPCM7XX_FADDR_BYTEADDR_MASK, addr);
+	regmap_read(fuse_regmap, NPCM7XX_FADDR, &val);
+	regmap_write(fuse_regmap, NPCM7XX_FCTL, NPCM7XX_FCTL_RDST);
+
+	regmap_read_poll_timeout(fuse_regmap, NPCM7XX_FST, fstreg,
+				 fstreg & NPCM7XX_FST_RDY, FUSE_READ_SLEEP,
+				 FUSE_READ_TIMEOUT);
+	regmap_write_bits(fuse_regmap, NPCM7XX_FST,
+			  NPCM7XX_FST_RDST, NPCM7XX_FST_RDST);
+
+	regmap_read(fuse_regmap, NPCM7XX_FDATA, &val);
+	*data = (u8)val;
+
+	regmap_write_bits(fuse_regmap, NPCM7XX_FDATA, NPCM7XX_FDATA_DATA_MASK,
+			  NPCM7XX_FDATA_CLEAN_VALUE);
+}
+
+static int npcm750_ECC_to_nibble(u8 ECC, u8 nibble)
+{
+	u8 nibble_b0 = (nibble >> 0) & BIT(0);
+	u8 nibble_b1 = (nibble >> 1) & BIT(0);
+	u8 nibble_b2 = (nibble >> 2) & BIT(0);
+	u8 nibble_b3 = (nibble >> 3) & BIT(0);
+	u8 tmp_ECC = nibble;
+
+	tmp_ECC |= (nibble_b0 ^ nibble_b1) << 4 | (nibble_b2 ^ nibble_b3) << 5 |
+		(nibble_b0 ^ nibble_b2) << 6  | (nibble_b1 ^ nibble_b3) << 7;
+
+	if (tmp_ECC != ECC)
+		return -EINVAL;
+
+	return 0;
+}
+
+static int npcm750_ECC_to_byte(u16 ECC, u8 *Byte)
+{
+	u8 nibble_L, nibble_H;
+	u8 ECC_L, ECC_H;
+
+	ECC_H = ECC >> 8;
+	nibble_H = ECC_H & 0x0F;
+	ECC_L = ECC >> 0;
+	nibble_L = ECC_L & 0x0F;
+
+	if (npcm750_ECC_to_nibble(ECC_H, nibble_H) != 0 ||
+	    npcm750_ECC_to_nibble(ECC_L, nibble_L) != 0)
+		return -EINVAL;
+
+	*Byte = nibble_H << 4 | nibble_L << 0;
+
+	return 0;
+}
+
+static int npcm750_read_nibble_parity(u8 *block_ECC, u8 *ADC_calib)
+{
+	int i;
+	u16 ECC;
+
+	for (i = 0; i < DATA_CALIB_SIZE; i++) {
+		memcpy(&ECC, block_ECC + (i * 2), 2);
+		if (npcm750_ECC_to_byte(ECC, &ADC_calib[i]) != 0)
+			return -EINVAL;
+	}
+
+	return 0;
+}
+
+static int npcm750_fuse_calibration_read(struct platform_device *pdev,
+					 struct npcm_adc *info)
+{
+	struct device_node *np = pdev->dev.of_node;
+	struct regmap *fuse_regmap;
+	ssize_t bytes_read = 0;
+	u8 read_buf[8];
+	u32 ADC_calib;
+	u32 addr = FUSE_CALIB_ADDR;
+
+	fuse_regmap = syscon_regmap_lookup_by_phandle(np, "syscon");
+	if (IS_ERR(fuse_regmap)) {
+		dev_warn(&pdev->dev, "Failed to find syscon\n");
+		return PTR_ERR(fuse_regmap);
+	}
+
+	while (bytes_read < FUSE_CALIB_SIZE) {
+		npcm750_fuse_read(fuse_regmap, addr,
+				  &read_buf[bytes_read]);
+		bytes_read++;
+		addr++;
+	}
+
+	if (npcm750_read_nibble_parity(read_buf, (u8 *)&ADC_calib)) {
+		dev_warn(info->dev, "FUSE Calibration read failed\n");
+		return -EINVAL;
+	}
+
+	info->R05 = ADC_calib & 0xFFFF;
+	info->R15 = ADC_calib >> 16;
+
+	return 0;
+}
+
 static irqreturn_t npcm_adc_isr(int irq, void *data)
 {
 	u32 regtemp;
@@ -125,6 +275,29 @@ static int npcm_adc_read(struct npcm_adc *info, int *val, u8 channel)
 	return 0;
 }
 
+static void npcm_adc_calibration(int *val, struct npcm_adc *info)
+{
+	int mul_val;
+	int offset_val;
+
+	mul_val = NPCM_INT_1000MV * (*val - info->R15);
+	if (mul_val < 0) {
+		mul_val = mul_val * -1;
+		offset_val = DIV_ROUND_CLOSEST(mul_val,
+					       (info->R15 - info->R05));
+		*val = NPCM_INT_1500MV - offset_val;
+	} else {
+		offset_val = DIV_ROUND_CLOSEST(mul_val,
+					       (info->R15 - info->R05));
+		*val = NPCM_INT_1500MV + offset_val;
+	}
+
+	if (*val < NPCM_ADC_MIN_VAL)
+		*val = NPCM_ADC_MIN_VAL;
+	if (*val > NPCM_ADC_MAX_VAL)
+		*val = NPCM_ADC_MAX_VAL;
+}
+
 static int npcm_adc_read_raw(struct iio_dev *indio_dev,
 			     struct iio_chan_spec const *chan, int *val,
 			     int *val2, long mask)
@@ -142,6 +315,10 @@ static int npcm_adc_read_raw(struct iio_dev *indio_dev,
 			dev_err(info->dev, "NPCM ADC read failed\n");
 			return ret;
 		}
+
+		if ((info->R05 || info->R15) && IS_ERR(info->vref))
+			npcm_adc_calibration(val, info);
+
 		return IIO_VAL_INT;
 	case IIO_CHAN_INFO_SCALE:
 		if (!IS_ERR(info->vref)) {
@@ -248,6 +425,7 @@ static int npcm_adc_probe(struct platform_device *pdev)
 			  info->regs + NPCM_ADCCON);
 	}
 
+	npcm750_fuse_calibration_read(pdev, info);
 	init_waitqueue_head(&info->wq);
 
 	reg_con = ioread32(info->regs + NPCM_ADCCON);
Signature · 1 line
2.22.0
author maintainer
#11 lore raw

PATCH v3 7/12 pinctrl: npcm7xx: Add HGPIO pin support to NPCM7xx pinctrl driver

In reply to Tomer Maimon
---
 drivers/pinctrl/nuvoton/pinctrl-npcm7xx.c | 65 +++++++++++++++++------
 1 file changed, 49 insertions(+), 16 deletions(-)
drivers/pinctrl/nuvoton/pinctrl-npcm7xx.c +49 -16
index a935065cdac4..e5f58ea89917 100644
@@ -504,6 +504,15 @@ static const int lkgpo2_pins[] = { 9 };
 
 static const int nprd_smi_pins[] = { 190 };
 
+static const int hgpio0_pins[] = { 20 };
+static const int hgpio1_pins[] = { 21 };
+static const int hgpio2_pins[] = { 22 };
+static const int hgpio3_pins[] = { 23 };
+static const int hgpio4_pins[] = { 24 };
+static const int hgpio5_pins[] = { 25 };
+static const int hgpio6_pins[] = { 59 };
+static const int hgpio7_pins[] = { 60 };
+
 /*
  * pin:	     name, number
  * group:    name, npins,   pins
@@ -631,6 +640,14 @@ struct npcm7xx_group {
 	NPCM7XX_GRP(lkgpo1), \
 	NPCM7XX_GRP(lkgpo2), \
 	NPCM7XX_GRP(nprd_smi), \
+	NPCM7XX_GRP(hgpio0), \
+	NPCM7XX_GRP(hgpio1), \
+	NPCM7XX_GRP(hgpio2), \
+	NPCM7XX_GRP(hgpio3), \
+	NPCM7XX_GRP(hgpio4), \
+	NPCM7XX_GRP(hgpio5), \
+	NPCM7XX_GRP(hgpio6), \
+	NPCM7XX_GRP(hgpio7), \
 	\
 
 enum {
@@ -774,6 +791,14 @@ NPCM7XX_SFUNC(lkgpo0);
 NPCM7XX_SFUNC(lkgpo1);
 NPCM7XX_SFUNC(lkgpo2);
 NPCM7XX_SFUNC(nprd_smi);
+NPCM7XX_SFUNC(hgpio0);
+NPCM7XX_SFUNC(hgpio1);
+NPCM7XX_SFUNC(hgpio2);
+NPCM7XX_SFUNC(hgpio3);
+NPCM7XX_SFUNC(hgpio4);
+NPCM7XX_SFUNC(hgpio5);
+NPCM7XX_SFUNC(hgpio6);
+NPCM7XX_SFUNC(hgpio7);
 
 /* Function names */
 static struct npcm7xx_func npcm7xx_funcs[] = {
@@ -892,6 +917,14 @@ static struct npcm7xx_func npcm7xx_funcs[] = {
 	NPCM7XX_MKFUNC(lkgpo1),
 	NPCM7XX_MKFUNC(lkgpo2),
 	NPCM7XX_MKFUNC(nprd_smi),
+	NPCM7XX_MKFUNC(hgpio0),
+	NPCM7XX_MKFUNC(hgpio1),
+	NPCM7XX_MKFUNC(hgpio2),
+	NPCM7XX_MKFUNC(hgpio3),
+	NPCM7XX_MKFUNC(hgpio4),
+	NPCM7XX_MKFUNC(hgpio5),
+	NPCM7XX_MKFUNC(hgpio6),
+	NPCM7XX_MKFUNC(hgpio7),
 };
 
 #define NPCM7XX_PINCFG(a, b, c, d, e, f, g, h, i, j, k) \
@@ -944,12 +977,12 @@ static const struct npcm7xx_pincfg pincfg[] = {
 	NPCM7XX_PINCFG(17,      pspi2, MFSEL3, 13,     smb4den, I2CSEGSEL, 23,  none, NONE, 0,       DS(8, 12)),
 	NPCM7XX_PINCFG(18,      pspi2, MFSEL3, 13,	 smb4b, I2CSEGSEL, 14,  none, NONE, 0,	     DS(8, 12)),
 	NPCM7XX_PINCFG(19,      pspi2, MFSEL3, 13,	 smb4b, I2CSEGSEL, 14,  none, NONE, 0,	     DS(8, 12)),
-	NPCM7XX_PINCFG(20,	smb4c, I2CSEGSEL, 15,    smb15, MFSEL3, 8,      none, NONE, 0,	     0),
-	NPCM7XX_PINCFG(21,	smb4c, I2CSEGSEL, 15,    smb15, MFSEL3, 8,      none, NONE, 0,	     0),
-	NPCM7XX_PINCFG(22,      smb4d, I2CSEGSEL, 16,	 smb14, MFSEL3, 7,      none, NONE, 0,	     0),
-	NPCM7XX_PINCFG(23,      smb4d, I2CSEGSEL, 16,	 smb14, MFSEL3, 7,      none, NONE, 0,	     0),
-	NPCM7XX_PINCFG(24,	 ioxh, MFSEL3, 18,	  none, NONE, 0,	none, NONE, 0,	     DS(8, 12)),
-	NPCM7XX_PINCFG(25,	 ioxh, MFSEL3, 18,	  none, NONE, 0,	none, NONE, 0,	     DS(8, 12)),
+	NPCM7XX_PINCFG(20,	hgpio0, MFSEL2, 24,      smb15, MFSEL3, 8,      smb4c, I2CSEGSEL, 15,	     0),
+	NPCM7XX_PINCFG(21,	hgpio1, MFSEL2, 25,      smb15, MFSEL3, 8,      smb4c, I2CSEGSEL, 15,	     0),
+	NPCM7XX_PINCFG(22,      hgpio2, MFSEL2, 26,	 smb14, MFSEL3, 7,      smb4d, I2CSEGSEL, 16,	     0),
+	NPCM7XX_PINCFG(23,      hgpio3, MFSEL2, 27,	 smb14, MFSEL3, 7,      smb4d, I2CSEGSEL, 16,	     0),
+	NPCM7XX_PINCFG(24,	 hgpio4, MFSEL2, 28,	ioxh, MFSEL3, 18,	none, NONE, 0,	     DS(8, 12)),
+	NPCM7XX_PINCFG(25,	 hgpio5, MFSEL2, 29,	ioxh, MFSEL3, 18,	none, NONE, 0,	     DS(8, 12)),
 	NPCM7XX_PINCFG(26,	 smb5, MFSEL1, 2,	  none, NONE, 0,	none, NONE, 0,	     0),
 	NPCM7XX_PINCFG(27,	 smb5, MFSEL1, 2,	  none, NONE, 0,	none, NONE, 0,	     0),
 	NPCM7XX_PINCFG(28,	 smb4, MFSEL1, 1,	  none, NONE, 0,	none, NONE, 0,	     0),
@@ -982,8 +1015,8 @@ static const struct npcm7xx_pincfg pincfg[] = {
 	NPCM7XX_PINCFG(56,	r1err, MFSEL1, 12,	  none, NONE, 0,	none, NONE, 0,	     0),
 	NPCM7XX_PINCFG(57,       r1md, MFSEL1, 13,        none, NONE, 0,        none, NONE, 0,       DS(2, 4)),
 	NPCM7XX_PINCFG(58,       r1md, MFSEL1, 13,        none, NONE, 0,	none, NONE, 0,	     DS(2, 4)),
-	NPCM7XX_PINCFG(59,	smb3d, I2CSEGSEL, 13,	  none, NONE, 0,	none, NONE, 0,	     0),
-	NPCM7XX_PINCFG(60,	smb3d, I2CSEGSEL, 13,	  none, NONE, 0,	none, NONE, 0,	     0),
+	NPCM7XX_PINCFG(59,	hgpio6, MFSEL2, 30,	  smb3d, I2CSEGSEL, 13,	none, NONE, 0,	     0),
+	NPCM7XX_PINCFG(60,	hgpio7, MFSEL2, 31,	  smb3d, I2CSEGSEL, 13,	none, NONE, 0,	     0),
 	NPCM7XX_PINCFG(61,      uart1, MFSEL1, 10,	  none, NONE, 0,	none, NONE, 0,     GPO),
 	NPCM7XX_PINCFG(62,      uart1, MFSEL1, 10,    bmcuart1, MFSEL3, 24,	none, NONE, 0,     GPO),
 	NPCM7XX_PINCFG(63,      uart1, MFSEL1, 10,    bmcuart1, MFSEL3, 24,	none, NONE, 0,     GPO),
@@ -1188,12 +1221,12 @@ static const struct pinctrl_pin_desc npcm7xx_pins[] = {
 	PINCTRL_PIN(17, "GPIO17/PSPI2DI/SMB4DEN"),
 	PINCTRL_PIN(18, "GPIO18/PSPI2D0/SMB4BSDA"),
 	PINCTRL_PIN(19, "GPIO19/PSPI2CK/SMB4BSCL"),
-	PINCTRL_PIN(20, "GPIO20/SMB4CSDA/SMB15SDA"),
-	PINCTRL_PIN(21, "GPIO21/SMB4CSCL/SMB15SCL"),
-	PINCTRL_PIN(22, "GPIO22/SMB4DSDA/SMB14SDA"),
-	PINCTRL_PIN(23, "GPIO23/SMB4DSCL/SMB14SCL"),
-	PINCTRL_PIN(24, "GPIO24/IOXHDO"),
-	PINCTRL_PIN(25, "GPIO25/IOXHDI"),
+	PINCTRL_PIN(20, "GPIO20/HGPIO0/SMB4CSDA/SMB15SDA"),
+	PINCTRL_PIN(21, "GPIO21/HGPIO1/SMB4CSCL/SMB15SCL"),
+	PINCTRL_PIN(22, "GPIO22/HGPIO2/SMB4DSDA/SMB14SDA"),
+	PINCTRL_PIN(23, "GPIO23/HGPIO3/SMB4DSCL/SMB14SCL"),
+	PINCTRL_PIN(24, "GPIO24/HGPIO4/IOXHDO"),
+	PINCTRL_PIN(25, "GPIO25/HGPIO5/IOXHDI"),
 	PINCTRL_PIN(26, "GPIO26/SMB5SDA"),
 	PINCTRL_PIN(27, "GPIO27/SMB5SCL"),
 	PINCTRL_PIN(28, "GPIO28/SMB4SDA"),
@@ -1226,8 +1259,8 @@ static const struct pinctrl_pin_desc npcm7xx_pins[] = {
 	PINCTRL_PIN(56, "GPIO56/R1RXERR"),
 	PINCTRL_PIN(57, "GPIO57/R1MDC"),
 	PINCTRL_PIN(58, "GPIO58/R1MDIO"),
-	PINCTRL_PIN(59, "GPIO59/SMB3DSDA"),
-	PINCTRL_PIN(60, "GPIO60/SMB3DSCL"),
+	PINCTRL_PIN(59, "GPIO59/HGPIO6/SMB3DSDA"),
+	PINCTRL_PIN(60, "GPIO60/HGPIO7/SMB3DSCL"),
 	PINCTRL_PIN(61, "GPO61/nDTR1_BOUT1/STRAP6"),
 	PINCTRL_PIN(62, "GPO62/nRTST1/STRAP5"),
 	PINCTRL_PIN(63, "GPO63/TXD1/STRAP4"),
Signature · 1 line
2.22.0

Tomer Maimon

author maintainer
#0 lore raw

v3 cover Add NPCM7xx patches to dev-5.8

In this patch set we will like to align with relevant modifications in Nuvoton OpenBMC Linux kernel 5.4.

Linux upstream current status:
1. npcm7xx clock driver - adding read only
flag to divider clocks, Will be sent to Linux community.
2. Adding NPCM ADC calibration - Will be sent to Linux vanilla, but I am not sure it will be approved.
3. Add DT restart priority and reset type support - sent to Linux community la but havent approved yet.
4. persist configuration to the pin control driver - asked by a costumer, didnt sent to Linux community.
5. Add HGPIO pin support to NPCM7xx pinctrl driver - will be sent to Linux community
6. JTAG master driver - will be sent to Linux community once we will have BMC folder.

Changes since version 2:
- Address comments from Joel Stanley

Changes since version 1:
- Address comments from Jonathan Neuschäfer: removing trailing whitespace in NPCM watchdog documentation.
- Adding Stanley Chu to NPCM JTAG master driver

Tomer Maimon (12):
clk: npcm7xx: add read only flag to divider clocks
dt-binding: iio: add syscon property to NPCM ADC
iio: adc: add calibration support to npcm ADC
dts: npcm750: add fuse regmap support node
dt-binding: watchdog: Add DT restart priority and reset type
watchdog: npcm: Add DT restart priority and reset type support
pinctrl: npcm7xx: Add HGPIO pin support to NPCM7xx pinctrl driver
pinctrl: pinconf: add pin persist configuration
pinctrl: npcm7xx: Add pin persist configuration support
spi: npcm-pspi: Add full duplex support
dt-binding: bmc: add NPCM7XX JTAG master documentation
misc: npcm7xx-jtag-master: add NPCM7xx JTAG master driver

 .../bindings/bmc/npcm7xx-jtag-master.txt      |  38 +
 .../bindings/iio/adc/nuvoton,npcm-adc.txt     |   2 +
 .../bindings/watchdog/nuvoton,npcm-wdt.txt    |  34 +
 arch/arm/boot/dts/nuvoton-common-npcm7xx.dtsi |   6 +
 drivers/clk/clk-npcm7xx.c                     |  70 +-
 drivers/iio/adc/npcm_adc.c                    | 178 ++++
 drivers/misc/Kconfig                          |   6 +
 drivers/misc/Makefile                         |   1 +
 drivers/misc/npcm7xx-jtag-master.c            | 840 ++++++++++++++++++
 drivers/pinctrl/nuvoton/pinctrl-npcm7xx.c     | 130 ++-
 drivers/pinctrl/pinconf-generic.c             |   3 +
 drivers/spi/spi-npcm-pspi.c                   |  75 +-
 drivers/watchdog/npcm_wdt.c                   | 117 ++-
 13 files changed, 1404 insertions(+), 96 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/bmc/npcm7xx-jtag-master.txt
 create mode 100644 drivers/misc/npcm7xx-jtag-master.c
Signature · 1 line
2.22.0
author maintainer
#3 lore raw

PATCH v3 2/12 dt-binding: iio: add syscon property to NPCM ADC

Add syscon property to NPCM ADC to handle FUSE
registers.

---
 Documentation/devicetree/bindings/iio/adc/nuvoton,npcm-adc.txt | 2 ++
 1 file changed, 2 insertions(+)
Documentation/devicetree/bindings/iio/adc/nuvoton,npcm-adc.txt +2 -0
index ef8eeec1a997..faf9f9b54f5b 100644
@@ -14,6 +14,7 @@ Optional properties:
 - vref-supply: The regulator supply ADC reference voltage, in case the
 			   vref-supply is not added the ADC will use internal voltage
 			   reference.
+- syscon: a phandle to access FUSE registers
 
 Example:
 
@@ -23,4 +24,5 @@ adc: adc@f000c000 {
 	interrupts = <GIC_SPI 0 IRQ_TYPE_LEVEL_HIGH>;
 	clocks = <&clk NPCM7XX_CLK_ADC>;
 	resets = <&rstc NPCM7XX_RESET_IPSRST1 NPCM7XX_RESET_ADC>;
+	syscon = <&fuse>;
 };
Signature · 1 line
2.22.0
author maintainer
#10 lore raw

PATCH v3 6/12 watchdog: npcm: Add DT restart priority and reset type support

In reply to Tomer Maimon

Add Device tree restart priority and
three reset types support.

---
 drivers/watchdog/npcm_wdt.c | 117 +++++++++++++++++++++++++++++++++++-
 1 file changed, 114 insertions(+), 3 deletions(-)
drivers/watchdog/npcm_wdt.c +114 -3
index 765577f11c8d..a93180d0a6f4 100644
@@ -11,7 +11,24 @@
 #include <linux/platform_device.h>
 #include <linux/slab.h>
 #include <linux/watchdog.h>
-
+#include <linux/regmap.h>
+#include <linux/mfd/syscon.h>
+
+/* NPCM7xx GCR module */
+#define NPCM7XX_RESSR_OFFSET		0x6C
+#define NPCM7XX_INTCR2_OFFSET		0x60
+
+#define NPCM7XX_PORST			BIT(31)
+#define NPCM7XX_CORST			BIT(30)
+#define NPCM7XX_WD0RST			BIT(29)
+#define NPCM7XX_WD1RST			BIT(24)
+#define NPCM7XX_WD2RST			BIT(23)
+#define NPCM7XX_SWR1RST			BIT(28)
+#define NPCM7XX_SWR2RST			BIT(27)
+#define NPCM7XX_SWR3RST			BIT(26)
+#define NPCM7XX_SWR4RST			BIT(25)
+
+ /* WD register */
 #define NPCM_WTCR	0x1C
 
 #define NPCM_WTCLK	(BIT(10) | BIT(11))	/* Clock divider */
@@ -41,8 +58,11 @@
  */
 
 struct npcm_wdt {
-	struct watchdog_device  wdd;
+	struct watchdog_device	wdd;
 	void __iomem		*reg;
+	u32			card_reset;
+	u32			ext1_reset;
+	u32			ext2_reset;
 };
 
 static inline struct npcm_wdt *to_npcm_wdt(struct watchdog_device *wdd)
@@ -176,14 +196,65 @@ static const struct watchdog_ops npcm_wdt_ops = {
 	.restart = npcm_wdt_restart,
 };
 
+static void npcm_get_reset_status(struct npcm_wdt *wdt, struct device *dev)
+{
+	struct regmap *gcr_regmap;
+	u32 rstval;
+
+	gcr_regmap = syscon_regmap_lookup_by_phandle(dev->of_node, "syscon");
+	if (IS_ERR(gcr_regmap))
+		dev_warn(dev, "Failed to find gcr syscon, WD reset status not supported\n");
+
+	regmap_read(gcr_regmap, NPCM7XX_RESSR_OFFSET, &rstval);
+	if (!rstval) {
+		regmap_read(gcr_regmap, NPCM7XX_INTCR2_OFFSET, &rstval);
+		rstval = ~rstval;
+	}
+
+	if (rstval & wdt->card_reset)
+		wdt->wdd.bootstatus |= WDIOF_CARDRESET;
+	if (rstval & wdt->ext1_reset)
+		wdt->wdd.bootstatus |= WDIOF_EXTERN1;
+	if (rstval & wdt->ext2_reset)
+		wdt->wdd.bootstatus |= WDIOF_EXTERN2;
+}
+
+static u32 npcm_wdt_reset_type(const char *reset_type)
+{
+	if (!strcmp(reset_type, "porst"))
+		return NPCM7XX_PORST;
+	else if (!strcmp(reset_type, "corst"))
+		return NPCM7XX_CORST;
+	else if (!strcmp(reset_type, "wd0"))
+		return NPCM7XX_WD0RST;
+	else if (!strcmp(reset_type, "wd1"))
+		return NPCM7XX_WD1RST;
+	else if (!strcmp(reset_type, "wd2"))
+		return NPCM7XX_WD2RST;
+	else if (!strcmp(reset_type, "sw1"))
+		return NPCM7XX_SWR1RST;
+	else if (!strcmp(reset_type, "sw2"))
+		return NPCM7XX_SWR2RST;
+	else if (!strcmp(reset_type, "sw3"))
+		return NPCM7XX_SWR3RST;
+	else if (!strcmp(reset_type, "sw4"))
+		return NPCM7XX_SWR4RST;
+
+	return 0;
+}
+
 static int npcm_wdt_probe(struct platform_device *pdev)
 {
 	struct device *dev = &pdev->dev;
+	const char *card_reset_type;
+	const char *ext1_reset_type;
+	const char *ext2_reset_type;
 	struct npcm_wdt *wdt;
+	u32 priority;
 	int irq;
 	int ret;
 
-	wdt = devm_kzalloc(dev, sizeof(*wdt), GFP_KERNEL);
+	wdt = devm_kzalloc(&pdev->dev, sizeof(*wdt), GFP_KERNEL);
 	if (!wdt)
 		return -ENOMEM;
 
@@ -195,6 +266,45 @@ static int npcm_wdt_probe(struct platform_device *pdev)
 	if (irq < 0)
 		return irq;
 
+	if (of_property_read_u32(pdev->dev.of_node, "nuvoton,restart-priority",
+				 &priority))
+		watchdog_set_restart_priority(&wdt->wdd, 128);
+	else
+		watchdog_set_restart_priority(&wdt->wdd, priority);
+
+	ret = of_property_read_string(pdev->dev.of_node,
+				      "nuvoton,card-reset-type",
+				      &card_reset_type);
+	if (ret) {
+		wdt->card_reset = NPCM7XX_PORST;
+	} else {
+		wdt->card_reset = npcm_wdt_reset_type(card_reset_type);
+		if (!wdt->card_reset)
+			wdt->card_reset = NPCM7XX_PORST;
+	}
+
+	ret = of_property_read_string(pdev->dev.of_node,
+				      "nuvoton,ext1-reset-type",
+				      &ext1_reset_type);
+	if (ret) {
+		wdt->ext1_reset = NPCM7XX_WD0RST;
+	} else {
+		wdt->ext1_reset = npcm_wdt_reset_type(ext1_reset_type);
+		if (!wdt->ext1_reset)
+			wdt->ext1_reset = NPCM7XX_WD0RST;
+	}
+
+	ret = of_property_read_string(pdev->dev.of_node,
+				      "nuvoton,ext2-reset-type",
+				      &ext2_reset_type);
+	if (ret) {
+		wdt->ext2_reset = NPCM7XX_SWR1RST;
+	} else {
+		wdt->ext2_reset = npcm_wdt_reset_type(ext2_reset_type);
+		if (!wdt->ext2_reset)
+			wdt->ext2_reset = NPCM7XX_SWR1RST;
+	}
+
 	wdt->wdd.info = &npcm_wdt_info;
 	wdt->wdd.ops = &npcm_wdt_ops;
 	wdt->wdd.min_timeout = 1;
@@ -213,6 +323,7 @@ static int npcm_wdt_probe(struct platform_device *pdev)
 		set_bit(WDOG_HW_RUNNING, &wdt->wdd.status);
 	}
 
+	npcm_get_reset_status(wdt, dev);
 	ret = devm_request_irq(dev, irq, npcm_wdt_interrupt, 0, "watchdog",
 			       wdt);
 	if (ret)
Signature · 1 line
2.22.0
author maintainer
#13 lore raw

PATCH v3 8/12 pinctrl: pinconf: add pin persist configuration

In reply to Tomer Maimon

Add generic pin persist configuration support.

---
 drivers/pinctrl/pinconf-generic.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/pinctrl/pinconf-generic.c +3 -0
index dfef471201f6..c609a69bd37e 100644
@@ -50,6 +50,7 @@ static const struct pin_config_item conf_items[] = {
 	PCONFDUMP(PIN_CONFIG_SLEEP_HARDWARE_STATE, "sleep hardware state", NULL, false),
 	PCONFDUMP(PIN_CONFIG_SLEW_RATE, "slew rate", NULL, true),
 	PCONFDUMP(PIN_CONFIG_SKEW_DELAY, "skew delay", NULL, true),
+	PCONFDUMP(PIN_CONFIG_PERSIST_STATE, "persist state", NULL, false),
 };
 
 static void pinconf_generic_dump_one(struct pinctrl_dev *pctldev,
@@ -184,6 +185,8 @@ static const struct pinconf_generic_params dt_params[] = {
 	{ "sleep-hardware-state", PIN_CONFIG_SLEEP_HARDWARE_STATE, 0 },
 	{ "slew-rate", PIN_CONFIG_SLEW_RATE, 0 },
 	{ "skew-delay", PIN_CONFIG_SKEW_DELAY, 0 },
+	{ "persist-state", PIN_CONFIG_PERSIST_STATE, 0 },
+	{ "reset-state", PIN_CONFIG_PERSIST_STATE, 1 },
 };
 
 /**
Signature · 1 line
2.22.0
author maintainer
#14 lore raw

PATCH v3 9/12 pinctrl: npcm7xx: Add pin persist configuration support

In reply to Tomer Maimon
---
 drivers/pinctrl/nuvoton/pinctrl-npcm7xx.c | 65 +++++++++++++++++++++++
 1 file changed, 65 insertions(+)
drivers/pinctrl/nuvoton/pinctrl-npcm7xx.c +65 -0
index e5f58ea89917..ec12efd23bbe 100644
@@ -36,6 +36,19 @@
 
 #define SRCNT_ESPI		BIT(3)
 
+/* reset registers */
+#define NPCM7XX_RST_WD0RCR	0x38
+#define NPCM7XX_RST_WD1RCR	0x3C
+#define NPCM7XX_RST_WD2RCR	0x40
+#define NPCM7XX_RST_SWRSTC1	0x44
+#define NPCM7XX_RST_SWRSTC2	0x48
+#define NPCM7XX_RST_SWRSTC3	0x4C
+#define NPCM7XX_RST_SWRSTC4	0x50
+#define NPCM7XX_RST_CORSTC	0x5C
+
+#define GPIOX_MODULE_RESET	BIT(16)
+#define CA9C_MODULE_RESET	BIT(0)
+
 /* GPIO registers */
 #define NPCM7XX_GP_N_TLOCK1	0x00
 #define NPCM7XX_GP_N_DIN	0x04 /* Data IN */
@@ -94,6 +107,7 @@ struct npcm7xx_pinctrl {
 	struct npcm7xx_gpio	gpio_bank[NPCM7XX_GPIO_BANK_NUM];
 	struct irq_domain	*domain;
 	struct regmap		*gcr_regmap;
+	struct regmap		*rst_regmap;
 	void __iomem		*regs;
 	u32			bank_num;
 };
@@ -1583,6 +1597,48 @@ static int npcm7xx_set_drive_strength(struct npcm7xx_pinctrl *npcm,
 	return -ENOTSUPP;
 }
 
+static int npcm7xx_gpio_reset_persist(struct npcm7xx_pinctrl *npcm,
+					unsigned int pin, int enable)
+{
+	struct npcm7xx_gpio *bank =
+		&npcm->gpio_bank[pin / NPCM7XX_GPIO_PER_BANK];
+	int banknum = pin / bank->gc.ngpio;
+
+	if (enable) {
+		regmap_update_bits(npcm->rst_regmap, NPCM7XX_RST_WD0RCR,
+				   GPIOX_MODULE_RESET << banknum, 0);
+		regmap_update_bits(npcm->rst_regmap, NPCM7XX_RST_WD1RCR,
+				   GPIOX_MODULE_RESET << banknum, 0);
+		regmap_update_bits(npcm->rst_regmap, NPCM7XX_RST_WD2RCR,
+				   GPIOX_MODULE_RESET << banknum, 0);
+		regmap_update_bits(npcm->rst_regmap, NPCM7XX_RST_CORSTC,
+				   GPIOX_MODULE_RESET << banknum, 0);
+	} else {
+		regmap_update_bits(npcm->rst_regmap, NPCM7XX_RST_WD0RCR,
+				   (GPIOX_MODULE_RESET << banknum) |
+				   CA9C_MODULE_RESET,
+				   (GPIOX_MODULE_RESET << banknum) |
+				   CA9C_MODULE_RESET);
+		regmap_update_bits(npcm->rst_regmap, NPCM7XX_RST_WD1RCR,
+				   (GPIOX_MODULE_RESET << banknum) |
+				   CA9C_MODULE_RESET,
+				   (GPIOX_MODULE_RESET << banknum) |
+				   CA9C_MODULE_RESET);
+		regmap_update_bits(npcm->rst_regmap, NPCM7XX_RST_WD2RCR,
+				   (GPIOX_MODULE_RESET << banknum) |
+				   CA9C_MODULE_RESET,
+				   (GPIOX_MODULE_RESET << banknum) |
+				   CA9C_MODULE_RESET);
+		regmap_update_bits(npcm->rst_regmap, NPCM7XX_RST_CORSTC,
+				   (GPIOX_MODULE_RESET << banknum) |
+				   CA9C_MODULE_RESET,
+				   (GPIOX_MODULE_RESET << banknum) |
+				   CA9C_MODULE_RESET);
+	}
+
+	return 0;
+}
+
 /* pinctrl_ops */
 static void npcm7xx_pin_dbg_show(struct pinctrl_dev *pctldev,
 				 struct seq_file *s, unsigned int offset)
@@ -1852,6 +1908,8 @@ static int npcm7xx_config_set_one(struct npcm7xx_pinctrl *npcm,
 		return npcm7xx_set_slew_rate(bank, npcm->gcr_regmap, pin, arg);
 	case PIN_CONFIG_DRIVE_STRENGTH:
 		return npcm7xx_set_drive_strength(npcm, pin, arg);
+	case PIN_CONFIG_PERSIST_STATE:
+		return npcm7xx_gpio_reset_persist(npcm, pin, arg);
 	default:
 		return -ENOTSUPP;
 	}
@@ -2051,6 +2109,13 @@ static int npcm7xx_pinctrl_probe(struct platform_device *pdev)
 		return PTR_ERR(pctrl->gcr_regmap);
 	}
 
+	pctrl->rst_regmap =
+		syscon_regmap_lookup_by_compatible("nuvoton,npcm750-rst");
+	if (IS_ERR(pctrl->rst_regmap)) {
+		dev_err(pctrl->dev, "didn't find nuvoton,npcm750-rst\n");
+		return PTR_ERR(pctrl->rst_regmap);
+	}
+
 	ret = npcm7xx_gpio_of(pctrl);
 	if (ret < 0) {
 		dev_err(pctrl->dev, "Failed to gpio dt-binding %u\n", ret);
Signature · 1 line
2.22.0
author maintainer
#15 lore raw

PATCH v3 10/12 spi: npcm-pspi: Add full duplex support

In reply to Tomer Maimon

Modify the IRQ handler in the NPCM PSPI
driver to support SPI full duplex communication.

---
 drivers/spi/spi-npcm-pspi.c | 75 +++++++++++++++----------------------
 1 file changed, 30 insertions(+), 45 deletions(-)
drivers/spi/spi-npcm-pspi.c +30 -45
index 87cd0233c60b..92fae0b23eb1 100644
@@ -197,22 +197,22 @@ static void npcm_pspi_setup_transfer(struct spi_device *spi,
 static void npcm_pspi_send(struct npcm_pspi *priv)
 {
 	int wsize;
-	u16 val;
+	u16 val = 0;
 
 	wsize = min(bytes_per_word(priv->bits_per_word), priv->tx_bytes);
 	priv->tx_bytes -= wsize;
 
-	if (!priv->tx_buf)
-		return;
-
 	switch (wsize) {
 	case 1:
-		val = *priv->tx_buf++;
+		if (priv->tx_buf)
+			val = *priv->tx_buf++;
 		iowrite8(val, NPCM_PSPI_DATA + priv->base);
 		break;
 	case 2:
-		val = *priv->tx_buf++;
-		val = *priv->tx_buf++ | (val << 8);
+		if (priv->tx_buf) {
+			val = *priv->tx_buf++;
+			val = *priv->tx_buf++ | (val << 8);
+		}
 		iowrite16(val, NPCM_PSPI_DATA + priv->base);
 		break;
 	default:
@@ -224,22 +224,24 @@ static void npcm_pspi_send(struct npcm_pspi *priv)
 static void npcm_pspi_recv(struct npcm_pspi *priv)
 {
 	int rsize;
-	u16 val;
+	u16 val_16;
+	u8  val_8;
 
 	rsize = min(bytes_per_word(priv->bits_per_word), priv->rx_bytes);
 	priv->rx_bytes -= rsize;
 
-	if (!priv->rx_buf)
-		return;
-
 	switch (rsize) {
 	case 1:
-		*priv->rx_buf++ = ioread8(priv->base + NPCM_PSPI_DATA);
+		val_8 = ioread8(priv->base + NPCM_PSPI_DATA);
+		if (priv->rx_buf)
+			*priv->rx_buf++ = val_8;
 		break;
 	case 2:
-		val = ioread16(priv->base + NPCM_PSPI_DATA);
-		*priv->rx_buf++ = (val >> 8);
-		*priv->rx_buf++ = val & 0xff;
+		val_16 = ioread16(priv->base + NPCM_PSPI_DATA);
+		if (priv->rx_buf) {
+			*priv->rx_buf++ = (val_16 >> 8);
+			*priv->rx_buf++ = val_16 & 0xff;
+		}
 		break;
 	default:
 		WARN_ON_ONCE(1);
@@ -298,43 +300,26 @@ static irqreturn_t npcm_pspi_handler(int irq, void *dev_id)
 	struct npcm_pspi *priv = dev_id;
 	u8 stat;
 
-	stat = ioread8(priv->base + NPCM_PSPI_STAT);
-
 	if (!priv->tx_buf && !priv->rx_buf)
 		return IRQ_NONE;
 
-	if (priv->tx_buf) {
-		if (stat & NPCM_PSPI_STAT_RBF) {
-			ioread8(NPCM_PSPI_DATA + priv->base);
-			if (priv->tx_bytes == 0) {
-				npcm_pspi_disable(priv);
-				complete(&priv->xfer_done);
-				return IRQ_HANDLED;
-			}
-		}
-
-		if ((stat & NPCM_PSPI_STAT_BSY) == 0)
-			if (priv->tx_bytes)
-				npcm_pspi_send(priv);
+	if (priv->tx_bytes == 0 && priv->rx_bytes == 0) {
+		npcm_pspi_disable(priv);
+		complete(&priv->xfer_done);
+		return IRQ_HANDLED;
 	}
 
-	if (priv->rx_buf) {
-		if (stat & NPCM_PSPI_STAT_RBF) {
-			if (!priv->rx_bytes)
-				return IRQ_NONE;
-
-			npcm_pspi_recv(priv);
+	stat = ioread8(priv->base + NPCM_PSPI_STAT);
 
-			if (!priv->rx_bytes) {
-				npcm_pspi_disable(priv);
-				complete(&priv->xfer_done);
-				return IRQ_HANDLED;
-			}
-		}
+	/*
+	 * first we do the read since if we do the write we previous read might
+	 * be lost (indeed low chances)
+	 */
+	if ((stat & NPCM_PSPI_STAT_RBF) && priv->rx_bytes)
+		npcm_pspi_recv(priv);
 
-		if (((stat & NPCM_PSPI_STAT_BSY) == 0) && !priv->tx_buf)
-			iowrite8(0x0, NPCM_PSPI_DATA + priv->base);
-	}
+	if (((stat & NPCM_PSPI_STAT_BSY) == 0) && priv->tx_bytes)
+		npcm_pspi_send(priv);
 
 	return IRQ_HANDLED;
 }
Signature · 1 line
2.22.0
author maintainer
#16 lore raw

PATCH v3 11/12 dt-binding: bmc: add NPCM7XX JTAG master documentation

In reply to Tomer Maimon

Added device tree binding documentation for
Nuvoton NPCM7XX JTAG master.

---
 .../bindings/bmc/npcm7xx-jtag-master.txt      | 38 +++++++++++++++++++
 1 file changed, 38 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/bmc/npcm7xx-jtag-master.txt
Documentation/devicetree/bindings/bmc/npcm7xx-jtag-master.txt new file +38 -0
new file mode 100644
index 000000000000..3ad7a18ba9a2
@@ -0,0 +1,38 @@
+Nuvoton NPCM7xx JTAG MASTER interface
+
+Nuvoton BMC NPCM7xx JTAG Master is used for debugging host CPU or programming
+CPLD device. The driver is implemented as an SPI device driver that enabling
+the option to transfer JTAG data with the assistance of SPI HW.
+
+Required properties for jtag_master node
+- compatible		: "nuvoton,npcm750-jtag-master" for Poleg NPCM7XX.
+- spi-max-frequency	: specify the max spi bus frequency.
+- reg 				: always 0
+- pinctrl-names		: contain 2 pinctrl states "pspi" and "gpio", which indicates
+					  the TCK/TDI/TDO pin state in HW mode(using PSPI hw) and
+					  SW mode (using GPIO bitbang) respectively.
+- tck-gpios			: specify the GPIO number of TCK pin
+- tdi-gpios			: specify the GPIO number of TDI pin
+- tdo-gpios			: specify the GPIO number of TDO pin
+- tms-gpios			: specify the GPIO number of TMS pin
+
+Example:
+spi1: spi@201000 {
+	...
+	jtag_master {
+		compatible = "nuvoton,npcm750-jtag-master";
+		spi-max-frequency = <25000000>;
+		reg = <0>;
+
+		pinctrl-names = "pspi", "gpio";
+		pinctrl-0 = <&pspi2_pins>;
+		pinctrl-1 = <&gpio17_pins &gpio18o_pins
+			&gpio19ol_pins>;
+
+		tck-gpios = <&gpio0 19 GPIO_ACTIVE_HIGH>;
+		tdi-gpios = <&gpio0 18 GPIO_ACTIVE_HIGH>;
+		tdo-gpios = <&gpio0 17 GPIO_ACTIVE_HIGH>;
+		tms-gpios = <&gpio0 16 GPIO_ACTIVE_HIGH>;
+		status = "okay";
+	};
+};
Signature · 1 line
2.22.0
author maintainer
#17 lore raw

PATCH v3 12/12 misc: npcm7xx-jtag-master: add NPCM7xx JTAG master driver

In reply to Tomer Maimon

Add NPCM7xx JTAG master driver,
The NPCM7xx JTAG master usign GPIO lines
and NPCM PSPI bus.

---
 drivers/misc/Kconfig               |   6 +
 drivers/misc/Makefile              |   1 +
 drivers/misc/npcm7xx-jtag-master.c | 840 +++++++++++++++++++++++++++++
 3 files changed, 847 insertions(+)
 create mode 100644 drivers/misc/npcm7xx-jtag-master.c
drivers/misc/Kconfig +6 -0
index d8626a0d3e31..1b1876284fa6 100644
@@ -478,6 +478,12 @@ config NPCM7XX_PCI_MBOX
 	  Expose the NPCM750/730/715/705 PCI MBOX registers found on
 	  Nuvoton SOCs to userspace.
 
+config NPCM7XX_JTAG_MASTER
+	tristate "NPCM7xx JTAG Master driver"
+	depends on (ARCH_NPCM7XX || COMPILE_TEST)
+	help
+	  Control PSPI/GPIO to transmit jtag signals to support jtag master function.
+
 source "drivers/misc/c2port/Kconfig"
 source "drivers/misc/eeprom/Kconfig"
 source "drivers/misc/cb710/Kconfig"
drivers/misc/Makefile +1 -0
index 183970192ced..b11d3c21fa03 100644
@@ -59,4 +59,5 @@ obj-$(CONFIG_UACCE)		+= uacce/
 obj-$(CONFIG_XILINX_SDFEC)	+= xilinx_sdfec.o
 obj-$(CONFIG_NPCM7XX_LPC_BPC)	+= npcm7xx-lpc-bpc.o
 obj-$(CONFIG_NPCM7XX_PCI_MBOX)	+= npcm7xx-pci-mbox.o
+obj-$(CONFIG_NPCM7XX_JTAG_MASTER)	+= npcm7xx-jtag-master.o
 obj-$(CONFIG_MCTP_LPC)		+= mctp-lpc.o
drivers/misc/npcm7xx-jtag-master.c new file +840 -0

840 lines not on this page · raw message

Signature · 1 line
2.22.0
author maintainer Reviewed-by Joel Stanley on v3 7/12
#12 lore raw

Re: [PATCH linux dev-5.8 v3 07/12] pinctrl: npcm7xx: Add HGPIO pin support to NPCM7xx pinctrl driver

In reply to Tomer Maimon

Sorry, forgot to add it this patch already approved.

Quoted 1 line · Tomer Maimon
Quoted 164 lines
---
 drivers/pinctrl/nuvoton/pinctrl-npcm7xx.c | 65 +++++++++++++++++------
 1 file changed, 49 insertions(+), 16 deletions(-)
drivers/pinctrl/nuvoton/pinctrl-npcm7xx.c +33 -4
index a935065cdac4..e5f58ea89917 100644
@@ -504,6 +504,15 @@ static const int lkgpo2_pins[] = { 9 };
 
 static const int nprd_smi_pins[] = { 190 };
 
+static const int hgpio0_pins[] = { 20 };
+static const int hgpio1_pins[] = { 21 };
+static const int hgpio2_pins[] = { 22 };
+static const int hgpio3_pins[] = { 23 };
+static const int hgpio4_pins[] = { 24 };
+static const int hgpio5_pins[] = { 25 };
+static const int hgpio6_pins[] = { 59 };
+static const int hgpio7_pins[] = { 60 };
+
 /*
  * pin:             name, number
  * group:    name, npins,   pins
@@ -631,6 +640,14 @@ struct npcm7xx_group {
        NPCM7XX_GRP(lkgpo1), \
        NPCM7XX_GRP(lkgpo2), \
        NPCM7XX_GRP(nprd_smi), \
+       NPCM7XX_GRP(hgpio0), \
+       NPCM7XX_GRP(hgpio1), \
+       NPCM7XX_GRP(hgpio2), \
+       NPCM7XX_GRP(hgpio3), \
+       NPCM7XX_GRP(hgpio4), \
+       NPCM7XX_GRP(hgpio5), \
+       NPCM7XX_GRP(hgpio6), \
+       NPCM7XX_GRP(hgpio7), \
        \
 
 enum {
@@ -774,6 +791,14 @@ NPCM7XX_SFUNC(lkgpo0);
 NPCM7XX_SFUNC(lkgpo1);
 NPCM7XX_SFUNC(lkgpo2);
 NPCM7XX_SFUNC(nprd_smi);
+NPCM7XX_SFUNC(hgpio0);
+NPCM7XX_SFUNC(hgpio1);
+NPCM7XX_SFUNC(hgpio2);
+NPCM7XX_SFUNC(hgpio3);
+NPCM7XX_SFUNC(hgpio4);
+NPCM7XX_SFUNC(hgpio5);
+NPCM7XX_SFUNC(hgpio6);
+NPCM7XX_SFUNC(hgpio7);
 
 /* Function names */
 static struct npcm7xx_func npcm7xx_funcs[] = {
@@ -892,6 +917,14 @@ static struct npcm7xx_func npcm7xx_funcs[] = {
        NPCM7XX_MKFUNC(lkgpo1),
        NPCM7XX_MKFUNC(lkgpo2),
        NPCM7XX_MKFUNC(nprd_smi),
+       NPCM7XX_MKFUNC(hgpio0),
+       NPCM7XX_MKFUNC(hgpio1),
+       NPCM7XX_MKFUNC(hgpio2),
+       NPCM7XX_MKFUNC(hgpio3),
+       NPCM7XX_MKFUNC(hgpio4),
+       NPCM7XX_MKFUNC(hgpio5),
+       NPCM7XX_MKFUNC(hgpio6),
+       NPCM7XX_MKFUNC(hgpio7),
 };
 
 #define NPCM7XX_PINCFG(a, b, c, d, e, f, g, h, i, j, k) \
@@ -944,12 +977,12 @@ static const struct npcm7xx_pincfg pincfg[] = {
        NPCM7XX_PINCFG(17,      pspi2, MFSEL3, 13,     smb4den, I2CSEGSEL,
 23,  none, NONE, 0,       DS(8, 12)),
        NPCM7XX_PINCFG(18,      pspi2, MFSEL3, 13,       smb4b, I2CSEGSEL,
 14,  none, NONE, 0,       DS(8, 12)),
        NPCM7XX_PINCFG(19,      pspi2, MFSEL3, 13,       smb4b, I2CSEGSEL,
 14,  none, NONE, 0,       DS(8, 12)),
-       NPCM7XX_PINCFG(20,      smb4c, I2CSEGSEL, 15,    smb15, MFSEL3,
 8,      none, NONE, 0,       0),
-       NPCM7XX_PINCFG(21,      smb4c, I2CSEGSEL, 15,    smb15, MFSEL3,
 8,      none, NONE, 0,       0),
-       NPCM7XX_PINCFG(22,      smb4d, I2CSEGSEL, 16,    smb14, MFSEL3,
 7,      none, NONE, 0,       0),
-       NPCM7XX_PINCFG(23,      smb4d, I2CSEGSEL, 16,    smb14, MFSEL3,

7, none, NONE, 0, 0),

drivers/pinctrl/nuvoton/pinctrl-npcm7xx.c +1 -2
-       NPCM7XX_PINCFG(24,       ioxh, MFSEL3, 18,        none, NONE, 0,
      none, NONE, 0,       DS(8, 12)),
-       NPCM7XX_PINCFG(25,       ioxh, MFSEL3, 18,        none, NONE, 0,
      none, NONE, 0,       DS(8, 12)),
+       NPCM7XX_PINCFG(20,      hgpio0, MFSEL2, 24,      smb15, MFSEL3,
8,      smb4c, I2CSEGSEL, 15,        0),
+       NPCM7XX_PINCFG(21,      hgpio1, MFSEL2, 25,      smb15, MFSEL3,
8,      smb4c, I2CSEGSEL, 15,        0),
+       NPCM7XX_PINCFG(22,      hgpio2, MFSEL2, 26,      smb14, MFSEL3,
7,      smb4d, I2CSEGSEL, 16,        0),
+       NPCM7XX_PINCFG(23,      hgpio3, MFSEL2, 27,      smb14, MFSEL3,
7,      smb4d, I2CSEGSEL, 16,        0),
drivers/pinctrl/nuvoton/pinctrl-npcm7xx.c +3 -2
+       NPCM7XX_PINCFG(24,       hgpio4, MFSEL2, 28,    ioxh, MFSEL3, 18,
     none, NONE, 0,       DS(8, 12)),
+       NPCM7XX_PINCFG(25,       hgpio5, MFSEL2, 29,    ioxh, MFSEL3, 18,
     none, NONE, 0,       DS(8, 12)),
        NPCM7XX_PINCFG(26,       smb5, MFSEL1, 2,         none, NONE, 0,
      none, NONE, 0,       0),
        NPCM7XX_PINCFG(27,       smb5, MFSEL1, 2,         none, NONE, 0,
      none, NONE, 0,       0),
        NPCM7XX_PINCFG(28,       smb4, MFSEL1, 1,         none, NONE, 0,
      none, NONE, 0,       0),
@@ -982,8 +1015,8 @@ static const struct npcm7xx_pincfg pincfg[] = {
        NPCM7XX_PINCFG(56,      r1err, MFSEL1, 12,        none, NONE, 0,
      none, NONE, 0,       0),
        NPCM7XX_PINCFG(57,       r1md, MFSEL1, 13,        none, NONE, 0,
      none, NONE, 0,       DS(2, 4)),
        NPCM7XX_PINCFG(58,       r1md, MFSEL1, 13,        none, NONE, 0,
      none, NONE, 0,       DS(2, 4)),
-       NPCM7XX_PINCFG(59,      smb3d, I2CSEGSEL, 13,     none, NONE, 0,
      none, NONE, 0,       0),
-       NPCM7XX_PINCFG(60,      smb3d, I2CSEGSEL, 13,     none, NONE, 0,
      none, NONE, 0,       0),
+       NPCM7XX_PINCFG(59,      hgpio6, MFSEL2, 30,       smb3d,

I2CSEGSEL, 13, none, NONE, 0, 0),
+ NPCM7XX_PINCFG(60, hgpio7, MFSEL2, 31, smb3d,
I2CSEGSEL, 13, none, NONE, 0, 0),

        NPCM7XX_PINCFG(61,      uart1, MFSEL1, 10,        none, NONE, 0,
      none, NONE, 0,     GPO),
        NPCM7XX_PINCFG(62,      uart1, MFSEL1, 10,    bmcuart1, MFSEL3,
24,     none, NONE, 0,     GPO),
        NPCM7XX_PINCFG(63,      uart1, MFSEL1, 10,    bmcuart1, MFSEL3,

24, none, NONE, 0, GPO),

drivers/pinctrl/nuvoton/pinctrl-npcm7xx.c +6 -6
@@ -1188,12 +1221,12 @@ static const struct pinctrl_pin_desc
 npcm7xx_pins[] = {
        PINCTRL_PIN(17, "GPIO17/PSPI2DI/SMB4DEN"),
        PINCTRL_PIN(18, "GPIO18/PSPI2D0/SMB4BSDA"),
        PINCTRL_PIN(19, "GPIO19/PSPI2CK/SMB4BSCL"),
-       PINCTRL_PIN(20, "GPIO20/SMB4CSDA/SMB15SDA"),
-       PINCTRL_PIN(21, "GPIO21/SMB4CSCL/SMB15SCL"),
-       PINCTRL_PIN(22, "GPIO22/SMB4DSDA/SMB14SDA"),
-       PINCTRL_PIN(23, "GPIO23/SMB4DSCL/SMB14SCL"),
-       PINCTRL_PIN(24, "GPIO24/IOXHDO"),
-       PINCTRL_PIN(25, "GPIO25/IOXHDI"),
+       PINCTRL_PIN(20, "GPIO20/HGPIO0/SMB4CSDA/SMB15SDA"),
+       PINCTRL_PIN(21, "GPIO21/HGPIO1/SMB4CSCL/SMB15SCL"),
+       PINCTRL_PIN(22, "GPIO22/HGPIO2/SMB4DSDA/SMB14SDA"),
+       PINCTRL_PIN(23, "GPIO23/HGPIO3/SMB4DSCL/SMB14SCL"),
+       PINCTRL_PIN(24, "GPIO24/HGPIO4/IOXHDO"),
+       PINCTRL_PIN(25, "GPIO25/HGPIO5/IOXHDI"),
        PINCTRL_PIN(26, "GPIO26/SMB5SDA"),
        PINCTRL_PIN(27, "GPIO27/SMB5SCL"),
        PINCTRL_PIN(28, "GPIO28/SMB4SDA"),
drivers/pinctrl/nuvoton/pinctrl-npcm7xx.c +2 -2
@@ -1226,8 +1259,8 @@ static const struct pinctrl_pin_desc npcm7xx_pins[]
 = {
        PINCTRL_PIN(56, "GPIO56/R1RXERR"),
        PINCTRL_PIN(57, "GPIO57/R1MDC"),
        PINCTRL_PIN(58, "GPIO58/R1MDIO"),
-       PINCTRL_PIN(59, "GPIO59/SMB3DSDA"),
-       PINCTRL_PIN(60, "GPIO60/SMB3DSCL"),
+       PINCTRL_PIN(59, "GPIO59/HGPIO6/SMB3DSDA"),
+       PINCTRL_PIN(60, "GPIO60/HGPIO7/SMB3DSCL"),
        PINCTRL_PIN(61, "GPO61/nDTR1_BOUT1/STRAP6"),
        PINCTRL_PIN(62, "GPO62/nRTST1/STRAP5"),
        PINCTRL_PIN(63, "GPO63/TXD1/STRAP4"),

--
2.22.0

Reviewed-by on v3 3/12
#6 lore raw

Re: [PATCH linux dev-5.8 v3 03/12] iio: adc: add calibration support to npcm ADC

In reply to Tomer Maimon
Quoted 7 lines · Tomer Maimon

Add calibration to improve accuracy measurement when using internal reference voltage.

the calibration values taken from the FUSE module.

When submitting this to mainline you should consider putting the fuse reading code in it's own driver if it is to be used by other components in your system.

Quoted 231 lines
---
 drivers/iio/adc/npcm_adc.c | 178 +++++++++++++++++++++++++++++++++++++
 1 file changed, 178 insertions(+)
drivers/iio/adc/npcm_adc.c +178 -1
index 83bad2d5575d..081378b98fa9 100644
@@ -17,6 +17,8 @@
 #include <linux/reset.h>
 
 struct npcm_adc {
+       u32 R05;
+       u32 R15;
        bool int_status;
        u32 adc_sample_hz;
        struct device *dev;
@@ -51,6 +53,41 @@ struct npcm_adc {
 #define NPCM_RESOLUTION_BITS           10
 #define NPCM_INT_VREF_MV               2000
 
+/* FUSE registers */
+#define NPCM7XX_FST            0x00
+#define NPCM7XX_FADDR          0x04
+#define NPCM7XX_FDATA          0x08
+#define NPCM7XX_FCFG           0x0C
+#define NPCM7XX_FCTL           0x14
+
+/* FST Register Bits */
+#define NPCM7XX_FST_RDY                BIT(0)
+#define NPCM7XX_FST_RDST       BIT(1)
+
+/* FADDR Register Bits */
+#define NPCM7XX_FADDR_BYTEADDR         BIT(0)
+#define NPCM7XX_FADDR_BYTEADDR_MASK    GENMASK(9, 0)
+
+/* FADDR Register Bits */
+#define NPCM7XX_FDATA_DATA             BIT(0)
+#define NPCM7XX_FDATA_CLEAN_VALUE      BIT(1)
+#define NPCM7XX_FDATA_DATA_MASK                GENMASK(7, 0)
+
+/* FCTL Register Bits */
+#define NPCM7XX_FCTL_RDST              BIT(1)
+
+/* ADC Calibration Definition */
+#define NPCM_INT_1500MV                768
+#define NPCM_INT_1000MV                512
+#define NPCM_ADC_MIN_VAL       0
+#define NPCM_ADC_MAX_VAL       1023
+
+#define FUSE_CALIB_ADDR                24
+#define FUSE_CALIB_SIZE                8
+#define DATA_CALIB_SIZE                4
+#define FUSE_READ_SLEEP                500
+#define FUSE_READ_TIMEOUT      1000000
+
 #define NPCM_ADC_CHAN(ch) {                                    \
        .type = IIO_VOLTAGE,                                    \
        .indexed = 1,                                           \
@@ -71,6 +108,119 @@ static const struct iio_chan_spec npcm_adc_iio_channels[] = {
        NPCM_ADC_CHAN(7),
 };
 
+static void npcm750_fuse_read(struct regmap *fuse_regmap, u32 addr, u8 *data)
+{
+       u32 val;
+       u32 fstreg;
+
+       regmap_read_poll_timeout(fuse_regmap, NPCM7XX_FST, fstreg,
+                                fstreg & NPCM7XX_FST_RDY, FUSE_READ_SLEEP,
+                                FUSE_READ_TIMEOUT);
+       regmap_write_bits(fuse_regmap, NPCM7XX_FST,
+                         NPCM7XX_FST_RDST, NPCM7XX_FST_RDST);
+
+       regmap_write_bits(fuse_regmap, NPCM7XX_FADDR,
+                         NPCM7XX_FADDR_BYTEADDR_MASK, addr);
+       regmap_read(fuse_regmap, NPCM7XX_FADDR, &val);
+       regmap_write(fuse_regmap, NPCM7XX_FCTL, NPCM7XX_FCTL_RDST);
+
+       regmap_read_poll_timeout(fuse_regmap, NPCM7XX_FST, fstreg,
+                                fstreg & NPCM7XX_FST_RDY, FUSE_READ_SLEEP,
+                                FUSE_READ_TIMEOUT);
+       regmap_write_bits(fuse_regmap, NPCM7XX_FST,
+                         NPCM7XX_FST_RDST, NPCM7XX_FST_RDST);
+
+       regmap_read(fuse_regmap, NPCM7XX_FDATA, &val);
+       *data = (u8)val;
+
+       regmap_write_bits(fuse_regmap, NPCM7XX_FDATA, NPCM7XX_FDATA_DATA_MASK,
+                         NPCM7XX_FDATA_CLEAN_VALUE);
+}
+
+static int npcm750_ECC_to_nibble(u8 ECC, u8 nibble)
+{
+       u8 nibble_b0 = (nibble >> 0) & BIT(0);
+       u8 nibble_b1 = (nibble >> 1) & BIT(0);
+       u8 nibble_b2 = (nibble >> 2) & BIT(0);
+       u8 nibble_b3 = (nibble >> 3) & BIT(0);
+       u8 tmp_ECC = nibble;
+
+       tmp_ECC |= (nibble_b0 ^ nibble_b1) << 4 | (nibble_b2 ^ nibble_b3) << 5 |
+               (nibble_b0 ^ nibble_b2) << 6  | (nibble_b1 ^ nibble_b3) << 7;
+
+       if (tmp_ECC != ECC)
+               return -EINVAL;
+
+       return 0;
+}
+
+static int npcm750_ECC_to_byte(u16 ECC, u8 *Byte)
+{
+       u8 nibble_L, nibble_H;
+       u8 ECC_L, ECC_H;
+
+       ECC_H = ECC >> 8;
+       nibble_H = ECC_H & 0x0F;
+       ECC_L = ECC >> 0;
+       nibble_L = ECC_L & 0x0F;
+
+       if (npcm750_ECC_to_nibble(ECC_H, nibble_H) != 0 ||
+           npcm750_ECC_to_nibble(ECC_L, nibble_L) != 0)
+               return -EINVAL;
+
+       *Byte = nibble_H << 4 | nibble_L << 0;
+
+       return 0;
+}
+
+static int npcm750_read_nibble_parity(u8 *block_ECC, u8 *ADC_calib)
+{
+       int i;
+       u16 ECC;
+
+       for (i = 0; i < DATA_CALIB_SIZE; i++) {
+               memcpy(&ECC, block_ECC + (i * 2), 2);
+               if (npcm750_ECC_to_byte(ECC, &ADC_calib[i]) != 0)
+                       return -EINVAL;
+       }
+
+       return 0;
+}
+
+static int npcm750_fuse_calibration_read(struct platform_device *pdev,
+                                        struct npcm_adc *info)
+{
+       struct device_node *np = pdev->dev.of_node;
+       struct regmap *fuse_regmap;
+       ssize_t bytes_read = 0;
+       u8 read_buf[8];
+       u32 ADC_calib;
+       u32 addr = FUSE_CALIB_ADDR;
+
+       fuse_regmap = syscon_regmap_lookup_by_phandle(np, "syscon");
+       if (IS_ERR(fuse_regmap)) {
+               dev_warn(&pdev->dev, "Failed to find syscon\n");
+               return PTR_ERR(fuse_regmap);
+       }
+
+       while (bytes_read < FUSE_CALIB_SIZE) {
+               npcm750_fuse_read(fuse_regmap, addr,
+                                 &read_buf[bytes_read]);
+               bytes_read++;
+               addr++;
+       }
+
+       if (npcm750_read_nibble_parity(read_buf, (u8 *)&ADC_calib)) {
+               dev_warn(info->dev, "FUSE Calibration read failed\n");
+               return -EINVAL;
+       }
+
+       info->R05 = ADC_calib & 0xFFFF;
+       info->R15 = ADC_calib >> 16;
+
+       return 0;
+}
+
 static irqreturn_t npcm_adc_isr(int irq, void *data)
 {
        u32 regtemp;
@@ -125,6 +275,29 @@ static int npcm_adc_read(struct npcm_adc *info, int *val, u8 channel)
        return 0;
 }
 
+static void npcm_adc_calibration(int *val, struct npcm_adc *info)
+{
+       int mul_val;
+       int offset_val;
+
+       mul_val = NPCM_INT_1000MV * (*val - info->R15);
+       if (mul_val < 0) {
+               mul_val = mul_val * -1;
+               offset_val = DIV_ROUND_CLOSEST(mul_val,
+                                              (info->R15 - info->R05));
+               *val = NPCM_INT_1500MV - offset_val;
+       } else {
+               offset_val = DIV_ROUND_CLOSEST(mul_val,
+                                              (info->R15 - info->R05));
+               *val = NPCM_INT_1500MV + offset_val;
+       }
+
+       if (*val < NPCM_ADC_MIN_VAL)
+               *val = NPCM_ADC_MIN_VAL;
+       if (*val > NPCM_ADC_MAX_VAL)
+               *val = NPCM_ADC_MAX_VAL;
+}
+
 static int npcm_adc_read_raw(struct iio_dev *indio_dev,
                             struct iio_chan_spec const *chan, int *val,
                             int *val2, long mask)
@@ -142,6 +315,10 @@ static int npcm_adc_read_raw(struct iio_dev *indio_dev,
                        dev_err(info->dev, "NPCM ADC read failed\n");
                        return ret;
                }
+
+               if ((info->R05 || info->R15) && IS_ERR(info->vref))
+                       npcm_adc_calibration(val, info);
+
                return IIO_VAL_INT;
        case IIO_CHAN_INFO_SCALE:
                if (!IS_ERR(info->vref)) {
@@ -248,6 +425,7 @@ static int npcm_adc_probe(struct platform_device *pdev)
                          info->regs + NPCM_ADCCON);
        }
 
+       npcm750_fuse_calibration_read(pdev, info);
        init_waitqueue_head(&info->wq);
 
        reg_con = ioread32(info->regs + NPCM_ADCCON);
--

2.22.0

Reviewed-by on v3 4/12
#8 lore raw

Re: [PATCH linux dev-5.8 v3 04/12] dts: npcm750: add fuse regmap support node

In reply to Tomer Maimon
Quoted 2 lines · Tomer Maimon
Quoted 9 lines
---
 arch/arm/boot/dts/nuvoton-common-npcm7xx.dtsi | 6 ++++++
 1 file changed, 6 insertions(+)
arch/arm/boot/dts/nuvoton-common-npcm7xx.dtsi +0 -0
index 7eee4145127f..455a96b23b85 100644

arch/arm/boot/dts/nuvoton-common-npcm7xx.dtsi line 86

Quoted 5 lines
arch/arm/boot/dts/nuvoton-common-npcm7xx.dtsi +2 -0
@@ -82,6 +82,12 @@
                        "simple-mfd";
                        reg = <0x801000 0x6C>;
                };
+
+               fuse:fuse@18a000 {

Convention is to put a space after the colon. No need to re-post, but remember this for future patches.

Quoted 10 lines
arch/arm/boot/dts/nuvoton-common-npcm7xx.dtsi +4 -1
+                       compatible = "nuvoton,npcm750-fuse", "syscon",
+                               "simple-mfd";
+                       reg = <0x18a000 0x1000>;
+               };
 
                scu: scu@3fe000 {
                        compatible = "arm,cortex-a9-scu";
--

2.22.0

Reviewed-by on v3 2/12
#4 lore raw

Re: [PATCH linux dev-5.8 v3 02/12] dt-binding: iio: add syscon property to NPCM ADC

In reply to Tomer Maimon
Quoted 5 lines · Tomer Maimon

Add syscon property to NPCM ADC to handle FUSE
registers.

Quoted 25 lines
---
 Documentation/devicetree/bindings/iio/adc/nuvoton,npcm-adc.txt | 2 ++
 1 file changed, 2 insertions(+)
Documentation/devicetree/bindings/iio/adc/nuvoton,npcm-adc.txt +2 -1
index ef8eeec1a997..faf9f9b54f5b 100644
@@ -14,6 +14,7 @@ Optional properties:
 - vref-supply: The regulator supply ADC reference voltage, in case the
                           vref-supply is not added the ADC will use internal voltage
                           reference.
+- syscon: a phandle to access FUSE registers
 
 Example:
 
@@ -23,4 +24,5 @@ adc: adc@f000c000 {
        interrupts = <GIC_SPI 0 IRQ_TYPE_LEVEL_HIGH>;
        clocks = <&clk NPCM7XX_CLK_ADC>;
        resets = <&rstc NPCM7XX_RESET_IPSRST1 NPCM7XX_RESET_ADC>;
+       syscon = <&fuse>;
 };
--

2.22.0

#18 lore raw
In reply to Tomer Maimon

Hi Tomer,

Quoted 3 lines · Tomer Maimon

In this patch set we will like to align with relevant modifications in Nuvoton OpenBMC Linux kernel 5.4.

I've reviewed some of the patches. There is some work to be done before some of them will be accepted for mainline, but nothing that blocks them from being in the openbmc tree, so I have merged the series.

I've bumped the kernel in meta-nuvoton, please review that change:

https://gerrit.openbmc-project.xyz/c/openbmc/meta-nuvoton/+/39742

Cheers,

Joel

Quoted 58 lines

Linux upstream current status:
1. npcm7xx clock driver - adding read only
flag to divider clocks, Will be sent to Linux community.
2. Adding NPCM ADC calibration - Will be sent to Linux vanilla, but I am not sure it will be approved.
3. Add DT restart priority and reset type support - sent to Linux community la but havent approved yet.
4. persist configuration to the pin control driver - asked by a costumer, didnt sent to Linux community.
5. Add HGPIO pin support to NPCM7xx pinctrl driver - will be sent to Linux community
6. JTAG master driver - will be sent to Linux community once we will have BMC folder.

Changes since version 2:
- Address comments from Joel Stanley

Changes since version 1:
- Address comments from Jonathan Neuschäfer: removing trailing whitespace in NPCM watchdog documentation.
- Adding Stanley Chu to NPCM JTAG master driver

Tomer Maimon (12):
clk: npcm7xx: add read only flag to divider clocks
dt-binding: iio: add syscon property to NPCM ADC
iio: adc: add calibration support to npcm ADC
dts: npcm750: add fuse regmap support node
dt-binding: watchdog: Add DT restart priority and reset type
watchdog: npcm: Add DT restart priority and reset type support
pinctrl: npcm7xx: Add HGPIO pin support to NPCM7xx pinctrl driver
pinctrl: pinconf: add pin persist configuration
pinctrl: npcm7xx: Add pin persist configuration support
spi: npcm-pspi: Add full duplex support
dt-binding: bmc: add NPCM7XX JTAG master documentation
misc: npcm7xx-jtag-master: add NPCM7xx JTAG master driver

 .../bindings/bmc/npcm7xx-jtag-master.txt      |  38 +
 .../bindings/iio/adc/nuvoton,npcm-adc.txt     |   2 +
 .../bindings/watchdog/nuvoton,npcm-wdt.txt    |  34 +
 arch/arm/boot/dts/nuvoton-common-npcm7xx.dtsi |   6 +
 drivers/clk/clk-npcm7xx.c                     |  70 +-
 drivers/iio/adc/npcm_adc.c                    | 178 ++++
 drivers/misc/Kconfig                          |   6 +
 drivers/misc/Makefile                         |   1 +
 drivers/misc/npcm7xx-jtag-master.c            | 840 ++++++++++++++++++
 drivers/pinctrl/nuvoton/pinctrl-npcm7xx.c     | 130 ++-
 drivers/pinctrl/pinconf-generic.c             |   3 +
 drivers/spi/spi-npcm-pspi.c                   |  75 +-
 drivers/watchdog/npcm_wdt.c                   | 117 ++-
 13 files changed, 1404 insertions(+), 96 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/bmc/npcm7xx-jtag-master.txt
 create mode 100644 drivers/misc/npcm7xx-jtag-master.c

--
2.22.0