CVS commit: [netbsd-9] src/sys/arch/arm/sunxi

2019-11-25 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Mon Nov 25 16:20:41 UTC 2019

Modified Files:
src/sys/arch/arm/sunxi [netbsd-9]: sunxi_drm.c

Log Message:
Pull up following revision(s) (requested by jmcneill in ticket #472):

sys/arch/arm/sunxi/sunxi_drm.c: revision 1.9

Reclaim bootloader FB memory for CMA pool.


To generate a diff of this commit:
cvs rdiff -u -r1.7.6.1 -r1.7.6.2 src/sys/arch/arm/sunxi/sunxi_drm.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: [netbsd-9] src/sys/arch/arm/sunxi

2019-11-25 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Mon Nov 25 16:20:41 UTC 2019

Modified Files:
src/sys/arch/arm/sunxi [netbsd-9]: sunxi_drm.c

Log Message:
Pull up following revision(s) (requested by jmcneill in ticket #472):

sys/arch/arm/sunxi/sunxi_drm.c: revision 1.9

Reclaim bootloader FB memory for CMA pool.


To generate a diff of this commit:
cvs rdiff -u -r1.7.6.1 -r1.7.6.2 src/sys/arch/arm/sunxi/sunxi_drm.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/arm/sunxi/sunxi_drm.c
diff -u src/sys/arch/arm/sunxi/sunxi_drm.c:1.7.6.1 src/sys/arch/arm/sunxi/sunxi_drm.c:1.7.6.2
--- src/sys/arch/arm/sunxi/sunxi_drm.c:1.7.6.1	Wed Nov  6 09:48:31 2019
+++ src/sys/arch/arm/sunxi/sunxi_drm.c	Mon Nov 25 16:20:41 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: sunxi_drm.c,v 1.7.6.1 2019/11/06 09:48:31 martin Exp $ */
+/* $NetBSD: sunxi_drm.c,v 1.7.6.2 2019/11/25 16:20:41 martin Exp $ */
 
 /*-
  * Copyright (c) 2019 Jared D. McNeill 
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sunxi_drm.c,v 1.7.6.1 2019/11/06 09:48:31 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sunxi_drm.c,v 1.7.6.2 2019/11/25 16:20:41 martin Exp $");
 
 #include 
 #include 
@@ -296,6 +296,27 @@ static struct drm_mode_config_funcs sunx
 };
 
 static int
+sunxi_drm_simplefb_lookup(bus_addr_t *paddr, bus_size_t *psize)
+{
+	static const char * compat[] = { "simple-framebuffer", NULL };
+	int chosen, child;
+
+	chosen = OF_finddevice("/chosen");
+	if (chosen == -1)
+		return ENOENT;
+
+	for (child = OF_child(chosen); child; child = OF_peer(child)) {
+		if (!fdtbus_status_okay(child))
+			continue;
+		if (!of_match_compatible(child, compat))
+			continue;
+		return fdtbus_get_reg(child, 0, paddr, psize);
+	}
+
+	return ENOENT;
+}
+
+static int
 sunxi_drm_fb_probe(struct drm_fb_helper *helper, struct drm_fb_helper_surface_size *sizes)
 {
 	struct sunxi_drm_softc * const sc = sunxi_drm_private(helper->dev);
@@ -303,6 +324,8 @@ sunxi_drm_fb_probe(struct drm_fb_helper 
 	struct sunxi_drm_framebuffer *sfb = to_sunxi_drm_framebuffer(helper->fb);
 	struct drm_framebuffer *fb = helper->fb;
 	struct sunxi_drmfb_attach_args sfa;
+	bus_addr_t sfb_addr;
+	bus_size_t sfb_size;
 	size_t cma_size;
 	int error;
 
@@ -312,14 +335,31 @@ sunxi_drm_fb_probe(struct drm_fb_helper 
 
 	const size_t size = roundup(height * pitch, PAGE_SIZE);
 
-	/* Reserve enough memory for the FB console plus a 4K plane, rounded to 1MB */
-	cma_size = size;
-	cma_size += (SUNXI_DRM_MAX_WIDTH * SUNXI_DRM_MAX_HEIGHT * 4);
+	if (sunxi_drm_simplefb_lookup(_addr, _size) != 0)
+		sfb_size = 0;
+
+	/* Reserve enough memory for a 4K plane, rounded to 1MB */
+	cma_size = (SUNXI_DRM_MAX_WIDTH * SUNXI_DRM_MAX_HEIGHT * 4);
+	if (sfb_size == 0) {
+		/* Add memory for FB console if we cannot reclaim bootloader memory */
+		cma_size += size;
+	}
 	cma_size = roundup(cma_size, 1024 * 1024);
 	sc->sc_ddev->cma_pool = sunxi_drm_alloc_cma_pool(sc->sc_ddev, cma_size);
-	if (sc->sc_ddev->cma_pool != NULL)
-		aprint_normal_dev(sc->sc_dev, "reserved %u MB DRAM for CMA\n",
-		(u_int)(cma_size / (1024 * 1024)));
+	if (sc->sc_ddev->cma_pool != NULL) {
+		if (sfb_size != 0) {
+			error = vmem_add(sc->sc_ddev->cma_pool, sfb_addr,
+			sfb_size, VM_SLEEP);
+			if (error != 0)
+sfb_size = 0;
+		}
+		aprint_normal_dev(sc->sc_dev, "reserved %u MB DRAM for CMA",
+		(u_int)((cma_size + sfb_size) / (1024 * 1024)));
+		if (sfb_size != 0)
+			aprint_normal(" (%u MB reclaimed from bootloader)",
+			(u_int)(sfb_size / (1024 * 1024)));
+		aprint_normal("\n");
+	}
 
 	sfb->obj = drm_gem_cma_create(ddev, size);
 	if (sfb->obj == NULL) {



CVS commit: [netbsd-9] src/sys/arch/arm/sunxi

2019-11-01 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Fri Nov  1 18:14:45 UTC 2019

Modified Files:
src/sys/arch/arm/sunxi [netbsd-9]: sunxi_gmac.c

Log Message:
Pull up following revision(s) (requested by bad in ticket #389):

sys/arch/arm/sunxi/sunxi_gmac.c: revision 1.7

fetch PHY id from FDT.  same as sunxi_emac.c.

prevents PHY 0 of RTL8211E from wrongly attaching on e.g. Bananpi M1.
requested by jmcneill@, patch by martin@.

XXX pullup-9


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.6.2.1 src/sys/arch/arm/sunxi/sunxi_gmac.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/arm/sunxi/sunxi_gmac.c
diff -u src/sys/arch/arm/sunxi/sunxi_gmac.c:1.6 src/sys/arch/arm/sunxi/sunxi_gmac.c:1.6.2.1
--- src/sys/arch/arm/sunxi/sunxi_gmac.c:1.6	Sun Jul 21 08:24:32 2019
+++ src/sys/arch/arm/sunxi/sunxi_gmac.c	Fri Nov  1 18:14:45 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: sunxi_gmac.c,v 1.6 2019/07/21 08:24:32 mrg Exp $ */
+/* $NetBSD: sunxi_gmac.c,v 1.6.2.1 2019/11/01 18:14:45 martin Exp $ */
 
 /*-
  * Copyright (c) 2017 Jared McNeill 
@@ -28,7 +28,7 @@
 
 #include 
 
-__KERNEL_RCSID(0, "$NetBSD: sunxi_gmac.c,v 1.6 2019/07/21 08:24:32 mrg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sunxi_gmac.c,v 1.6.2.1 2019/11/01 18:14:45 martin Exp $");
 
 #include 
 #include 
@@ -94,6 +94,24 @@ sunxi_gmac_intr(void *arg)
 }
 
 static int
+sunxi_gmac_get_phyid(int phandle)
+{
+	bus_addr_t addr;
+	int phy_phandle;
+
+	phy_phandle = fdtbus_get_phandle(phandle, "phy");
+	if (phy_phandle == -1)
+		phy_phandle = fdtbus_get_phandle(phandle, "phy-handle");
+	if (phy_phandle == -1)
+		return MII_PHY_ANY;
+
+	if (fdtbus_get_reg(phy_phandle, 0, , NULL) != 0)
+		return MII_PHY_ANY;
+
+	return (int)addr;
+}
+
+static int
 sunxi_gmac_match(device_t parent, cfdata_t cf, void *aux)
 {
 	struct fdt_attach_args * const faa = aux;
@@ -192,7 +210,8 @@ sunxi_gmac_attach(device_t parent, devic
 	if (sunxi_gmac_reset(phandle) != 0)
 		aprint_error_dev(self, "PHY reset failed\n");
 
-	dwc_gmac_attach(sc, MII_PHY_ANY, GMAC_MII_CLK_150_250M_DIV102);
+	dwc_gmac_attach(sc, sunxi_gmac_get_phyid(phandle),
+	GMAC_MII_CLK_150_250M_DIV102);
 }
 
 CFATTACH_DECL_NEW(sunxi_gmac, sizeof(struct dwc_gmac_softc),



CVS commit: [netbsd-9] src/sys/arch/arm/sunxi

2019-11-01 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Fri Nov  1 18:14:45 UTC 2019

Modified Files:
src/sys/arch/arm/sunxi [netbsd-9]: sunxi_gmac.c

Log Message:
Pull up following revision(s) (requested by bad in ticket #389):

sys/arch/arm/sunxi/sunxi_gmac.c: revision 1.7

fetch PHY id from FDT.  same as sunxi_emac.c.

prevents PHY 0 of RTL8211E from wrongly attaching on e.g. Bananpi M1.
requested by jmcneill@, patch by martin@.

XXX pullup-9


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.6.2.1 src/sys/arch/arm/sunxi/sunxi_gmac.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: [netbsd-9] src/sys/arch/arm/sunxi

2019-09-06 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Fri Sep  6 19:54:23 UTC 2019

Modified Files:
src/sys/arch/arm/sunxi [netbsd-9]: sunxi_mmc.c

Log Message:
Pull up following revision(s) (requested by bouyer in ticket #187):

sys/arch/arm/sunxi/sunxi_mmc.c: revision 1.37

The mmc module clock needs to be doubled only for 8bits DDR mode on old
timing hardware.

This makes the lime2-eemc works in 4bits DDR52 mode.


To generate a diff of this commit:
cvs rdiff -u -r1.33 -r1.33.2.1 src/sys/arch/arm/sunxi/sunxi_mmc.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: [netbsd-9] src/sys/arch/arm/sunxi

2019-09-06 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Fri Sep  6 19:54:23 UTC 2019

Modified Files:
src/sys/arch/arm/sunxi [netbsd-9]: sunxi_mmc.c

Log Message:
Pull up following revision(s) (requested by bouyer in ticket #187):

sys/arch/arm/sunxi/sunxi_mmc.c: revision 1.37

The mmc module clock needs to be doubled only for 8bits DDR mode on old
timing hardware.

This makes the lime2-eemc works in 4bits DDR52 mode.


To generate a diff of this commit:
cvs rdiff -u -r1.33 -r1.33.2.1 src/sys/arch/arm/sunxi/sunxi_mmc.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/arm/sunxi/sunxi_mmc.c
diff -u src/sys/arch/arm/sunxi/sunxi_mmc.c:1.33 src/sys/arch/arm/sunxi/sunxi_mmc.c:1.33.2.1
--- src/sys/arch/arm/sunxi/sunxi_mmc.c:1.33	Mon May 27 23:27:01 2019
+++ src/sys/arch/arm/sunxi/sunxi_mmc.c	Fri Sep  6 19:54:23 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: sunxi_mmc.c,v 1.33 2019/05/27 23:27:01 jmcneill Exp $ */
+/* $NetBSD: sunxi_mmc.c,v 1.33.2.1 2019/09/06 19:54:23 martin Exp $ */
 
 /*-
  * Copyright (c) 2014-2017 Jared McNeill 
@@ -29,7 +29,7 @@
 #include "opt_sunximmc.h"
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sunxi_mmc.c,v 1.33 2019/05/27 23:27:01 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sunxi_mmc.c,v 1.33.2.1 2019/09/06 19:54:23 martin Exp $");
 
 #include 
 #include 
@@ -480,7 +480,7 @@ free:
 }
 
 static int
-sunxi_mmc_set_clock(struct sunxi_mmc_softc *sc, u_int freq, bool ddr)
+sunxi_mmc_set_clock(struct sunxi_mmc_softc *sc, u_int freq, bool ddr, bool dbl)
 {
 	const struct sunxi_mmc_delay *delays;
 	int error, timing = SUNXI_MMC_TIMING_400K;
@@ -506,7 +506,7 @@ sunxi_mmc_set_clock(struct sunxi_mmc_sof
 			return EINVAL;
 	}
 
-	error = clk_set_rate(sc->sc_clk_mmc, (freq * 1000) << ddr);
+	error = clk_set_rate(sc->sc_clk_mmc, (freq * 1000) << dbl);
 	if (error != 0)
 		return error;
 
@@ -554,7 +554,7 @@ sunxi_mmc_attach_i(device_t self)
 
 	sunxi_mmc_host_reset(sc);
 	sunxi_mmc_bus_width(sc, 1);
-	sunxi_mmc_set_clock(sc, 400, false);
+	sunxi_mmc_set_clock(sc, 400, false, false);
 
 	if (sc->sc_pwrseq)
 		fdtbus_mmc_pwrseq_post_power_on(sc->sc_pwrseq);
@@ -815,6 +815,7 @@ sunxi_mmc_bus_clock(sdmmc_chipset_handle
 	struct sunxi_mmc_softc *sc = sch;
 	uint32_t clkcr, gctrl, ntsr;
 	const u_int flags = sc->sc_config->flags;
+	bool dbl = 0;
 
 	clkcr = MMC_READ(sc, SUNXI_MMC_CLKCR);
 	if (clkcr & SUNXI_MMC_CLKCR_CARDCLKON) {
@@ -832,9 +833,15 @@ sunxi_mmc_bus_clock(sdmmc_chipset_handle
 	}
 
 	if (freq) {
+		/* For 8bits ddr in old timing modes, and all ddr in new
+		 * timing modes, the module clock has to be 2x the card clock.
+		 */
+		if (ddr && ((flags & SUNXI_MMC_FLAG_NEW_TIMINGS) ||
+		sc->sc_mmc_width == 8))
+			dbl = 1;
 
 		clkcr &= ~SUNXI_MMC_CLKCR_DIV;
-		clkcr |= __SHIFTIN(ddr, SUNXI_MMC_CLKCR_DIV);
+		clkcr |= __SHIFTIN(dbl, SUNXI_MMC_CLKCR_DIV);
 		MMC_WRITE(sc, SUNXI_MMC_CLKCR, clkcr);
 
 		if (flags & SUNXI_MMC_FLAG_NEW_TIMINGS) {
@@ -856,7 +863,7 @@ sunxi_mmc_bus_clock(sdmmc_chipset_handle
 			gctrl &= ~SUNXI_MMC_GCTRL_DDR_MODE;
 		MMC_WRITE(sc, SUNXI_MMC_GCTRL, gctrl);
 
-		if (sunxi_mmc_set_clock(sc, freq, ddr) != 0)
+		if (sunxi_mmc_set_clock(sc, freq, ddr, dbl) != 0)
 			return 1;
 
 		clkcr |= SUNXI_MMC_CLKCR_CARDCLKON;



CVS commit: [netbsd-9] src/sys/arch/arm/sunxi

2019-09-06 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Fri Sep  6 19:48:09 UTC 2019

Modified Files:
src/sys/arch/arm/sunxi [netbsd-9]: sunxi_rtc.c

Log Message:
Pull up following revision(s) (requested by thorpej in ticket #185):

sys/arch/arm/sunxi/sunxi_rtc.c: revision 1.5

Catch up with RTC-related DTS changes for the H3, H5, and A64 SoCs.
mujo AT SDF.ORG, and verified on Pinebook by Jun Ebihara.
XXX pullup-9


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.4.4.1 src/sys/arch/arm/sunxi/sunxi_rtc.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: [netbsd-9] src/sys/arch/arm/sunxi

2019-09-06 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Fri Sep  6 19:48:09 UTC 2019

Modified Files:
src/sys/arch/arm/sunxi [netbsd-9]: sunxi_rtc.c

Log Message:
Pull up following revision(s) (requested by thorpej in ticket #185):

sys/arch/arm/sunxi/sunxi_rtc.c: revision 1.5

Catch up with RTC-related DTS changes for the H3, H5, and A64 SoCs.
mujo AT SDF.ORG, and verified on Pinebook by Jun Ebihara.
XXX pullup-9


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.4.4.1 src/sys/arch/arm/sunxi/sunxi_rtc.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/arm/sunxi/sunxi_rtc.c
diff -u src/sys/arch/arm/sunxi/sunxi_rtc.c:1.4 src/sys/arch/arm/sunxi/sunxi_rtc.c:1.4.4.1
--- src/sys/arch/arm/sunxi/sunxi_rtc.c:1.4	Mon Jul 16 23:11:47 2018
+++ src/sys/arch/arm/sunxi/sunxi_rtc.c	Fri Sep  6 19:48:09 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: sunxi_rtc.c,v 1.4 2018/07/16 23:11:47 christos Exp $ */
+/* $NetBSD: sunxi_rtc.c,v 1.4.4.1 2019/09/06 19:48:09 martin Exp $ */
 
 /*-
  * Copyright (c) 2014-2017 Jared McNeill 
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sunxi_rtc.c,v 1.4 2018/07/16 23:11:47 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sunxi_rtc.c,v 1.4.4.1 2019/09/06 19:48:09 martin Exp $");
 
 #include 
 #include 
@@ -130,6 +130,8 @@ static const struct of_compat_data compa
 	{ "allwinner,sun4i-a10-rtc",		(uintptr_t)_rtc_config },
 	{ "allwinner,sun6i-a31-rtc",		(uintptr_t)_rtc_config },
 	{ "allwinner,sun7i-a20-rtc",		(uintptr_t)_rtc_config },
+	{ "allwinner,sun8i-h3-rtc",		(uintptr_t)_rtc_config },
+	{ "allwinner,sun50i-h5-rtc",		(uintptr_t)_rtc_config },
 	{ NULL }
 };