From: Sjoerd Simons <sjoerd@collabora.com>
To: u-boot@lists.denx.de
Cc: Angus Ainslie <angus@akkea.ca>,
Jan Kiszka <jan.kiszka@siemens.com>, Marek Vasut <marex@denx.de>,
Michal Simek <michal.simek@amd.com>,
Sean Anderson <seanga2@gmail.com>,
T Karthik Reddy <t.karthik.reddy@xilinx.com>
Subject: [PATCH 5/8] usb: dwc3: Add dwc3 glue for am62
Date: Sat, 21 Jan 2023 16:54:31 +0100 [thread overview]
Message-ID: <20230121155435.2858173-6-sjoerd@collabora.com> (raw)
In-Reply-To: <20230121155435.2858173-1-sjoerd@collabora.com>
Add glue code for TI AM62 to the dwc3 driver; Most code adopted from
TI vendor u-boot code.
Signed-off-by: Sjoerd Simons <sjoerd@collabora.com>
---
drivers/usb/dwc3/dwc3-generic.c | 102 ++++++++++++++++++++++++++++++++
1 file changed, 102 insertions(+)
diff --git a/drivers/usb/dwc3/dwc3-generic.c b/drivers/usb/dwc3/dwc3-generic.c
index 78966718d01..cab7b2e928d 100644
--- a/drivers/usb/dwc3/dwc3-generic.c
+++ b/drivers/usb/dwc3/dwc3-generic.c
@@ -11,6 +11,7 @@
#include <cpu_func.h>
#include <log.h>
#include <dm.h>
+#include <dm/device_compat.h>
#include <dm/device-internal.h>
#include <dm/lists.h>
#include <dwc3-uboot.h>
@@ -23,7 +24,9 @@
#include <usb.h>
#include "core.h"
#include "gadget.h"
+#include <regmap.h>
#include <reset.h>
+#include <syscon.h>
#include <clk.h>
#include <usb/xhci.h>
#include <asm/gpio.h>
@@ -398,6 +401,104 @@ struct dwc3_glue_ops ti_ops = {
.glue_configure = dwc3_ti_glue_configure,
};
+void dwc3_ti_am62_glue_configure(struct udevice *dev, int index,
+ enum usb_dr_mode mode)
+{
+#define USBSS_MODE_CONTROL 0x1c
+#define USBSS_PHY_CONFIG 0x8
+#define USBSS_PHY_VBUS_SEL_MASK GENMASK(2, 1)
+#define USBSS_PHY_VBUS_SEL_SHIFT 1
+#define USBSS_MODE_VALID BIT(0)
+#define PHY_PLL_REFCLK_MASK GENMASK(3, 0)
+static const int dwc3_ti_am62_rate_table[] = { /* in KHZ */
+ 9600,
+ 10000,
+ 12000,
+ 19200,
+ 20000,
+ 24000,
+ 25000,
+ 26000,
+ 38400,
+ 40000,
+ 58000,
+ 50000,
+ 52000,
+};
+
+ struct clk usb2_refclk;
+ int rate_code, i, ret;
+ unsigned long rate;
+ u32 reg;
+ void *usbss;
+ bool vbus_divider;
+ struct regmap *syscon;
+ struct ofnode_phandle_args args;
+
+ usbss = dev_remap_addr_index(dev, 0);
+ if (IS_ERR(usbss)) {
+ dev_err(dev, "can't map IOMEM resource\n");
+ return;
+ }
+
+ ret = clk_get_by_name(dev, "ref", &usb2_refclk);
+ if (ret) {
+ dev_err(dev, "can't get usb2_refclk\n");
+ return;
+ }
+
+ /* Calcuate the rate code */
+ rate = clk_get_rate(&usb2_refclk);
+ rate /= 1000; /* To KHz */
+ for (i = 0; i < ARRAY_SIZE(dwc3_ti_am62_rate_table); i++) {
+ if (dwc3_ti_am62_rate_table[i] == rate)
+ break;
+ }
+
+ if (i == ARRAY_SIZE(dwc3_ti_am62_rate_table)) {
+ dev_err(dev, "unsupported usb2_refclk rate: %lu KHz\n", rate);
+ return;
+ }
+
+ rate_code = i;
+
+ /* Read the syscon property */
+ syscon = syscon_regmap_lookup_by_phandle(dev, "ti,syscon-phy-pll-refclk");
+ if (IS_ERR(syscon)) {
+ dev_err(dev, "unable to get ti,syscon-phy-pll-refclk regmap\n");
+ return;
+ }
+
+ ret = ofnode_parse_phandle_with_args(dev_ofnode(dev), "ti,syscon-phy-pll-refclk", NULL, 1,
+ 0, &args);
+ if (ret)
+ return;
+
+ /* Program PHY PLL refclk by reading syscon property */
+ ret = regmap_update_bits(syscon, args.args[0], PHY_PLL_REFCLK_MASK, rate_code);
+ if (ret) {
+ dev_err(dev, "failed to set phy pll reference clock rate\n");
+ return;
+ }
+
+ /* VBUS divider select */
+ reg = readl(usbss + USBSS_PHY_CONFIG);
+ vbus_divider = dev_read_bool(dev, "ti,vbus-divider");
+ if (vbus_divider)
+ reg |= 1 << USBSS_PHY_VBUS_SEL_SHIFT;
+
+ writel(reg, usbss + USBSS_PHY_CONFIG);
+
+ /* Set mode valid */
+ reg = readl(usbss + USBSS_MODE_CONTROL);
+ reg |= USBSS_MODE_VALID;
+ writel(reg, usbss + USBSS_MODE_CONTROL);
+}
+
+struct dwc3_glue_ops ti_am62_ops = {
+ .glue_configure = dwc3_ti_am62_glue_configure,
+};
+
static int dwc3_glue_bind(struct udevice *parent)
{
ofnode node;
@@ -570,6 +671,7 @@ static const struct udevice_id dwc3_glue_ids[] = {
{ .compatible = "ti,keystone-dwc3"},
{ .compatible = "ti,dwc3", .data = (ulong)&ti_ops },
{ .compatible = "ti,am437x-dwc3", .data = (ulong)&ti_ops },
+ { .compatible = "ti,am62-usb", .data = (ulong)&ti_am62_ops },
{ .compatible = "ti,am654-dwc3" },
{ .compatible = "rockchip,rk3328-dwc3" },
{ .compatible = "rockchip,rk3399-dwc3" },
--
2.39.0
next prev parent reply other threads:[~2023-01-21 15:55 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-01-21 15:54 [PATCH 0/8] Add DFU, emmc and usb boot for TI am62x Sjoerd Simons
2023-01-21 15:54 ` [PATCH 1/8] omap: timer: add ti,am654-timer compatibility Sjoerd Simons
2023-01-24 20:47 ` Tom Rini
2023-01-25 12:18 ` Dhruva Gole
2023-01-21 15:54 ` [PATCH 2/8] arm: mach-k3: am62: Add timer0 id to the dev list Sjoerd Simons
2023-01-24 20:47 ` Tom Rini
2023-01-21 15:54 ` [PATCH 3/8] arm: dts: k3-am62: Bump dtsi from ti-next Sjoerd Simons
2023-01-24 20:47 ` Tom Rini
2023-01-25 7:32 ` Sjoerd Simons
2023-01-25 14:05 ` Tom Rini
2023-01-21 15:54 ` [PATCH 4/8] arm: dts: k3-am625-sk: Enable emmc in SPL Sjoerd Simons
2023-01-24 20:47 ` Tom Rini
2023-01-26 18:26 ` Tom Rini
2023-01-21 15:54 ` Sjoerd Simons [this message]
2023-01-27 19:30 ` [PATCH 5/8] usb: dwc3: Add dwc3 glue for am62 Tom Rini
2023-01-21 15:54 ` [PATCH 6/8] configs: am62: Add configs for enabling USB in U-Boot Sjoerd Simons
2023-01-21 15:54 ` [PATCH 7/8] arm: dts: k3-am625-sk: Enable usb ports in u-boot Sjoerd Simons
2023-01-24 20:47 ` Tom Rini
2023-01-21 15:54 ` [PATCH 8/8] configs: am62x_evm_*: Enable USB and DFU support Sjoerd Simons
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230121155435.2858173-6-sjoerd@collabora.com \
--to=sjoerd@collabora.com \
--cc=angus@akkea.ca \
--cc=jan.kiszka@siemens.com \
--cc=marex@denx.de \
--cc=michal.simek@amd.com \
--cc=seanga2@gmail.com \
--cc=t.karthik.reddy@xilinx.com \
--cc=u-boot@lists.denx.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox