Skip to contentSkip to conversation

Microchip PolarFire SoC support

PATCH Superseded Padmarao Begari 4 participants 15 messages Dec 14, 2020 – Dec 21, 2020

Subsystems (4)

v6 of 9 Superseded Latest is v9 →

lore
Share & tools
lore
#0 lore raw

v6 cover Microchip PolarFire SoC support

This patch set adds Microchip PolarFire SoC Icicle Kit support to RISC-V U-Boot.

The patches are based upon latest U-Boot tree
(https://gitlab.denx.de/u-boot/u-boot.git) at commit id 5a1a8a63be8f7262a300eddafb18020926b12fb6

All drivers namely: NS16550 Serial, Microchip clock, Cadence eMMC and Cadence MACB Ethernet work fine on actual Microchip PolarFire SoC Icicle Kit.

Changes in v6:
- Update MACB driver for 32-bit/64-bit DMA based on struct mac_config
- Rename microchip,mpfs-clock.h to microchip-mpfs-clock.h
- Add dual-license GPL or MIT in the clock dt-binding
- Move refclk device tree node under / device tree node
- Remove the dtc warnings
- Fix some typos in device tree and doc

Changes in v5:
- Replace compatible string "microchip,polarfire-soc" with "microchip,mpfs-icicle-kit" in the device tree
- Use "mpfs" as identifier in place of "polarfire-soc", "pfsoc"
- Fix some typos in doc
- Rename the clock driver files clk_pfsoc_* to mpfs_clk_*
- Rename pfsoc-clock.h to mpfs-clock.h

Changes in v4:
- Add dual-license GPL or MIT in the device tree
- Replace microsemi compatible strings with microchip
- Add MACB compatible string for Microchip PolarFire SoC ethernet
- Update MACB driver for 32-bit/64-bit DMA based on compatible string

Changes in v3:
- Add 'default y if 64BIT' for config DMA_ADDR_T_64BIT
- Update MACB driver for 32-bit/64-bit DMA based on design config register
- Add phy-handle in MACB driver to read the phy address from device tree
- Fix checkpatch warnings in the clock driver
- Remove fu540 related compatible strings from soc device tree node
- Move refclk device tree node under /soc device tree node
- Use local-mac-address instead of mac-address in the device tree
- Rename device tree to microchip-mpfs-icicle-kit.dts
- Add U-Boot specific dts microchip-mpfs-icicle-kit-u-boot.dtsi file
- Drop the imply DMA_ADDR_T_64BIT from board config
- Fix some typos
- Update doc with Microchip and Custom boot-flow

Changes in v2:
- Add clock frequency for the clint device tree node
- Move peripheral device tree nodes under /soc device tree node
- Device tree nodes are in order based on the address
- Enable UART0 for U-Boot logs
- Update doc for the U-Boot logs are on UART0
- Move clock and reset index source into patch4
- Remove "dma_addr_r" type in the macb driver
- Add lower_32_bits() for 32-bit address in the macb driver
- Add set_rate() returns the new clock rate in the clock driver

Padmarao Begari (7):
riscv: Add DMA 64-bit address support
net: macb: Add DMA 64-bit address support for macb
net: macb: Add phy address to read it from device tree
clk: Add Microchip PolarFire SoC clock driver
riscv: dts: Add device tree for Microchip Icicle Kit
riscv: Add Microchip MPFS Icicle Kit support
doc: board: Add Microchip MPFS Icicle Kit doc

 arch/riscv/Kconfig                            |   4 +
 arch/riscv/dts/Makefile                       |   1 +
 .../dts/microchip-mpfs-icicle-kit-u-boot.dtsi |  14 +
 arch/riscv/dts/microchip-mpfs-icicle-kit.dts  | 421 +++++++++
 arch/riscv/include/asm/types.h                |   4 +
 board/microchip/mpfs_icicle/Kconfig           |  23 +
 board/microchip/mpfs_icicle/mpfs_icicle.c     |  99 ++-
 configs/microchip_mpfs_icicle_defconfig       |   9 +-
 doc/board/index.rst                           |   1 +
 doc/board/microchip/index.rst                 |   9 +
 doc/board/microchip/mpfs_icicle.rst           | 816 ++++++++++++++++++
 drivers/clk/Kconfig                           |   1 +
 drivers/clk/Makefile                          |   1 +
 drivers/clk/microchip/Kconfig                 |   5 +
 drivers/clk/microchip/Makefile                |   1 +
 drivers/clk/microchip/mpfs_clk.c              | 127 +++
 drivers/clk/microchip/mpfs_clk.h              |  19 +
 drivers/clk/microchip/mpfs_clk_cfg.c          | 134 +++
 drivers/clk/microchip/mpfs_clk_periph.c       | 173 ++++
 drivers/net/macb.c                            | 144 +++-
 drivers/net/macb.h                            |   6 +
 include/configs/microchip_mpfs_icicle.h       |  60 +-
 .../dt-bindings/clock/microchip-mpfs-clock.h  |  45 +
 23 files changed, 2055 insertions(+), 62 deletions(-)
 create mode 100644 arch/riscv/dts/microchip-mpfs-icicle-kit-u-boot.dtsi
 create mode 100644 arch/riscv/dts/microchip-mpfs-icicle-kit.dts
 create mode 100644 doc/board/microchip/index.rst
 create mode 100644 doc/board/microchip/mpfs_icicle.rst
 create mode 100644 drivers/clk/microchip/Kconfig
 create mode 100644 drivers/clk/microchip/Makefile
 create mode 100644 drivers/clk/microchip/mpfs_clk.c
 create mode 100644 drivers/clk/microchip/mpfs_clk.h
 create mode 100644 drivers/clk/microchip/mpfs_clk_cfg.c
 create mode 100644 drivers/clk/microchip/mpfs_clk_periph.c
 create mode 100644 include/dt-bindings/clock/microchip-mpfs-clock.h
Signature · 1 line
2.17.1
#1 lore raw

PATCH v6 1/7 riscv: Add DMA 64-bit address support

dma_addr_t holds any valid DMA address. If the DMA API only uses 32/64-bit addresses, dma_addr_t need only be 32/64 bits wide.

---
 arch/riscv/Kconfig             | 4 ++++
 arch/riscv/include/asm/types.h | 4 ++++
 2 files changed, 8 insertions(+)
arch/riscv/Kconfig +4 -0
index 30b05408b1..55eaee2da6 100644
@@ -152,6 +152,10 @@ config 32BIT
 config 64BIT
 	bool
 
+config DMA_ADDR_T_64BIT
+	bool
+	default y if 64BIT
+
 config SIFIVE_CLINT
 	bool
 	depends on RISCV_MMODE || SPL_RISCV_MMODE
arch/riscv/include/asm/types.h +4 -0
index 403cf9a48f..b800b2d221 100644
@@ -29,7 +29,11 @@ typedef unsigned short umode_t;
 
 #include <stddef.h>
 
+#ifdef CONFIG_DMA_ADDR_T_64BIT
+typedef u64 dma_addr_t;
+#else
 typedef u32 dma_addr_t;
+#endif
 
 typedef unsigned long phys_addr_t;
 typedef unsigned long phys_size_t;
Signature · 1 line
2.17.1
#3 lore raw

PATCH v6 2/7 net: macb: Add DMA 64-bit address support for macb

In reply to Padmarao Begari

Enable 32-bit or 64-bit DMA in the macb driver based on the macb hardware compatibility and it is configured with structure macb_config in the driver.

The Microchip PolarFire SoC Memory Protection Unit(MPU) gives the 64-bit DMA access with the GEM, the MPU transactions on the AXI bus is 64-bit not 32-bit So 64-bit DMA is enabled for the Microchip PolarFire SoC GEM.

---
 drivers/net/macb.c | 131 +++++++++++++++++++++++++++++++++++++++------
 drivers/net/macb.h |   6 +++
 2 files changed, 120 insertions(+), 17 deletions(-)
drivers/net/macb.c +114 -17
index b80a259ff7..626ee49227 100644
@@ -83,7 +83,16 @@ struct macb_dma_desc {
 	u32	ctrl;
 };
 
-#define DMA_DESC_BYTES(n)	(n * sizeof(struct macb_dma_desc))
+struct macb_dma_desc_64 {
+	u32 addrh;
+	u32 unused;
+};
+
+#define HW_DMA_CAP_32B		0
+#define HW_DMA_CAP_64B		1
+
+#define DMA_DESC_SIZE		16
+#define DMA_DESC_BYTES(n)	((n) * DMA_DESC_SIZE)
 #define MACB_TX_DMA_DESC_SIZE	(DMA_DESC_BYTES(MACB_TX_RING_SIZE))
 #define MACB_RX_DMA_DESC_SIZE	(DMA_DESC_BYTES(MACB_RX_RING_SIZE))
 #define MACB_TX_DUMMY_DMA_DESC_SIZE	(DMA_DESC_BYTES(1))
@@ -137,6 +146,7 @@ struct macb_device {
 
 struct macb_config {
 	unsigned int		dma_burst_length;
+	unsigned int		hw_dma_cap;
 
 	int			(*clk_init)(struct udevice *dev, ulong rate);
 };
@@ -307,6 +317,24 @@ static inline void macb_invalidate_rx_buffer(struct macb_device *macb)
 
 #if defined(CONFIG_CMD_NET)
 
+static struct macb_dma_desc_64 *macb_64b_desc(struct macb_dma_desc *desc)
+{
+	return (struct macb_dma_desc_64 *)((void *)desc
+		+ sizeof(struct macb_dma_desc));
+}
+
+static void macb_set_addr(struct macb_device *macb, struct macb_dma_desc *desc,
+			  ulong addr)
+{
+	struct macb_dma_desc_64 *desc_64;
+
+	if (macb->config->hw_dma_cap & HW_DMA_CAP_64B) {
+		desc_64 = macb_64b_desc(desc);
+		desc_64->addrh = upper_32_bits(addr);
+	}
+	desc->addr = lower_32_bits(addr);
+}
+
 static int _macb_send(struct macb_device *macb, const char *name, void *packet,
 		      int length)
 {
@@ -325,8 +353,12 @@ static int _macb_send(struct macb_device *macb, const char *name, void *packet,
 		macb->tx_head++;
 	}
 
+	if (macb->config->hw_dma_cap & HW_DMA_CAP_64B)
+		tx_head = tx_head * 2;
+
 	macb->tx_ring[tx_head].ctrl = ctrl;
-	macb->tx_ring[tx_head].addr = paddr;
+	macb_set_addr(macb, &macb->tx_ring[tx_head], paddr);
+
 	barrier();
 	macb_flush_ring_desc(macb, TX);
 	macb_writel(macb, NCR, MACB_BIT(TE) | MACB_BIT(RE) | MACB_BIT(TSTART));
@@ -363,19 +395,28 @@ static void reclaim_rx_buffers(struct macb_device *macb,
 			       unsigned int new_tail)
 {
 	unsigned int i;
+	unsigned int count;
 
 	i = macb->rx_tail;
 
 	macb_invalidate_ring_desc(macb, RX);
 	while (i > new_tail) {
-		macb->rx_ring[i].addr &= ~MACB_BIT(RX_USED);
+		if (macb->config->hw_dma_cap & HW_DMA_CAP_64B)
+			count = i * 2;
+		else
+			count = i;
+		macb->rx_ring[count].addr &= ~MACB_BIT(RX_USED);
 		i++;
 		if (i > MACB_RX_RING_SIZE)
 			i = 0;
 	}
 
 	while (i < new_tail) {
-		macb->rx_ring[i].addr &= ~MACB_BIT(RX_USED);
+		if (macb->config->hw_dma_cap & HW_DMA_CAP_64B)
+			count = i * 2;
+		else
+			count = i;
+		macb->rx_ring[count].addr &= ~MACB_BIT(RX_USED);
 		i++;
 	}
 
@@ -390,16 +431,25 @@ static int _macb_recv(struct macb_device *macb, uchar **packetp)
 	void *buffer;
 	int length;
 	u32 status;
+	u8 flag = false;
 
 	macb->wrapped = false;
 	for (;;) {
 		macb_invalidate_ring_desc(macb, RX);
 
+		if (macb->config->hw_dma_cap & HW_DMA_CAP_64B)
+			next_rx_tail = next_rx_tail * 2;
+
 		if (!(macb->rx_ring[next_rx_tail].addr & MACB_BIT(RX_USED)))
 			return -EAGAIN;
 
 		status = macb->rx_ring[next_rx_tail].ctrl;
 		if (status & MACB_BIT(RX_SOF)) {
+			if (macb->config->hw_dma_cap & HW_DMA_CAP_64B) {
+				next_rx_tail = next_rx_tail / 2;
+				flag = true;
+			}
+
 			if (next_rx_tail != macb->rx_tail)
 				reclaim_rx_buffers(macb, next_rx_tail);
 			macb->wrapped = false;
@@ -426,11 +476,22 @@ static int _macb_recv(struct macb_device *macb, uchar **packetp)
 				*packetp = buffer;
 			}
 
+			if (macb->config->hw_dma_cap & HW_DMA_CAP_64B) {
+				if (!flag)
+					next_rx_tail = next_rx_tail / 2;
+			}
+
 			if (++next_rx_tail >= MACB_RX_RING_SIZE)
 				next_rx_tail = 0;
 			macb->next_rx_tail = next_rx_tail;
 			return length;
 		} else {
+			if (macb->config->hw_dma_cap & HW_DMA_CAP_64B) {
+				if (!flag)
+					next_rx_tail = next_rx_tail / 2;
+				flag = false;
+			}
+
 			if (++next_rx_tail >= MACB_RX_RING_SIZE) {
 				macb->wrapped = true;
 				next_rx_tail = 0;
@@ -718,6 +779,7 @@ static int gmac_init_multi_queues(struct macb_device *macb)
 {
 	int i, num_queues = 1;
 	u32 queue_mask;
+	unsigned long paddr;
 
 	/* bit 0 is never set but queue 0 always exists */
 	queue_mask = gem_readl(macb, DCFG6) & 0xff;
@@ -731,10 +793,18 @@ static int gmac_init_multi_queues(struct macb_device *macb)
 	macb->dummy_desc->addr = 0;
 	flush_dcache_range(macb->dummy_desc_dma, macb->dummy_desc_dma +
 			ALIGN(MACB_TX_DUMMY_DMA_DESC_SIZE, PKTALIGN));
-
-	for (i = 1; i < num_queues; i++)
-		gem_writel_queue_TBQP(macb, macb->dummy_desc_dma, i - 1);
-
+	paddr = macb->dummy_desc_dma;
+
+	for (i = 1; i < num_queues; i++) {
+		gem_writel_queue_TBQP(macb, lower_32_bits(paddr), i - 1);
+		gem_writel_queue_RBQP(macb, lower_32_bits(paddr), i - 1);
+		if (macb->config->hw_dma_cap & HW_DMA_CAP_64B) {
+			gem_writel_queue_TBQPH(macb, upper_32_bits(paddr),
+					       i - 1);
+			gem_writel_queue_RBQPH(macb, upper_32_bits(paddr),
+					       i - 1);
+		}
+	}
 	return 0;
 }
 
@@ -760,6 +830,9 @@ static void gmac_configure_dma(struct macb_device *macb)
 		dmacfg &= ~GEM_BIT(ENDIA_DESC);
 
 	dmacfg &= ~GEM_BIT(ADDR64);
+	if (macb->config->hw_dma_cap & HW_DMA_CAP_64B)
+		dmacfg |= GEM_BIT(ADDR64);
+
 	gem_writel(macb, DMACFG, dmacfg);
 }
 
@@ -775,6 +848,7 @@ static int _macb_init(struct macb_device *macb, const char *name)
 	unsigned long paddr;
 	int ret;
 	int i;
+	int count;
 
 	/*
 	 * macb_halt should have been called at some point before now,
@@ -786,20 +860,28 @@ static int _macb_init(struct macb_device *macb, const char *name)
 	for (i = 0; i < MACB_RX_RING_SIZE; i++) {
 		if (i == (MACB_RX_RING_SIZE - 1))
 			paddr |= MACB_BIT(RX_WRAP);
-		macb->rx_ring[i].addr = paddr;
-		macb->rx_ring[i].ctrl = 0;
+		if (macb->config->hw_dma_cap & HW_DMA_CAP_64B)
+			count = i * 2;
+		else
+			count = i;
+		macb->rx_ring[count].ctrl = 0;
+		macb_set_addr(macb, &macb->rx_ring[count], paddr);
 		paddr += macb->rx_buffer_size;
 	}
 	macb_flush_ring_desc(macb, RX);
 	macb_flush_rx_buffer(macb);
 
 	for (i = 0; i < MACB_TX_RING_SIZE; i++) {
-		macb->tx_ring[i].addr = 0;
+		if (macb->config->hw_dma_cap & HW_DMA_CAP_64B)
+			count = i * 2;
+		else
+			count = i;
+		macb_set_addr(macb, &macb->tx_ring[count], 0);
 		if (i == (MACB_TX_RING_SIZE - 1))
-			macb->tx_ring[i].ctrl = MACB_BIT(TX_USED) |
+			macb->tx_ring[count].ctrl = MACB_BIT(TX_USED) |
 				MACB_BIT(TX_WRAP);
 		else
-			macb->tx_ring[i].ctrl = MACB_BIT(TX_USED);
+			macb->tx_ring[count].ctrl = MACB_BIT(TX_USED);
 	}
 	macb_flush_ring_desc(macb, TX);
 
@@ -812,8 +894,12 @@ static int _macb_init(struct macb_device *macb, const char *name)
 	gem_writel(macb, DMACFG, MACB_ZYNQ_GEM_DMACR_INIT);
 #endif
 
-	macb_writel(macb, RBQP, macb->rx_ring_dma);
-	macb_writel(macb, TBQP, macb->tx_ring_dma);
+	macb_writel(macb, RBQP, lower_32_bits(macb->rx_ring_dma));
+	macb_writel(macb, TBQP, lower_32_bits(macb->tx_ring_dma));
+	if (macb->config->hw_dma_cap & HW_DMA_CAP_64B) {
+		macb_writel(macb, RBQPH, upper_32_bits(macb->rx_ring_dma));
+		macb_writel(macb, TBQPH, upper_32_bits(macb->tx_ring_dma));
+	}
 
 	if (macb_is_gem(macb)) {
 		/* Initialize DMA properties */
@@ -1217,6 +1303,7 @@ static int macb_enable_clk(struct udevice *dev)
 
 static const struct macb_config default_gem_config = {
 	.dma_burst_length = 16,
+	.hw_dma_cap = HW_DMA_CAP_32B,
 	.clk_init = NULL,
 };
 
@@ -1227,8 +1314,8 @@ static int macb_eth_probe(struct udevice *dev)
 	const char *phy_mode;
 	int ret;
 
-	phy_mode = fdt_getprop(gd->fdt_blob, dev_of_offset(dev), "phy-mode",
-			       NULL);
+	phy_mode = dev_read_prop(dev, "phy-mode", NULL);
+
 	if (phy_mode)
 		macb->phy_interface = phy_get_interface_by_name(phy_mode);
 	if (macb->phy_interface == -1) {
@@ -1304,13 +1391,21 @@ static int macb_eth_ofdata_to_platdata(struct udevice *dev)
 	return macb_late_eth_ofdata_to_platdata(dev);
 }
 
+static const struct macb_config microchip_config = {
+	.dma_burst_length = 16,
+	.hw_dma_cap = HW_DMA_CAP_64B,
+	.clk_init = NULL,
+};
+
 static const struct macb_config sama5d4_config = {
 	.dma_burst_length = 4,
+	.hw_dma_cap = HW_DMA_CAP_32B,
 	.clk_init = NULL,
 };
 
 static const struct macb_config sifive_config = {
 	.dma_burst_length = 16,
+	.hw_dma_cap = HW_DMA_CAP_32B,
 	.clk_init = macb_sifive_clk_init,
 };
 
@@ -1324,6 +1419,8 @@ static const struct udevice_id macb_eth_ids[] = {
 	{ .compatible = "cdns,zynq-gem" },
 	{ .compatible = "sifive,fu540-c000-gem",
 	  .data = (ulong)&sifive_config },
+	{ .compatible = "microchip,mpfs-mss-gem",
+	  .data = (ulong)&microchip_config },
 	{ }
 };
 
drivers/net/macb.h +6 -0
index 9b16383eba..72b84ae96e 100644
@@ -768,5 +768,11 @@
 #define GEM_RX_CSUM_CHECKED_MASK		2
 #define gem_writel_queue_TBQP(port, value, queue_num)	\
 	writel((value), (port)->regs + GEM_TBQP(queue_num))
+#define gem_writel_queue_TBQPH(port, value, queue_num)	\
+	writel((value), (port)->regs + GEM_TBQPH(queue_num))
+#define gem_writel_queue_RBQP(port, value, queue_num)	\
+	writel((value), (port)->regs + GEM_RBQP(queue_num))
+#define gem_writel_queue_RBQPH(port, value, queue_num)	\
+	writel((value), (port)->regs + GEM_RBQPH(queue_num))
 
 #endif /* __DRIVERS_MACB_H__ */
Signature · 1 line
2.17.1
#4 lore raw

PATCH v6 2/7 net: macb: Add DMA 64-bit address support for macb

Quoted 9 lines · Padmarao Begari

Enable 32-bit or 64-bit DMA in the macb driver based on the macb hardware compatibility and it is configured with structure macb_config in the driver.

The Microchip PolarFire SoC Memory Protection Unit(MPU) gives the 64-bit DMA access with the GEM, the MPU transactions on the AXI bus is 64-bit not 32-bit So 64-bit DMA is enabled for the Microchip PolarFire SoC GEM.

Quoted 7 lines
---
 drivers/net/macb.c | 131 +++++++++++++++++++++++++++++++++++++++------
 drivers/net/macb.h |   6 +++
 2 files changed, 120 insertions(+), 17 deletions(-)
#5 lore raw

PATCH v6 3/7 net: macb: Add phy address to read it from device tree

In reply to Padmarao Begari

Read phy address from device tree and use it to find the phy device if not found then search in the range of 0 to 31.

---
 drivers/net/macb.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)
drivers/net/macb.c +13 -0
index 626ee49227..9b45187e5a 100644
@@ -531,6 +531,12 @@ static int macb_phy_find(struct macb_device *macb, const char *name)
 	int i;
 	u16 phy_id;
 
+	phy_id = macb_mdio_read(macb, macb->phy_addr, MII_PHYSID1);
+	if (phy_id != 0xffff) {
+		printf("%s: PHY present at %d\n", name, macb->phy_addr);
+		return 0;
+	}
+
 	/* Search for PHY... */
 	for (i = 0; i < 32; i++) {
 		macb->phy_addr = i;
@@ -1311,6 +1317,7 @@ static int macb_eth_probe(struct udevice *dev)
 {
 	struct eth_pdata *pdata = dev_get_platdata(dev);
 	struct macb_device *macb = dev_get_priv(dev);
+	struct ofnode_phandle_args phandle_args;
 	const char *phy_mode;
 	int ret;
 
@@ -1323,6 +1330,12 @@ static int macb_eth_probe(struct udevice *dev)
 		return -EINVAL;
 	}
 
+	/* Read phyaddr from DT */
+	if (!dev_read_phandle_with_args(dev, "phy-handle", NULL, 0, 0,
+					&phandle_args))
+		macb->phy_addr = ofnode_read_u32_default(phandle_args.node,
+							 "reg", -1);
+
 	macb->regs = (void *)pdata->iobase;
 
 	macb->is_big_endian = (cpu_to_be32(0x12345678) == 0x12345678);
Signature · 1 line
2.17.1
#6 lore raw

PATCH v6 4/7 clk: Add Microchip PolarFire SoC clock driver

In reply to Padmarao Begari

Add clock driver code for the Microchip PolarFire SoC. This driver handles reset and clock control of the Microchip PolarFire SoC device.

---
 drivers/clk/Kconfig                           |   1 +
 drivers/clk/Makefile                          |   1 +
 drivers/clk/microchip/Kconfig                 |   5 +
 drivers/clk/microchip/Makefile                |   1 +
 drivers/clk/microchip/mpfs_clk.c              | 127 +++++++++++++
 drivers/clk/microchip/mpfs_clk.h              |  19 ++
 drivers/clk/microchip/mpfs_clk_cfg.c          | 134 ++++++++++++++
 drivers/clk/microchip/mpfs_clk_periph.c       | 173 ++++++++++++++++++
 .../dt-bindings/clock/microchip-mpfs-clock.h  |  45 +++++
 9 files changed, 506 insertions(+)
 create mode 100644 drivers/clk/microchip/Kconfig
 create mode 100644 drivers/clk/microchip/Makefile
 create mode 100644 drivers/clk/microchip/mpfs_clk.c
 create mode 100644 drivers/clk/microchip/mpfs_clk.h
 create mode 100644 drivers/clk/microchip/mpfs_clk_cfg.c
 create mode 100644 drivers/clk/microchip/mpfs_clk_periph.c
 create mode 100644 include/dt-bindings/clock/microchip-mpfs-clock.h
drivers/clk/Kconfig +1 -0
index 4dfbad7986..1161fe7b5a 100644
@@ -173,6 +173,7 @@ source "drivers/clk/exynos/Kconfig"
 source "drivers/clk/imx/Kconfig"
 source "drivers/clk/kendryte/Kconfig"
 source "drivers/clk/meson/Kconfig"
+source "drivers/clk/microchip/Kconfig"
 source "drivers/clk/mvebu/Kconfig"
 source "drivers/clk/owl/Kconfig"
 source "drivers/clk/renesas/Kconfig"
drivers/clk/Makefile +1 -0
index d1e295ac7c..bd8a6eed88 100644
@@ -28,6 +28,7 @@ obj-$(CONFIG_CLK_EXYNOS) += exynos/
 obj-$(CONFIG_$(SPL_TPL_)CLK_INTEL) += intel/
 obj-$(CONFIG_CLK_HSDK) += clk-hsdk-cgu.o
 obj-$(CONFIG_CLK_K210) += kendryte/
+obj-$(CONFIG_CLK_MPFS) += microchip/
 obj-$(CONFIG_CLK_MPC83XX) += mpc83xx_clk.o
 obj-$(CONFIG_CLK_OCTEON) += clk_octeon.o
 obj-$(CONFIG_CLK_OWL) += owl/
drivers/clk/microchip/Kconfig new file +5 -0
new file mode 100644
index 0000000000..b70241559d
@@ -0,0 +1,5 @@
+config CLK_MPFS
+	bool "Clock support for Microchip PolarFire SoC"
+	depends on CLK && CLK_CCF
+	help
+	  This enables support clock driver for Microchip PolarFire SoC platform.
drivers/clk/microchip/Makefile new file +1 -0
new file mode 100644
index 0000000000..904b345d75
@@ -0,0 +1 @@
+obj-y += mpfs_clk.o mpfs_clk_cfg.o mpfs_clk_periph.o
drivers/clk/microchip/mpfs_clk.c new file +127 -0

127 lines not on this page · raw message

drivers/clk/microchip/mpfs_clk.h new file +19 -0
new file mode 100644
index 0000000000..35eecc02c0
@@ -0,0 +1,19 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * Copyright (C) 2020 Microchip Technology Inc.
+ * Padmarao Begari <[email protected]>
+ */
+#ifndef __MICROCHIP_MPFS_CLK_H
+#define __MICROCHIP_MPFS_CLK_H
+
+#include <linux/clk-provider.h>
+
+int mpfs_clk_register_cfgs(void __iomem *base, u32 clk_rate,
+			   const char *parent_name);
+int mpfs_clk_register_periphs(void __iomem *base, u32 clk_rate,
+			      const char *parent_name);
+int divider_get_val(unsigned long rate, unsigned long parent_rate,
+		    const struct clk_div_table *table,
+		    u8 width, unsigned long flags);
+
+#endif	/* __MICROCHIP_MPFS_CLK_H */
drivers/clk/microchip/mpfs_clk_cfg.c new file +134 -0

134 lines not on this page · raw message

drivers/clk/microchip/mpfs_clk_periph.c new file +173 -0

173 lines not on this page · raw message

include/dt-bindings/clock/microchip-mpfs-clock.h new file +45 -0

45 lines not on this page · raw message

Signature · 1 line
2.17.1
#7 lore raw

PATCH v6 4/7 clk: Add Microchip PolarFire SoC clock driver

Quoted 16 lines · Padmarao Begari

Add clock driver code for the Microchip PolarFire SoC. This driver handles reset and clock control of the Microchip PolarFire SoC device.

---
 drivers/clk/Kconfig                           |   1 +
 drivers/clk/Makefile                          |   1 +
 drivers/clk/microchip/Kconfig                 |   5 +
 drivers/clk/microchip/Makefile                |   1 +
 drivers/clk/microchip/mpfs_clk.c              | 127 +++++++++++++
 drivers/clk/microchip/mpfs_clk.h              |  19 ++
 drivers/clk/microchip/mpfs_clk_cfg.c          | 134 ++++++++++++++
 drivers/clk/microchip/mpfs_clk_periph.c       | 173 ++++++++++++++++++
 .../dt-bindings/clock/microchip-mpfs-clock.h  |  45 +++++
Quoted 9 lines
 9 files changed, 506 insertions(+)
 create mode 100644 drivers/clk/microchip/Kconfig
 create mode 100644 drivers/clk/microchip/Makefile
 create mode 100644 drivers/clk/microchip/mpfs_clk.c
 create mode 100644 drivers/clk/microchip/mpfs_clk.h
 create mode 100644 drivers/clk/microchip/mpfs_clk_cfg.c
 create mode 100644 drivers/clk/microchip/mpfs_clk_periph.c
 create mode 100644 include/dt-bindings/clock/microchip-mpfs-clock.h
#8 lore raw

PATCH v6 4/7 clk: Add Microchip PolarFire SoC clock driver

In reply to Padmarao Begari

Hi Padmarao,

Quoted 16 lines · Padmarao Begari

Add clock driver code for the Microchip PolarFire SoC. This driver handles reset and clock control of the Microchip PolarFire SoC device.

---
 drivers/clk/Kconfig                           |   1 +
 drivers/clk/Makefile                          |   1 +
 drivers/clk/microchip/Kconfig                 |   5 +
 drivers/clk/microchip/Makefile                |   1 +
 drivers/clk/microchip/mpfs_clk.c              | 127 +++++++++++++
 drivers/clk/microchip/mpfs_clk.h              |  19 ++
 drivers/clk/microchip/mpfs_clk_cfg.c          | 134 ++++++++++++++
 drivers/clk/microchip/mpfs_clk_periph.c       | 173 ++++++++++++++++++
 .../dt-bindings/clock/microchip-mpfs-clock.h  |  45 +++++
Quoted 8 lines
 9 files changed, 506 insertions(+)
 create mode 100644 drivers/clk/microchip/Kconfig
 create mode 100644 drivers/clk/microchip/Makefile
 create mode 100644 drivers/clk/microchip/mpfs_clk.c
 create mode 100644 drivers/clk/microchip/mpfs_clk.h
 create mode 100644 drivers/clk/microchip/mpfs_clk_cfg.c
 create mode 100644 drivers/clk/microchip/mpfs_clk_periph.c
 create mode 100644 include/dt-bindings/clock/microchip-mpfs-clock.h

Rather than allocating memory in your driver should use driver model's auto-alloc feature.

Quoted 189 lines
drivers/clk/Kconfig +1 -0
index 4dfbad7986..1161fe7b5a 100644
@@ -173,6 +173,7 @@ source "drivers/clk/exynos/Kconfig"
 source "drivers/clk/imx/Kconfig"
 source "drivers/clk/kendryte/Kconfig"
 source "drivers/clk/meson/Kconfig"
+source "drivers/clk/microchip/Kconfig"
 source "drivers/clk/mvebu/Kconfig"
 source "drivers/clk/owl/Kconfig"
 source "drivers/clk/renesas/Kconfig"
drivers/clk/Makefile +1 -0
index d1e295ac7c..bd8a6eed88 100644
@@ -28,6 +28,7 @@ obj-$(CONFIG_CLK_EXYNOS) += exynos/
 obj-$(CONFIG_$(SPL_TPL_)CLK_INTEL) += intel/
 obj-$(CONFIG_CLK_HSDK) += clk-hsdk-cgu.o
 obj-$(CONFIG_CLK_K210) += kendryte/
+obj-$(CONFIG_CLK_MPFS) += microchip/
 obj-$(CONFIG_CLK_MPC83XX) += mpc83xx_clk.o
 obj-$(CONFIG_CLK_OCTEON) += clk_octeon.o
 obj-$(CONFIG_CLK_OWL) += owl/
drivers/clk/microchip/Kconfig new file +5 -0
new file mode 100644
index 0000000000..b70241559d
@@ -0,0 +1,5 @@
+config CLK_MPFS
+       bool "Clock support for Microchip PolarFire SoC"
+       depends on CLK && CLK_CCF
+       help
+         This enables support clock driver for Microchip PolarFire SoC platform.
drivers/clk/microchip/Makefile new file +1 -0
new file mode 100644
index 0000000000..904b345d75
@@ -0,0 +1 @@
+obj-y += mpfs_clk.o mpfs_clk_cfg.o mpfs_clk_periph.o
drivers/clk/microchip/mpfs_clk.c new file +127 -0
new file mode 100644
index 0000000000..1b1b66ef64
@@ -0,0 +1,127 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (C) 2020 Microchip Technology Inc.
+ * Padmarao Begari <[email protected]>
+ */
+#include <common.h>
+#include <clk.h>
+#include <clk-uclass.h>
+#include <dm.h>
+#include <log.h>
+#include <dm/device.h>
+#include <dm/devres.h>
+#include <dm/uclass.h>
+#include <malloc.h>
+#include <linux/err.h>
+
+#include "mpfs_clk.h"
+
+/* All methods are delegated to CCF clocks */
+
+static ulong mpfs_clk_get_rate(struct clk *clk)
+{
+       struct clk *c;
+       int err = clk_get_by_id(clk->id, &c);
+
+       if (err)
+               return err;
+       return clk_get_rate(c);
+}
+
+static ulong mpfs_clk_set_rate(struct clk *clk, unsigned long rate)
+{
+       struct clk *c;
+       int err = clk_get_by_id(clk->id, &c);
+
+       if (err)
+               return err;
+       return clk_set_rate(c, rate);
+}
+
+static int mpfs_clk_set_parent(struct clk *clk, struct clk *parent)
+{
+       struct clk *c, *p;
+       int err = clk_get_by_id(clk->id, &c);
+
+       if (err)
+               return err;
+
+       err = clk_get_by_id(parent->id, &p);
+       if (err)
+               return err;
+
+       return clk_set_parent(c, p);
+}
+
+static int mpfs_clk_endisable(struct clk *clk, bool enable)
+{
+       struct clk *c;
+       int err = clk_get_by_id(clk->id, &c);
+
+       if (err)
+               return err;
+       return enable ? clk_enable(c) : clk_disable(c);
+}
+
+static int mpfs_clk_enable(struct clk *clk)
+{
+       return mpfs_clk_endisable(clk, true);
+}
+
+static int mpfs_clk_disable(struct clk *clk)
+{
+       return mpfs_clk_endisable(clk, false);
+}
+
+static int mpfs_clk_probe(struct udevice *dev)
+{
+       int ret;
+       void __iomem *base;
+       u32 clk_rate;
+       struct clk *clk;
+       const char *parent_clk_name;
+
+       base = dev_read_addr_ptr(dev);
+       if (!base)
+               return -ENODEV;
+
+       clk = kzalloc(sizeof(*clk), GFP_KERNEL);
+       if (!clk)
+               return -ENOMEM;
+
+       ret = clk_get_by_index(dev, 0, clk);
+       if (ret)
+               return ret;
+
+       dev_read_u32(clk->dev, "clock-frequency", &clk_rate);
+       parent_clk_name = clk->dev->name;
+
+       ret = mpfs_clk_register_cfgs(base, clk_rate, parent_clk_name);
+       if (ret)
+               return ret;
+
+       ret = mpfs_clk_register_periphs(base, clk_rate, "clk_ahb");
+
+       return ret;
+}
+
+static const struct clk_ops mpfs_clk_ops = {
+       .set_rate = mpfs_clk_set_rate,
+       .get_rate = mpfs_clk_get_rate,
+       .set_parent = mpfs_clk_set_parent,
+       .enable = mpfs_clk_enable,
+       .disable = mpfs_clk_disable,
+};
+
+static const struct udevice_id mpfs_of_match[] = {
+       { .compatible = "microchip,mpfs-clkcfg" },
+       { }
+};
+
+U_BOOT_DRIVER(mpfs_clk) = {
+       .name = "mpfs_clk",
+       .id = UCLASS_CLK,
+       .of_match = mpfs_of_match,
+       .ops = &mpfs_clk_ops,
+       .probe = mpfs_clk_probe,
+};
drivers/clk/microchip/mpfs_clk.h new file +7 -0
new file mode 100644
index 0000000000..35eecc02c0
@@ -0,0 +1,19 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * Copyright (C) 2020 Microchip Technology Inc.
+ * Padmarao Begari <[email protected]>
+ */
+#ifndef __MICROCHIP_MPFS_CLK_H
+#define __MICROCHIP_MPFS_CLK_H

drivers/clk/microchip/mpfs_clk.h line 17

Quoted 10 lines
drivers/clk/microchip/mpfs_clk.h new file +10 -0
+
+#include <linux/clk-provider.h>
+
+int mpfs_clk_register_cfgs(void __iomem *base, u32 clk_rate,
+                          const char *parent_name);
+int mpfs_clk_register_periphs(void __iomem *base, u32 clk_rate,
+                             const char *parent_name);
+int divider_get_val(unsigned long rate, unsigned long parent_rate,
+                   const struct clk_div_table *table,
+                   u8 width, unsigned long flags);

Comments?

Quoted 12 lines
drivers/clk/microchip/mpfs_clk.h new file +2 -0
+
+#endif /* __MICROCHIP_MPFS_CLK_H */
drivers/clk/microchip/mpfs_clk_cfg.c new file +4 -0
new file mode 100644
index 0000000000..44db14c664
@@ -0,0 +1,134 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (C) 2020 Microchip Technology Inc.
+ * Padmarao Begari <[email protected]>

drivers/clk/microchip/mpfs_clk_cfg.c line 14

Quoted 10 lines
drivers/clk/microchip/mpfs_clk_cfg.c new file +10 -0
+ */
+#include <common.h>
+#include <clk.h>
+#include <clk-uclass.h>
+#include <dm/device.h>
+#include <dm/devres.h>
+#include <dm/uclass.h>
+#include <asm/io.h>
+#include <linux/err.h>
+#include <dt-bindings/clock/microchip-mpfs-clock.h>

Please check header order.

https://www.denx.de/wiki/U-Boot/CodingStyle

Quoted 15 lines
drivers/clk/microchip/mpfs_clk_cfg.c new file +15 -0
+
+#include "mpfs_clk.h"
+
+#define MPFS_CFG_CLOCK "mpfs_cfg_clock"
+
+#define REG_CLOCK_CONFIG_CR 0x08
+
+static const struct clk_div_table mpfs_div_cpu_axi_table[] = {
+       { 0, 1 }, { 1, 2 }, { 2, 4 }, { 3, 8 },
+       { 0, 0 }
+};
+
+static const struct clk_div_table mpfs_div_ahb_table[] = {
+       { 1, 2 }, { 2, 4}, { 3, 8 },
+       { 0, 0 }

drivers/clk/microchip/mpfs_clk_cfg.c line 39

Quoted 10 lines
drivers/clk/microchip/mpfs_clk_cfg.c new file +10 -0
+};
+
+struct mpfs_cfg_clock {
+       unsigned int id;
+       const char *name;
+       u8 shift;
+       u8 width;
+       const struct clk_div_table *table;
+       unsigned long flags;
+};

comments

drivers/clk/microchip/mpfs_clk_cfg.c line 46

Quoted 7 lines
drivers/clk/microchip/mpfs_clk_cfg.c new file +7 -0
+
+struct mpfs_cfg_hw_clock {
+       struct mpfs_cfg_clock cfg;
+       void __iomem *sys_base;
+       u32 prate;
+       struct clk hw;
+};

comments!!!

Regards,
Simon

#9 lore raw

PATCH v6 4/7 clk: Add Microchip PolarFire SoC clock driver

Hi Simon,

Quoted 29 lines · Simon Glass

Hi Padmarao,

Quoted 16 lines · Padmarao Begari

Add clock driver code for the Microchip PolarFire SoC. This driver handles reset and clock control of the Microchip PolarFire SoC device.

---
 drivers/clk/Kconfig                           |   1 +
 drivers/clk/Makefile                          |   1 +
 drivers/clk/microchip/Kconfig                 |   5 +
 drivers/clk/microchip/Makefile                |   1 +
 drivers/clk/microchip/mpfs_clk.c              | 127 +++++++++++++
 drivers/clk/microchip/mpfs_clk.h              |  19 ++
 drivers/clk/microchip/mpfs_clk_cfg.c          | 134 ++++++++++++++
 drivers/clk/microchip/mpfs_clk_periph.c       | 173 ++++++++++++++++++
 .../dt-bindings/clock/microchip-mpfs-clock.h  |  45 +++++
Quoted 8 lines
 9 files changed, 506 insertions(+)
 create mode 100644 drivers/clk/microchip/Kconfig
 create mode 100644 drivers/clk/microchip/Makefile
 create mode 100644 drivers/clk/microchip/mpfs_clk.c
 create mode 100644 drivers/clk/microchip/mpfs_clk.h
 create mode 100644 drivers/clk/microchip/mpfs_clk_cfg.c
 create mode 100644 drivers/clk/microchip/mpfs_clk_periph.c
 create mode 100644 include/dt-bindings/clock/microchip-mpfs-clock.h
Quoted 4 lines

Rather than allocating memory in your driver should use driver model's auto-alloc feature.

ok

Quoted 198 lines

Review

Quoted 26 lines
drivers/clk/Kconfig +1 -0
index 4dfbad7986..1161fe7b5a 100644
@@ -173,6 +173,7 @@ source "drivers/clk/exynos/Kconfig"
 source "drivers/clk/imx/Kconfig"
 source "drivers/clk/kendryte/Kconfig"
 source "drivers/clk/meson/Kconfig"
+source "drivers/clk/microchip/Kconfig"
 source "drivers/clk/mvebu/Kconfig"
 source "drivers/clk/owl/Kconfig"
 source "drivers/clk/renesas/Kconfig"
drivers/clk/Makefile +1 -0
index d1e295ac7c..bd8a6eed88 100644
@@ -28,6 +28,7 @@ obj-$(CONFIG_CLK_EXYNOS) += exynos/
 obj-$(CONFIG_$(SPL_TPL_)CLK_INTEL) += intel/
 obj-$(CONFIG_CLK_HSDK) += clk-hsdk-cgu.o
 obj-$(CONFIG_CLK_K210) += kendryte/
+obj-$(CONFIG_CLK_MPFS) += microchip/
 obj-$(CONFIG_CLK_MPC83XX) += mpc83xx_clk.o
 obj-$(CONFIG_CLK_OCTEON) += clk_octeon.o
 obj-$(CONFIG_CLK_OWL) += owl/
(quoted diff) +0 -0

b/drivers/clk/microchip/Kconfig

drivers/clk/microchip/Kconfig line 5

Quoted 10 lines

new file mode 100644
index 0000000000..b70241559d

drivers/clk/microchip/Kconfig new file +5 -0
@@ -0,0 +1,5 @@
+config CLK_MPFS
+       bool "Clock support for Microchip PolarFire SoC"
+       depends on CLK && CLK_CCF
+       help
+         This enables support clock driver for Microchip PolarFire SoC

platform.

Review

Quoted 1 line
(quoted diff) +0 -0

b/drivers/clk/microchip/Makefile

Review

Quoted 7 lines

new file mode 100644
index 0000000000..904b345d75

drivers/clk/microchip/Makefile new file +1 -0
@@ -0,0 +1 @@
+obj-y += mpfs_clk.o mpfs_clk_cfg.o mpfs_clk_periph.o
(quoted diff) +0 -0

b/drivers/clk/microchip/mpfs_clk.c

Review

Quoted 133 lines

new file mode 100644
index 0000000000..1b1b66ef64

drivers/clk/microchip/mpfs_clk.c new file +127 -0
@@ -0,0 +1,127 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (C) 2020 Microchip Technology Inc.
+ * Padmarao Begari <[email protected]>
+ */
+#include <common.h>
+#include <clk.h>
+#include <clk-uclass.h>
+#include <dm.h>
+#include <log.h>
+#include <dm/device.h>
+#include <dm/devres.h>
+#include <dm/uclass.h>
+#include <malloc.h>
+#include <linux/err.h>
+
+#include "mpfs_clk.h"
+
+/* All methods are delegated to CCF clocks */
+
+static ulong mpfs_clk_get_rate(struct clk *clk)
+{
+       struct clk *c;
+       int err = clk_get_by_id(clk->id, &c);
+
+       if (err)
+               return err;
+       return clk_get_rate(c);
+}
+
+static ulong mpfs_clk_set_rate(struct clk *clk, unsigned long rate)
+{
+       struct clk *c;
+       int err = clk_get_by_id(clk->id, &c);
+
+       if (err)
+               return err;
+       return clk_set_rate(c, rate);
+}
+
+static int mpfs_clk_set_parent(struct clk *clk, struct clk *parent)
+{
+       struct clk *c, *p;
+       int err = clk_get_by_id(clk->id, &c);
+
+       if (err)
+               return err;
+
+       err = clk_get_by_id(parent->id, &p);
+       if (err)
+               return err;
+
+       return clk_set_parent(c, p);
+}
+
+static int mpfs_clk_endisable(struct clk *clk, bool enable)
+{
+       struct clk *c;
+       int err = clk_get_by_id(clk->id, &c);
+
+       if (err)
+               return err;
+       return enable ? clk_enable(c) : clk_disable(c);
+}
+
+static int mpfs_clk_enable(struct clk *clk)
+{
+       return mpfs_clk_endisable(clk, true);
+}
+
+static int mpfs_clk_disable(struct clk *clk)
+{
+       return mpfs_clk_endisable(clk, false);
+}
+
+static int mpfs_clk_probe(struct udevice *dev)
+{
+       int ret;
+       void __iomem *base;
+       u32 clk_rate;
+       struct clk *clk;
+       const char *parent_clk_name;
+
+       base = dev_read_addr_ptr(dev);
+       if (!base)
+               return -ENODEV;
+
+       clk = kzalloc(sizeof(*clk), GFP_KERNEL);
+       if (!clk)
+               return -ENOMEM;
+
+       ret = clk_get_by_index(dev, 0, clk);
+       if (ret)
+               return ret;
+
+       dev_read_u32(clk->dev, "clock-frequency", &clk_rate);
+       parent_clk_name = clk->dev->name;
+
+       ret = mpfs_clk_register_cfgs(base, clk_rate, parent_clk_name);
+       if (ret)
+               return ret;
+
+       ret = mpfs_clk_register_periphs(base, clk_rate, "clk_ahb");
+
+       return ret;
+}
+
+static const struct clk_ops mpfs_clk_ops = {
+       .set_rate = mpfs_clk_set_rate,
+       .get_rate = mpfs_clk_get_rate,
+       .set_parent = mpfs_clk_set_parent,
+       .enable = mpfs_clk_enable,
+       .disable = mpfs_clk_disable,
+};
+
+static const struct udevice_id mpfs_of_match[] = {
+       { .compatible = "microchip,mpfs-clkcfg" },
+       { }
+};
+
+U_BOOT_DRIVER(mpfs_clk) = {
+       .name = "mpfs_clk",
+       .id = UCLASS_CLK,
+       .of_match = mpfs_of_match,
+       .ops = &mpfs_clk_ops,
+       .probe = mpfs_clk_probe,
+};
(quoted diff) +0 -0

b/drivers/clk/microchip/mpfs_clk.h

Quoted 16 lines

new file mode 100644
index 0000000000..35eecc02c0

drivers/clk/microchip/mpfs_clk.h new file +11 -0
@@ -0,0 +1,19 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * Copyright (C) 2020 Microchip Technology Inc.
+ * Padmarao Begari <[email protected]>
+ */
+#ifndef __MICROCHIP_MPFS_CLK_H
+#define __MICROCHIP_MPFS_CLK_H
+
+#include <linux/clk-provider.h>
+
+int mpfs_clk_register_cfgs(void __iomem *base, u32 clk_rate,
Quoted 10 lines

drivers/clk/microchip/mpfs_clk.h line 17

Quoted 6 lines
drivers/clk/microchip/mpfs_clk.h new file +6 -0
+                          const char *parent_name);
+int mpfs_clk_register_periphs(void __iomem *base, u32 clk_rate,
+                             const char *parent_name);
+int divider_get_val(unsigned long rate, unsigned long parent_rate,
+                   const struct clk_div_table *table,
+                   u8 width, unsigned long flags);

Comments?

ok

Quoted 17 lines

Review

Quoted 3 lines
drivers/clk/microchip/mpfs_clk.h new file +2 -0
+
+#endif /* __MICROCHIP_MPFS_CLK_H */
(quoted diff) +0 -0

b/drivers/clk/microchip/mpfs_clk_cfg.c

Quoted 13 lines

new file mode 100644
index 0000000000..44db14c664

drivers/clk/microchip/mpfs_clk_cfg.c new file +8 -0
@@ -0,0 +1,134 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (C) 2020 Microchip Technology Inc.
+ * Padmarao Begari <[email protected]>
+ */
+#include <common.h>
+#include <clk.h>
+#include <clk-uclass.h>
Quoted 10 lines

drivers/clk/microchip/mpfs_clk_cfg.c line 14

Quoted 6 lines
drivers/clk/microchip/mpfs_clk_cfg.c new file +6 -0
+#include <dm/device.h>
+#include <dm/devres.h>
+#include <dm/uclass.h>
+#include <asm/io.h>
+#include <linux/err.h>
+#include <dt-bindings/clock/microchip-mpfs-clock.h>

Please check header order.

ok

https://www.denx.de/wiki/U-Boot/CodingStyle

Quoted 41 lines
Quoted 16 lines
drivers/clk/microchip/mpfs_clk_cfg.c new file +15 -0
+
+#include "mpfs_clk.h"
+
+#define MPFS_CFG_CLOCK "mpfs_cfg_clock"
+
+#define REG_CLOCK_CONFIG_CR 0x08
+
+static const struct clk_div_table mpfs_div_cpu_axi_table[] = {
+       { 0, 1 }, { 1, 2 }, { 2, 4 }, { 3, 8 },
+       { 0, 0 }
+};
+
+static const struct clk_div_table mpfs_div_ahb_table[] = {
+       { 1, 2 }, { 2, 4}, { 3, 8 },
+       { 0, 0 }

drivers/clk/microchip/mpfs_clk_cfg.c line 39

Quoted 10 lines
drivers/clk/microchip/mpfs_clk_cfg.c new file +10 -0
+};
+
+struct mpfs_cfg_clock {
+       unsigned int id;
+       const char *name;
+       u8 shift;
+       u8 width;
+       const struct clk_div_table *table;
+       unsigned long flags;
+};

comments

ok

drivers/clk/microchip/mpfs_clk_cfg.c line 46

Quoted 7 lines
drivers/clk/microchip/mpfs_clk_cfg.c new file +7 -0
+
+struct mpfs_cfg_hw_clock {
+       struct mpfs_cfg_clock cfg;
+       void __iomem *sys_base;
+       u32 prate;
+       struct clk hw;
+};

comments!!!

Quoted 1 line

ok

Regards
Padmarao

Quoted 4 lines

Regards,
Simon

#10 lore raw

PATCH v6 5/7 riscv: dts: Add device tree for Microchip Icicle Kit

In reply to Padmarao Begari

Add device tree for Microchip PolarFire SoC Icicle Kit.

---
 arch/riscv/dts/Makefile                       |   1 +
 .../dts/microchip-mpfs-icicle-kit-u-boot.dtsi |  14 +
 arch/riscv/dts/microchip-mpfs-icicle-kit.dts  | 421 ++++++++++++++++++
 3 files changed, 436 insertions(+)
 create mode 100644 arch/riscv/dts/microchip-mpfs-icicle-kit-u-boot.dtsi
 create mode 100644 arch/riscv/dts/microchip-mpfs-icicle-kit.dts
arch/riscv/dts/Makefile +1 -0
index 3a6f96c67d..01331b0aa1 100644
@@ -3,6 +3,7 @@
 dtb-$(CONFIG_TARGET_AX25_AE350) += ae350_32.dtb ae350_64.dtb
 dtb-$(CONFIG_TARGET_SIFIVE_FU540) += hifive-unleashed-a00.dtb
 dtb-$(CONFIG_TARGET_SIPEED_MAIX) += k210-maix-bit.dtb
+dtb-$(CONFIG_TARGET_MICROCHIP_ICICLE) += microchip-mpfs-icicle-kit.dtb
 
 targets += $(dtb-y)
 
arch/riscv/dts/microchip-mpfs-icicle-kit-u-boot.dtsi new file +14 -0
new file mode 100644
index 0000000000..f60283fb6b
@@ -0,0 +1,14 @@
+// SPDX-License-Identifier: (GPL-2.0 OR MIT)
+/*
+ * Copyright (C) 2020 Microchip Technology Inc.
+ * Padmarao Begari <[email protected]>
+ */
+
+/ {
+	aliases {
+		cpu1 = &cpu1;
+		cpu2 = &cpu2;
+		cpu3 = &cpu3;
+		cpu4 = &cpu4;
+	};
+};
arch/riscv/dts/microchip-mpfs-icicle-kit.dts new file +421 -0

421 lines not on this page · raw message

Signature · 1 line
2.17.1
#11 lore raw

PATCH v6 6/7 riscv: Add Microchip MPFS Icicle Kit support

In reply to Padmarao Begari

This patch adds Microchip MPFS Icicle Kit support. For now, only NS16550 Serial, Microchip clock, Cadence eMMC and MACB drivers are enabled. The Microchip MPFS Icicle defconfig by default builds U-Boot for S-Mode because U-Boot on Microchip PolarFire SoC will run in S-Mode as payload of HSS + OpenSBI.

---
 board/microchip/mpfs_icicle/Kconfig       | 23 ++++++
 board/microchip/mpfs_icicle/mpfs_icicle.c | 99 ++++++++++++++++++++++-
 configs/microchip_mpfs_icicle_defconfig   |  9 ++-
 include/configs/microchip_mpfs_icicle.h   | 60 +++++---------
 4 files changed, 146 insertions(+), 45 deletions(-)
board/microchip/mpfs_icicle/Kconfig +23 -0
index bf8e1a13ec..4678462378 100644
@@ -20,7 +20,30 @@ config BOARD_SPECIFIC_OPTIONS # dummy
 	def_bool y
 	select GENERIC_RISCV
 	select BOARD_EARLY_INIT_F
+	select BOARD_LATE_INIT
 	imply SMP
+	imply CLK_CCF
+	imply CLK_MPFS
 	imply SYS_NS16550
+	imply CMD_DHCP
+	imply CMD_EXT2
+	imply CMD_EXT4
+	imply CMD_FAT
+	imply CMD_FS_GENERIC
+	imply CMD_NET
+	imply CMD_PING
+	imply CMD_MMC
+	imply DOS_PARTITION
+	imply EFI_PARTITION
+	imply IP_DYN
+	imply ISO_PARTITION
+	imply MACB
+	imply MII
+	imply PHY_LIB
+	imply PHY_VITESSE
+	imply MMC
+	imply MMC_WRITE
+	imply MMC_SDHCI
+	imply MMC_SDHCI_CADENCE
 
 endif
board/microchip/mpfs_icicle/mpfs_icicle.c +96 -3

116 lines not on this page · raw message

configs/microchip_mpfs_icicle_defconfig +6 -3
index 2977966473..9abbc18a89 100644
@@ -1,12 +1,15 @@
 CONFIG_RISCV=y
 CONFIG_ENV_SIZE=0x2000
 CONFIG_TARGET_MICROCHIP_ICICLE=y
-CONFIG_NR_CPUS=5
 CONFIG_ARCH_RV64I=y
+CONFIG_RISCV_SMODE=y
+CONFIG_SBI_V01=y
+CONFIG_DEFAULT_DEVICE_TREE="microchip-mpfs-icicle-kit"
+CONFIG_DISTRO_DEFAULTS=y
+CONFIG_DISPLAY_CPUINFO=y
+CONFIG_DISPLAY_BOARDINFO=y
 CONFIG_FIT=y
-CONFIG_BOOTDELAY=3
 CONFIG_SYS_PROMPT="RISC-V # "
-CONFIG_OF_PRIOR_STAGE=y
 CONFIG_SYS_RELOC_GD_ENV_ADDR=y
 CONFIG_BOOTP_SEND_HOSTNAME=y
 CONFIG_DM_MTD=y
include/configs/microchip_mpfs_icicle.h +21 -39

74 lines not on this page · raw message

Signature · 1 line
2.17.1
#12 lore raw

PATCH v6 6/7 riscv: Add Microchip MPFS Icicle Kit support

Quoted 160 lines · Padmarao Begari

This patch adds Microchip MPFS Icicle Kit support. For now, only NS16550 Serial, Microchip clock, Cadence eMMC and MACB drivers are enabled. The Microchip MPFS Icicle defconfig by default builds U-Boot for S-Mode because U-Boot on Microchip PolarFire SoC will run in S-Mode as payload of HSS + OpenSBI.

---
 board/microchip/mpfs_icicle/Kconfig       | 23 ++++++
 board/microchip/mpfs_icicle/mpfs_icicle.c | 99 ++++++++++++++++++++++-
 configs/microchip_mpfs_icicle_defconfig   |  9 ++-
 include/configs/microchip_mpfs_icicle.h   | 60 +++++---------
 4 files changed, 146 insertions(+), 45 deletions(-)
board/microchip/mpfs_icicle/Kconfig +23 -0
index bf8e1a13ec..4678462378 100644
@@ -20,7 +20,30 @@ config BOARD_SPECIFIC_OPTIONS # dummy
        def_bool y
        select GENERIC_RISCV
        select BOARD_EARLY_INIT_F
+       select BOARD_LATE_INIT
        imply SMP
+       imply CLK_CCF
+       imply CLK_MPFS
        imply SYS_NS16550
+       imply CMD_DHCP
+       imply CMD_EXT2
+       imply CMD_EXT4
+       imply CMD_FAT
+       imply CMD_FS_GENERIC
+       imply CMD_NET
+       imply CMD_PING
+       imply CMD_MMC
+       imply DOS_PARTITION
+       imply EFI_PARTITION
+       imply IP_DYN
+       imply ISO_PARTITION
+       imply MACB
+       imply MII
+       imply PHY_LIB
+       imply PHY_VITESSE
+       imply MMC
+       imply MMC_WRITE
+       imply MMC_SDHCI
+       imply MMC_SDHCI_CADENCE
 
 endif
board/microchip/mpfs_icicle/mpfs_icicle.c +83 -3
index 8381361ec3..0e34409067 100644
@@ -6,10 +6,49 @@
 
 #include <common.h>
 #include <dm.h>
+#include <env.h>
 #include <init.h>
 #include <asm/io.h>
 
-#define MPFS_SYSREG_SOFT_RESET ((unsigned int *)0x20002088)
+DECLARE_GLOBAL_DATA_PTR;
+
+#define MPFS_SYSREG_SOFT_RESET         ((unsigned int *)0x20002088)
+#define MPFS_SYS_SERVICE_CR            ((unsigned int *)0x37020050)
+#define MPFS_SYS_SERVICE_SR            ((unsigned int *)0x37020054)
+#define MPFS_SYS_SERVICE_MAILBOX       ((unsigned char *)0x37020800)
+
+#define PERIPH_RESET_VALUE             0x1e8u
+#define SERVICE_CR_REQ                 0x1u
+#define SERVICE_SR_BUSY                        0x2u
+
+static void read_device_serial_number(u8 *response, u8 response_size)
+{
+       u8 idx;
+       u8 *response_buf;
+       unsigned int val;
+
+       response_buf = (u8 *)response;
+
+       writel(SERVICE_CR_REQ, MPFS_SYS_SERVICE_CR);
+       /*
+        * REQ bit will remain set till the system controller starts
+        * processing.
+        */
+       do {
+               val = readl(MPFS_SYS_SERVICE_CR);
+       } while (SERVICE_CR_REQ == (val & SERVICE_CR_REQ));
+
+       /*
+        * Once system controller starts processing the busy bit will
+        * go high and service is completed when busy bit is gone low
+        */
+       do {
+               val = readl(MPFS_SYS_SERVICE_SR);
+       } while (SERVICE_SR_BUSY == (val & SERVICE_SR_BUSY));
+
+       for (idx = 0; idx < response_size; idx++)
+               response_buf[idx] = readb(MPFS_SYS_SERVICE_MAILBOX + idx);
+}
 
 int board_init(void)
 {
@@ -22,10 +61,64 @@ int board_early_init_f(void)
 {
        unsigned int val;
 
-       /* Reset uart peripheral */
+       /* Reset uart, mmc peripheral */
        val = readl(MPFS_SYSREG_SOFT_RESET);
-       val = (val & ~(1u << 5u));
+       val = (val & ~(PERIPH_RESET_VALUE));
        writel(val, MPFS_SYSREG_SOFT_RESET);
 
        return 0;
 }
+
+int board_late_init(void)
+{
+       u32 ret;
+       u32 node;
+       u8 idx;
+       u8 device_serial_number[16] = { 0 };
+       unsigned char mac_addr[6];
+       char icicle_mac_addr[20];
+       void *blob = (void *)gd->fdt_blob;
+
+       node = fdt_path_offset(blob, "ethernet0");
+       if (node < 0) {
+               printf("No ethernet0 path offset\n");
+               return -ENODEV;
+       }
+
+       ret = fdtdec_get_byte_array(blob, node, "local-mac-address", mac_addr, 6);
+       if (ret) {
+               printf("No local-mac-address property\n");
+               return -EINVAL;
+       }
+
+       read_device_serial_number(device_serial_number, 16);
+
+       /* Update MAC address with device serial number */
+       mac_addr[0] = 0x00;
+       mac_addr[1] = 0x04;
+       mac_addr[2] = 0xA3;
+       mac_addr[3] = device_serial_number[2];
+       mac_addr[4] = device_serial_number[1];
+       mac_addr[5] = device_serial_number[0];
+
+       ret = fdt_setprop(blob, node, "local-mac-address", mac_addr, 6);
+       if (ret) {
+               printf("Error setting local-mac-address property\n");
+               return -ENODEV;
+       }
+
+       icicle_mac_addr[0] = '[';
+

board/microchip/mpfs_icicle/mpfs_icicle.c int board_early_init_f(void) · line 121

Quoted 10 lines
board/microchip/mpfs_icicle/mpfs_icicle.c +10 -0
+       sprintf(&icicle_mac_addr[1], "%pM", mac_addr);
+
+       icicle_mac_addr[18] = ']';
+       icicle_mac_addr[19] = '\0';
+
+       for (idx = 0; idx < 20; idx++) {
+               if (icicle_mac_addr[idx] == ':')
+                       icicle_mac_addr[idx] = ' ';
+       }
+       env_set("icicle_mac_addr", icicle_mac_addr);

I am still not convinced this "ad-hoc" environment variable is needed. What happens if both 2 GEMs are enabled in the future?

board/microchip/mpfs_icicle/mpfs_icicle.c int board_early_init_f(void) · line 124

Quoted 3 lines
board/microchip/mpfs_icicle/mpfs_icicle.c +3 -0
+
+       return 0;
+}

[snip]

Anyway, we can address that if something changes in the future.

Regards,
Bin

#13 lore raw

PATCH v6 7/7 doc: board: Add Microchip MPFS Icicle Kit doc

In reply to Padmarao Begari

This doc describes the procedure to build, flash and boot Linux using U-boot on Microchip MPFS Icicle Kit.

---
 doc/board/index.rst                 |   1 +
 doc/board/microchip/index.rst       |   9 +
 doc/board/microchip/mpfs_icicle.rst | 816 ++++++++++++++++++++++++++++
 3 files changed, 826 insertions(+)
 create mode 100644 doc/board/microchip/index.rst
 create mode 100644 doc/board/microchip/mpfs_icicle.rst
doc/board/index.rst +1 -0
index 915f1be8a5..08c167b6b5 100644
@@ -17,6 +17,7 @@ Board-specific doc
    google/index
    intel/index
    kontron/index
+   microchip/index
    renesas/index
    rockchip/index
    sifive/index
doc/board/microchip/index.rst new file +9 -0
new file mode 100644
index 0000000000..affc5a9e01
@@ -0,0 +1,9 @@
+.. SPDX-License-Identifier: GPL-2.0+
+
+Microchip
+=========
+
+.. toctree::
+   :maxdepth: 2
+
+   mpfs_icicle
doc/board/microchip/mpfs_icicle.rst new file +816 -0

816 lines not on this page · raw message

Signature · 1 line
2.17.1
#14 lore raw

PATCH v6 7/7 doc: board: Add Microchip MPFS Icicle Kit doc

Quoted 6 lines · Padmarao Begari

This doc describes the procedure to build, flash and boot Linux using U-boot on Microchip MPFS Icicle Kit.

Quoted 8 lines
---
 doc/board/index.rst                 |   1 +
 doc/board/microchip/index.rst       |   9 +
 doc/board/microchip/mpfs_icicle.rst | 816 ++++++++++++++++++++++++++++
 3 files changed, 826 insertions(+)
 create mode 100644 doc/board/microchip/index.rst
 create mode 100644 doc/board/microchip/mpfs_icicle.rst