1 // SPDX-License-Identifier: GPL-2.0
3 // Copyright (C) 2019 Texas Instruments Incorporated - http://www.ti.com/
4 // Author: Vignesh Raghavendra <vigneshr@ti.com>
12 #define FSS_SYSC_REG 0x4
14 #define HYPERBUS_CALIB_COUNT 25
16 struct am654_hbmc_priv {
17 void __iomem *mmiobase;
21 /* Calibrate by looking for "QRY" string within the CFI space */
22 static int am654_hyperbus_calibrate(struct udevice *dev)
24 struct am654_hbmc_priv *priv = dev_get_priv(dev);
25 int count = HYPERBUS_CALIB_COUNT;
32 writew(0xF0, priv->mmiobase);
33 writew(0x98, priv->mmiobase + 0xaa);
36 qry[0] = readw(priv->mmiobase + 0x20);
37 qry[1] = readw(priv->mmiobase + 0x22);
38 qry[2] = readw(priv->mmiobase + 0x24);
40 if (qry[0] == 'Q' && qry[1] == 'R' && qry[2] == 'Y')
47 writew(0xF0, priv->mmiobase);
48 writew(0xFF, priv->mmiobase);
50 return pass_count == 5;
53 static int am654_select_hbmc(struct udevice *dev)
55 struct regmap *regmap = syscon_get_regmap(dev_get_parent(dev));
57 return regmap_update_bits(regmap, FSS_SYSC_REG, 0x2, 0x2);
60 static int am654_hbmc_bind(struct udevice *dev)
62 return dm_scan_fdt_dev(dev);
65 static int am654_hbmc_probe(struct udevice *dev)
67 struct am654_hbmc_priv *priv = dev_get_priv(dev);
70 priv->mmiobase = devfdt_remap_addr_index(dev, 1);
71 if (dev_read_bool(dev, "mux-controls")) {
72 ret = am654_select_hbmc(dev);
74 dev_err(dev, "Failed to select HBMC mux\n");
79 if (!priv->calibrated) {
80 ret = am654_hyperbus_calibrate(dev);
82 dev_err(dev, "Calibration Failed\n");
86 priv->calibrated = true;
91 static const struct udevice_id am654_hbmc_dt_ids[] = {
93 .compatible = "ti,am654-hbmc",
95 { /* end of table */ }
98 U_BOOT_DRIVER(hbmc_am654) = {
101 .of_match = am654_hbmc_dt_ids,
102 .probe = am654_hbmc_probe,
103 .bind = am654_hbmc_bind,
104 .priv_auto_alloc_size = sizeof(struct am654_hbmc_priv),