From nobody Mon Aug 15 12:04:23 2022 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4M5tHW2f6bz4YjqB; Mon, 15 Aug 2022 12:04:23 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4M5tHW2470z3Mm6; Mon, 15 Aug 2022 12:04:23 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1660565063; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=m0ipc38ebchy2E0Rc62dK3Vdhh+8gTGG5A1WHwghYb8=; b=r69H8Ywsmd08kfmmXEJXEmTz4AU8E+kWcms5wEuyt7ZBj+NaR1evpq6tlFChlPo7i5x/L+ zlelE5Jp3MSFg9BJXa5LkiP092pSllnx/RPBRHdvdQyo5ZPu2A81pzcMYmR496LXX6+jUp bD7ysFwzUf7jI0J/m9Z+ob58KlCHA5SZ052+waFgbwmxl2e1k1L7VX5EAxTIm1Qs5yr0uL /0IK6L6lvTbsHJh8KOYhjKAo0JQI/TzJGKNLMfhs8nw7Aa/+GOwhag4UXUuDFGX43YL/z1 1vFaST/l6NmuGqpDrNIGZnlxsh38CJRda/jbO2vqaaXDwCgEBmsSCDFLUQuuhA== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4M5tHW16GNzTfH; Mon, 15 Aug 2022 12:04:23 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 27FC4Nqk052454; Mon, 15 Aug 2022 12:04:23 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 27FC4Nhe052453; Mon, 15 Aug 2022 12:04:23 GMT (envelope-from git) Date: Mon, 15 Aug 2022 12:04:23 GMT Message-Id: <202208151204.27FC4Nhe052453@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Ganbold Tsagaankhuu Subject: git: 530d5f833860 - main - Add RockChip RK356X support to existing RockChip iodomain driver. List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: ganbold X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 530d5f83386092fe1e5cb220d3ca070cb9db0bfa Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1660565063; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=m0ipc38ebchy2E0Rc62dK3Vdhh+8gTGG5A1WHwghYb8=; b=C3ho9E07XVciSorIxHmZkolKE1eLzWwDXQQUGGYJp7A1O80aT+jVAWhk5k3KEUqVw0Eern UvWj08rbdx8ldNxa8zOxqte+PY/x949D7Iq8+BytWuw01N9HTB1IPanKPNWG0fx4wJqH9I L4JYb0vC3KONNF5vsqetpXZvbT0g+9o/kgLVdqPHLeVCrWRfq7mMq4tJhaj+DzRv8NQxTU bbcBlICadbDdf5ER7Rau9GPGaLsmAFnN0xgmmGtOs7p3lH33RB1NjtZ25zBowAF7mrvL6G yS/eKx2m5xJ0QtdlrB0YR3Yk9yA8rWDmLSdDLWB0VvrNwhnSyR2j+zKweWKpKw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1660565063; a=rsa-sha256; cv=none; b=EPDVF3XT6LmoM2Kj49UVymwujGZnDYjHLPgNdToMtVHxu9oGzSOuWV45vjA6kwiS1Ln0Fr 88VV6QW52awFprydo9AB0jMGjh6456EjypiqnxfwUXX5fuDxFoj5kQ/tbaJhC+vv3qTpW7 TpckhFv4f03HuptF0vpvHiELc+N79uP5QEhHQf35I9TLcu7uzJ8w+w7VjZbf9SLvRwMHak i0klQ7Ei1sDFuRiofnFvirl9ZsU8BTk7cwSuofKJCY7qmGWJVoZNzHba1epG7SczqJBdMY gInuMxvhzHp1YqFw8UDMGX5/GOoxfMeZUX8RSZRjZ3Z4sJ9NmK3hhyQ9NfR9oQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by ganbold: URL: https://cgit.FreeBSD.org/src/commit/?id=530d5f83386092fe1e5cb220d3ca070cb9db0bfa commit 530d5f83386092fe1e5cb220d3ca070cb9db0bfa Author: Søren Schmidt AuthorDate: 2022-08-15 12:03:28 +0000 Commit: Ganbold Tsagaankhuu CommitDate: 2022-08-15 12:03:28 +0000 Add RockChip RK356X support to existing RockChip iodomain driver. --- sys/arm64/rockchip/rk_iodomain.c | 120 +++++++++++++++++++++++++++++++++------ 1 file changed, 102 insertions(+), 18 deletions(-) diff --git a/sys/arm64/rockchip/rk_iodomain.c b/sys/arm64/rockchip/rk_iodomain.c index 183332208cd9..d37118ed7dec 100644 --- a/sys/arm64/rockchip/rk_iodomain.c +++ b/sys/arm64/rockchip/rk_iodomain.c @@ -46,6 +46,17 @@ __FBSDID("$FreeBSD$"); #define RK3288_GRF_IO_VSEL 0x380 #define RK3399_GRF_IO_VSEL 0xe640 #define RK3399_PMUGRF_SOC_CON0 0x180 +#define RK3568_PMUGRF_IO_VSEL0 0x0140 +#define RK3568_PMUGRF_IO_VSEL1 0x0144 +#define RK3568_PMUGRF_IO_VSEL2 0x0148 + +#define MAX_1V8 1850000 + +enum rk_iodomain_type { + RK3328 = 1, + RK3399, + RK3568, +}; struct rk_iodomain_supply { char *name; @@ -59,6 +70,7 @@ struct rk_iodomain_conf { int nsupply; uint32_t grf_reg; void (*init)(struct rk_iodomain_softc *sc); + enum rk_iodomain_type type; }; struct rk_iodomain_softc { @@ -85,6 +97,7 @@ static struct rk_iodomain_conf rk3288_conf = { .supply = rk3288_supply, .nsupply = nitems(rk3288_supply), .grf_reg = RK3288_GRF_IO_VSEL, + .type = RK3328, }; static struct rk_iodomain_supply rk3399_supply[] = { @@ -98,6 +111,7 @@ static struct rk_iodomain_conf rk3399_conf = { .supply = rk3399_supply, .nsupply = nitems(rk3399_supply), .grf_reg = RK3399_GRF_IO_VSEL, + .type = RK3399, }; static struct rk_iodomain_supply rk3399_pmu_supply[] = { @@ -110,12 +124,31 @@ static struct rk_iodomain_conf rk3399_pmu_conf = { .nsupply = nitems(rk3399_pmu_supply), .grf_reg = RK3399_PMUGRF_SOC_CON0, .init = rk3399_pmu_init, + .type = RK3399, +}; + +static struct rk_iodomain_supply rk3568_pmu_supply[] = { + {"pmuio1-supply", 0}, + {"pmuio2-supply", 1}, + {"vccio1-supply", 1}, + {"vccio2-supply", 2}, + {"vccio3-supply", 3}, + {"vccio4-supply", 4}, + {"vccio5-supply", 5}, + {"vccio6-supply", 6}, + {"vccio7-supply", 7}, +}; +static struct rk_iodomain_conf rk3568_pmu_conf = { + .supply = rk3568_pmu_supply, + .nsupply = nitems(rk3568_pmu_supply), + .type = RK3568, }; static struct ofw_compat_data compat_data[] = { {"rockchip,rk3288-io-voltage-domain", (uintptr_t)&rk3288_conf}, {"rockchip,rk3399-io-voltage-domain", (uintptr_t)&rk3399_conf}, {"rockchip,rk3399-pmu-io-voltage-domain", (uintptr_t)&rk3399_pmu_conf}, + {"rockchip,rk3568-pmu-io-voltage-domain", (uintptr_t)&rk3568_pmu_conf}, {NULL, 0} }; @@ -127,7 +160,7 @@ rk3399_pmu_init(struct rk_iodomain_softc *sc) (1 << 8) | (1 << (8 + 16))); /* set pmu1830_volsel */ } -static void +static int rk_iodomain_set(struct rk_iodomain_softc *sc) { regulator_t supply; @@ -136,26 +169,77 @@ rk_iodomain_set(struct rk_iodomain_softc *sc) int uvolt, i; for (i = 0; i < sc->conf->nsupply; i++) { - mask |= (1 << sc->conf->supply[i].bit) << 16; if (regulator_get_by_ofw_property(sc->dev, sc->node, - sc->conf->supply[i].name, &supply) == 0) { - if (regulator_get_voltage(supply, &uvolt) == 0) { - if (uvolt == 1800000) - reg |= (1 << sc->conf->supply[i].bit); - else if (uvolt != 3000000) - device_printf(sc->dev, - "%s regulator is at %duV, ignoring\n", - sc->conf->supply[i].name, uvolt); - } else - device_printf(sc->dev, "Cannot get current " - "voltage for regulator %s\n", - sc->conf->supply[i].name); + sc->conf->supply[i].name, &supply) != 0) { + device_printf(sc->dev, + "Cannot get property for regulator %s\n", + sc->conf->supply[i].name); + return (ENXIO); + } + + if (regulator_get_voltage(supply, &uvolt) != 0) { + device_printf(sc->dev, + "Cannot get current voltage for regulator %s\n", + sc->conf->supply[i].name); + return (ENXIO); } - } - SYSCON_WRITE_4(sc->grf, sc->conf->grf_reg, reg | mask); + if (sc->conf->type != RK3568) { + /* RK3328 and RK3399 iodomain */ + mask |= (1 << sc->conf->supply[i].bit) << 16; + if (uvolt == 1800000) + reg |= (1 << sc->conf->supply[i].bit); + else if (uvolt != 3000000) + device_printf(sc->dev, + "%s regulator is at %duV, ignoring\n", + sc->conf->supply[i].name, uvolt); + } else { + /* RK3568 iodomain */ + if (bootverbose) { + device_printf(sc->dev, + "Setting regulator %s voltage=%duV\n", + sc->conf->supply[i].name, uvolt); + } + switch(i) { + case 0: /* pmuio1 */ + break; + case 1: /* pmuio2 */ + SYSCON_WRITE_4(sc->grf, RK3568_PMUGRF_IO_VSEL2, + (1 << (sc->conf->supply[i].bit + 16)) | + (uvolt > MAX_1V8 ? + 0 : 1 << sc->conf->supply[i].bit)); + SYSCON_WRITE_4(sc->grf, RK3568_PMUGRF_IO_VSEL2, + (1 << (sc->conf->supply[i].bit + 4 + 16)) | + (uvolt > MAX_1V8 ? + 1 << (sc->conf->supply[i].bit + 4) : 0)); + case 3: /* vccio2 */ + break; + case 2: /* vccio1 */ + case 4: /* vccio3 */ + case 5: /* vccio4 */ + case 6: /* vccio5 */ + case 7: /* vccio6 */ + case 8: /* vccio7 */ + SYSCON_WRITE_4(sc->grf, RK3568_PMUGRF_IO_VSEL0, + (1 << (sc->conf->supply[i].bit + 16)) | + (uvolt > MAX_1V8 ? + 0 : 1 << sc->conf->supply[i].bit)); + SYSCON_WRITE_4(sc->grf, RK3568_PMUGRF_IO_VSEL1, + (1 << (sc->conf->supply[i].bit + 16)) | + (uvolt > MAX_1V8 ? + 1 << sc->conf->supply[i].bit : 0)); + break; + default: + device_printf(sc->dev, "Index out of range\n"); + } + } + } + if (sc->conf->type != RK3568) + SYSCON_WRITE_4(sc->grf, sc->conf->grf_reg, reg | mask); if (sc->conf->init != NULL) sc->conf->init(sc); + + return (0); } static int @@ -189,9 +273,9 @@ rk_iodomain_attach(device_t dev) } sc->conf = (struct rk_iodomain_conf *)ofw_bus_search_compatible(dev, compat_data)->ocd_data; - rk_iodomain_set(sc); + rv = rk_iodomain_set(sc); - return (0); + return (rv); } static int