Skip to contentSkip to conversation

PCIe support for i.MX7

PATCH Superseded Andrey Smirnov 3 participants 24 messages Jan 12, 2019 – Jan 15, 2019

Subsystems (9)

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#1 lore raw

PATCH v2 1/18 regulator: Convert drivers to use struct regulator_desc

In reply to Andrey Smirnov

To simplify porting kernel code, port a very basic struct regulator_desc and convert all of the code to use it.

---
 drivers/regulator/bcm2835.c | 6 ++++--
 drivers/regulator/core.c    | 8 ++++----
 drivers/regulator/fixed.c   | 6 ++++--
 include/regulator.h         | 6 +++++-
 4 files changed, 17 insertions(+), 9 deletions(-)
drivers/regulator/bcm2835.c +4 -2
index 0ada05db16..ea7cf7fe1e 100644
@@ -24,6 +24,7 @@ static struct regulator_bcm2835 {
 
 	struct device_d *dev;
 	struct regulator_dev rdev;
+	struct regulator_desc rdesc;
 } regs[] = {
 	REG_DEV(BCM2835_MBOX_POWER_DEVID_SDHCI, "bcm2835_mci0"),
 	REG_DEV(BCM2835_MBOX_POWER_DEVID_UART0, "uart0-pl0110"),
@@ -108,7 +109,7 @@ static int regulator_bcm2835_is_enabled(struct regulator_dev *rdev)
 	return msg_pwr->get_power_state.body.resp.state;
 }
 
-static struct regulator_ops bcm2835_ops = {
+const static struct regulator_ops bcm2835_ops = {
 	.enable = regulator_bcm2835_enable,
 	.disable = regulator_bcm2835_disable,
 	.is_enabled = regulator_bcm2835_is_enabled,
@@ -122,7 +123,8 @@ static int regulator_bcm2835_probe(struct device_d *dev)
 	for (i = 0; i < ARRAY_SIZE(regs); i++) {
 		rb = &regs[i];
 
-		rb->rdev.ops = &bcm2835_ops;
+		rb->rdesc.ops = &bcm2835_ops;
+		rb->rdev.desc = &rb->rdesc;
 		rb->dev = dev;
 
 		ret = dev_regulator_register(&rb->rdev, rb->devname, NULL);
drivers/regulator/core.c +4 -4
index 39df980dcb..bcfbda62e3 100644
@@ -52,10 +52,10 @@ static int regulator_enable_internal(struct regulator_internal *ri)
 		return 0;
 	}
 
-	if (!ri->rdev->ops->enable)
+	if (!ri->rdev->desc->ops->enable)
 		return -ENOSYS;
 
-	ret = ri->rdev->ops->enable(ri->rdev);
+	ret = ri->rdev->desc->ops->enable(ri->rdev);
 	if (ret)
 		return ret;
 
@@ -74,10 +74,10 @@ static int regulator_disable_internal(struct regulator_internal *ri)
 	if (!ri->enable_count)
 		return -EINVAL;
 
-	if (!ri->rdev->ops->disable)
+	if (!ri->rdev->desc->ops->disable)
 		return -ENOSYS;
 
-	ret = ri->rdev->ops->disable(ri->rdev);
+	ret = ri->rdev->desc->ops->disable(ri->rdev);
 	if (ret)
 		return ret;
 
drivers/regulator/fixed.c +4 -2
index 87554d22e3..cb5d785817 100644
@@ -29,6 +29,7 @@ struct regulator_fixed {
 	int active_low;
 	int always_on;
 	struct regulator_dev rdev;
+	struct regulator_desc rdesc;
 };
 
 static int regulator_fixed_enable(struct regulator_dev *rdev)
@@ -54,7 +55,7 @@ static int regulator_fixed_disable(struct regulator_dev *rdev)
 	return gpio_direction_output(fix->gpio, fix->active_low);
 }
 
-static struct regulator_ops fixed_ops = {
+const static struct regulator_ops fixed_ops = {
 	.enable = regulator_fixed_enable,
 	.disable = regulator_fixed_disable,
 };
@@ -82,7 +83,8 @@ static int regulator_fixed_probe(struct device_d *dev)
 			fix->active_low = 1;
 	}
 
-	fix->rdev.ops = &fixed_ops;
+	fix->rdesc.ops = &fixed_ops;
+	fix->rdev.desc = &fix->rdesc;
 
 	if (of_find_property(dev->device_node, "regulator-always-on", NULL)) {
 		fix->always_on = 1;
include/regulator.h +5 -1
index 367e13f05b..907073607f 100644
@@ -4,8 +4,12 @@
 /* struct regulator is an opaque object for consumers */
 struct regulator;
 
+struct regulator_desc {
+	const struct regulator_ops *ops;
+};
+
 struct regulator_dev {
-	struct regulator_ops *ops;
+	const struct regulator_desc *desc;
 	int boot_on;
 };
 
Signature · 7 lines
2.20.1


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#0 lore raw

v2 cover PCIe support for i.MX7

Everyone:

This seires is a build-up on previously submitted PCI sync set [1] and contains the patches I created while working on adding support for PCIe on i.MX7. The series consists of following:

- Patches adding necessary regulator pluming to support porint ANATOP driver

- ANATOP driver port

- Port of basic power domain infrastructure from Linux kernel needed for controlling GPCv2 (useful for both i.MX7 and, especially, for i.MX8MQ)

- Port of GPCv2 driver from Linux as well as of some bug fixes for it

- Port of i.MX7 reset controller driver

- Patches adding support for i.MX7 to existing i.MX6 PCIe host controller driver

- Misc fixes

This series has been tested on i.MX7D SabreSD board against Toshiba NVMe device.

Feedback is welcome!

Changes since [v1]:

- Patches containing bugfixes for GPCv2 were squashed into the patch introducing the driver

- Patches containing bugfixes for i.MX7 reset controller were squashed into the patch introducing the driver

- Deffered probe by GPIO support in i.MX6 PCI driver fixed by having GPIO request preceed the call to dev_request_mem_resource()

Thanks,
Andrey Smirnov

[1] http://lists.infradead.org/pipermail/barebox/2018-December/036005.html
[v1] http://lists.infradead.org/pipermail/barebox/2019-January/036318.html

Andrey Smirnov (18):
regulator: Convert drivers to use struct regulator_desc
regulator: Port basic regmap regulator functions
regulator: Add support for setting regulator's voltage
base: driver: Drop redundant list_empty() check
base: Port driver_deferred_probe_check_state() from Linux
regulator: Add primitive support for deferred probe
regulator: Port ANATOP driver from Linux
drivers: base: Port power management code from Linux
soc: imx: Add GPCv2 power gating driver
reset: Add i.MX7 SRC reset driver
reset: Mark local functions as static
PCI: imx6: Add code to support i.MX7D
PCI: imx6: Allow probe deferral by reset GPIO
PCI: imx6: Do not wait for speed change on i.MX7
PCI: imx6: Do not switch speed if Gen2 is disabled
PCI: imx6: Fix spelling mistake: "contol" -> "control"
PCI: imx6: Drop unnecessary root_bus_nr setting
PCI: imx6: Port imx6_pcie_ltssm_enable()

 arch/arm/mach-imx/Kconfig            |   1 +
 drivers/Kconfig                      |   2 +
 drivers/Makefile                     |   1 +
 drivers/base/Kconfig                 |   3 +
 drivers/base/Makefile                |   4 +-
 drivers/base/driver.c                |  68 ++++--
 drivers/base/platform.c              |   7 +
 drivers/base/power.c                 | 245 +++++++++++++++++++++
 drivers/pci/Kconfig                  |   4 +-
 drivers/pci/pci-imx6.c               | 255 +++++++++++++++-------
 drivers/regulator/Kconfig            |   8 +
 drivers/regulator/Makefile           |   5 +-
 drivers/regulator/anatop-regulator.c | 161 ++++++++++++++
 drivers/regulator/bcm2835.c          |   6 +-
 drivers/regulator/core.c             |  60 ++++-
 drivers/regulator/fixed.c            |   6 +-
 drivers/regulator/helpers.c          | 186 ++++++++++++++++
 drivers/reset/Kconfig                |  11 +
 drivers/reset/Makefile               |   1 +
 drivers/reset/core.c                 |   8 +-
 drivers/reset/reset-imx7.c           | 151 +++++++++++++
 drivers/soc/imx/Kconfig              |   9 +
 drivers/soc/imx/Makefile             |   1 +
 drivers/soc/imx/gpcv2.c              | 315 +++++++++++++++++++++++++++
 include/driver.h                     |   2 +
 include/pm_domain.h                  |  82 +++++++
 include/regulator.h                  |  41 +++-
 27 files changed, 1529 insertions(+), 114 deletions(-)
 create mode 100644 drivers/base/Kconfig
 create mode 100644 drivers/base/power.c
 create mode 100644 drivers/regulator/anatop-regulator.c
 create mode 100644 drivers/regulator/helpers.c
 create mode 100644 drivers/reset/reset-imx7.c
 create mode 100644 drivers/soc/imx/Kconfig
 create mode 100644 drivers/soc/imx/Makefile
 create mode 100644 drivers/soc/imx/gpcv2.c
 create mode 100644 include/pm_domain.h
Signature · 7 lines
2.20.1


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#2 lore raw

PATCH v2 2/18 regulator: Port basic regmap regulator functions

In order to be able to port Linux driver relying on this API, port various regmap related regulator function to Barebox.

---
 drivers/regulator/Makefile  |  2 +-
 drivers/regulator/helpers.c | 87 +++++++++++++++++++++++++++++++++++++
 include/regulator.h         | 11 ++++-
 3 files changed, 98 insertions(+), 2 deletions(-)
 create mode 100644 drivers/regulator/helpers.c
drivers/regulator/Makefile +1 -1
index ff5daf9a7d..36ce3e87f7 100644
@@ -1,4 +1,4 @@
-obj-$(CONFIG_REGULATOR) += core.o
+obj-$(CONFIG_REGULATOR) += core.o helpers.o
 obj-$(CONFIG_REGULATOR_FIXED) += fixed.o
 obj-$(CONFIG_REGULATOR_BCM283X) += bcm2835.o
 obj-$(CONFIG_REGULATOR_PFUZE) += pfuze.o
\ No newline at end of file
drivers/regulator/helpers.c new file +87 -0

87 lines not on this page · raw message

include/regulator.h +10 -1
index 907073607f..1824e6ea14 100644
@@ -6,10 +6,17 @@ struct regulator;
 
 struct regulator_desc {
 	const struct regulator_ops *ops;
+
+	unsigned int enable_reg;
+	unsigned int enable_mask;
+	unsigned int enable_val;
+	unsigned int disable_val;
+	bool enable_is_inverted;
 };
 
 struct regulator_dev {
 	const struct regulator_desc *desc;
+	struct regmap *regmap;
 	int boot_on;
 };
 
@@ -39,7 +46,9 @@ void regulators_print(void);
 struct regulator *regulator_get(struct device_d *, const char *);
 int regulator_enable(struct regulator *);
 int regulator_disable(struct regulator *);
-
+int regulator_is_enabled_regmap(struct regulator_dev *);
+int regulator_enable_regmap(struct regulator_dev *);
+int regulator_disable_regmap(struct regulator_dev *);
 #else
 
 static inline struct regulator *regulator_get(struct device_d *dev, const char *id)
Signature · 7 lines
2.20.1


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#3 lore raw

PATCH v2 3/18 regulator: Add support for setting regulator's voltage

In reply to Andrey Smirnov

Add code needed to implement regulator_set_voltage(). Currently only bare minmum needed for ANATOP driver (added in follow up commit) is supported.

---
 drivers/regulator/core.c    | 44 +++++++++++++++++
 drivers/regulator/helpers.c | 99 +++++++++++++++++++++++++++++++++++++
 include/regulator.h         | 24 +++++++++
 3 files changed, 167 insertions(+)
drivers/regulator/core.c +44 -0
index bcfbda62e3..795dcdb8c1 100644
@@ -43,6 +43,15 @@ struct regulator {
 	struct device_d *dev;
 };
 
+static int regulator_map_voltage(struct regulator_dev *rdev, int min_uV,
+				 int max_uV)
+{
+	if (rdev->desc->ops->list_voltage == regulator_list_voltage_linear)
+		return regulator_map_voltage_linear(rdev, min_uV, max_uV);
+
+	return -ENOSYS;
+}
+
 static int regulator_enable_internal(struct regulator_internal *ri)
 {
 	int ret;
@@ -86,6 +95,33 @@ static int regulator_disable_internal(struct regulator_internal *ri)
 	return 0;
 }
 
+static int regulator_set_voltage_internal(struct regulator_internal *ri,
+					  int min_uV, int max_uV)
+{
+	struct regulator_dev *rdev = ri->rdev;
+	const struct regulator_ops *ops = rdev->desc->ops;
+	unsigned int selector;
+	int best_val = 0;
+	int ret;
+
+	if (ops->set_voltage_sel) {
+		ret = regulator_map_voltage(rdev, min_uV, max_uV);
+		if (ret >= 0) {
+			best_val = ops->list_voltage(rdev, ret);
+			if (min_uV <= best_val && max_uV >= best_val) {
+				selector = ret;
+				ret = ops->set_voltage_sel(rdev, selector);
+			} else {
+				ret = -EINVAL;
+			}
+		}
+
+		return ret;
+	}
+
+	return -ENOSYS;
+}
+
 static struct regulator_internal * __regulator_register(struct regulator_dev *rd, const char *name)
 {
 	struct regulator_internal *ri;
@@ -320,6 +356,14 @@ int regulator_disable(struct regulator *r)
 	return regulator_disable_internal(r->ri);
 }
 
+int regulator_set_voltage(struct regulator *r, int min_uV, int max_uV)
+{
+	if (!r)
+		return 0;
+
+	return regulator_set_voltage_internal(r->ri, min_uV, max_uV);
+}
+
 static void regulator_print_one(struct regulator_internal *ri)
 {
 	struct regulator *r;
drivers/regulator/helpers.c +99 -0

102 lines not on this page · raw message

include/regulator.h +24 -0
index 1824e6ea14..cd1d3ccf55 100644
@@ -5,8 +5,17 @@
 struct regulator;
 
 struct regulator_desc {
+	unsigned n_voltages;
 	const struct regulator_ops *ops;
 
+	unsigned int min_uV;
+	unsigned int uV_step;
+	unsigned int linear_min_sel;
+
+	unsigned int vsel_reg;
+	unsigned int vsel_mask;
+	unsigned int apply_reg;
+	unsigned int apply_bit;
 	unsigned int enable_reg;
 	unsigned int enable_mask;
 	unsigned int enable_val;
@@ -25,6 +34,9 @@ struct regulator_ops {
 	int (*enable) (struct regulator_dev *);
 	int (*disable) (struct regulator_dev *);
 	int (*is_enabled) (struct regulator_dev *);
+
+	int (*list_voltage) (struct regulator_dev *, unsigned int);
+	int (*set_voltage_sel) (struct regulator_dev *, unsigned int);
 };
 
 #ifdef CONFIG_OFDEVICE
@@ -49,6 +61,12 @@ int regulator_disable(struct regulator *);
 int regulator_is_enabled_regmap(struct regulator_dev *);
 int regulator_enable_regmap(struct regulator_dev *);
 int regulator_disable_regmap(struct regulator_dev *);
+int regulator_set_voltage_sel_regmap(struct regulator_dev *, unsigned);
+int regulator_set_voltage(struct regulator *regulator, int min_uV, int max_uV);
+int regulator_map_voltage_linear(struct regulator_dev *rdev,
+				 int min_uV, int max_uV);
+int regulator_list_voltage_linear(struct regulator_dev *rdev,
+				  unsigned int selector);
 #else
 
 static inline struct regulator *regulator_get(struct device_d *dev, const char *id)
@@ -66,6 +84,12 @@ static inline int regulator_disable(struct regulator *r)
 	return 0;
 }
 
+static inline int regulator_set_voltage(struct regulator *regulator,
+					int min_uV, int max_uV)
+{
+	return 0;
+}
+
 #endif
 
 #endif /* __REGULATOR_H */
Signature · 7 lines
2.20.1


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#4 lore raw

PATCH v2 4/18 base: driver: Drop redundant list_empty() check

In reply to Andrey Smirnov
---
 drivers/base/driver.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
drivers/base/driver.c +1 -4
index 1fd890542e..1fd6bbc014 100644
@@ -269,7 +269,7 @@ static int device_probe_deferred(void)
 		success = false;
 
 		if (list_empty(&deferred))
-			break;
+			return 0;
 
 		list_for_each_entry_safe(dev, tmp, &deferred, active) {
 			list_del(&dev->active);
@@ -285,9 +285,6 @@ static int device_probe_deferred(void)
 		}
 	} while (success);
 
-	if (list_empty(&deferred))
-		return 0;
-
 	list_for_each_entry(dev, &deferred, active)
 		dev_err(dev, "probe permanently deferred\n");
 
Signature · 7 lines
2.20.1


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#6 lore raw

PATCH v2 6/18 regulator: Add primitive support for deferred probe

In reply to Andrey Smirnov

Don't report requested regulator (via of_regulator_get()) as non-existent if said regulator is missing from regulator list. Instead rely on driver_deferred_probe_check_state() to properly declare regulator as such after all of the initcalls were done and no further missing dependencies could be resolved.

---
 drivers/regulator/core.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
drivers/regulator/core.c +7 -1
index 795dcdb8c1..a5ac8f3c94 100644
@@ -227,7 +227,13 @@ static struct regulator_internal *of_regulator_get(struct device_d *dev, const c
 		}
 	}
 
-	ri = ERR_PTR(-ENODEV);
+	/*
+	 * It is possible that regulator we are looking for will be
+	 * added in future initcalls, so, instead of reporting a
+	 * complete failure we see if probe deferral is more
+	 * appropriate
+	 */
+	ri = ERR_PTR(driver_deferred_probe_check_state(dev));
 out:
 	free(propname);
 
Signature · 7 lines
2.20.1


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#5 lore raw

PATCH v2 5/18 base: Port driver_deferred_probe_check_state() from Linux

In reply to Andrey Smirnov

Port driver_deferred_probe_check_state() from Linux by adding on last pass going through all of the deferred drivers that allows us to declare all unresolved dependencies as missing.

---
 drivers/base/driver.c | 73 ++++++++++++++++++++++++++++++++-----------
 include/driver.h      |  2 ++
 2 files changed, 57 insertions(+), 18 deletions(-)
drivers/base/driver.c +55 -18
index 1fd6bbc014..be735189a5 100644
@@ -46,6 +46,8 @@ EXPORT_SYMBOL(driver_list);
 static LIST_HEAD(active);
 static LIST_HEAD(deferred);
 
+static bool initcalls_done;
+
 struct device_d *get_device_by_name(const char *name)
 {
 	struct device_d *dev;
@@ -259,31 +261,66 @@ EXPORT_SYMBOL(unregister_device);
  * For devices finally left in deferred list -EPROBE_DEFER
  * becomes a fatal error.
  */
-static int device_probe_deferred(void)
+
+/**
+ * driver_deferred_probe_check_state() - Check deferred probe state
+ * @dev: device to check
+ *
+ * Returns -ENODEV if init is done and all built-in drivers have had a chance
+ * to probe (i.e. initcalls are done), -ETIMEDOUT if deferred probe debug
+ * timeout has expired, or -EPROBE_DEFER if none of those conditions are met.
+ *
+ * Drivers or subsystems can opt-in to calling this function instead of directly
+ * returning -EPROBE_DEFER.
+ */
+int driver_deferred_probe_check_state(struct device_d *dev)
+{
+	if (initcalls_done) {
+		dev_warn(dev, "ignoring dependency for device, assuming no driver");
+		return -ENODEV;
+	}
+	return -EPROBE_DEFER;
+}
+
+static bool device_probe_deferred_match_all(void)
 {
 	struct device_d *dev, *tmp;
 	struct driver_d *drv;
-	bool success;
+	bool success = false;
 
-	do {
-		success = false;
+	list_for_each_entry_safe(dev, tmp, &deferred, active) {
+		list_del(&dev->active);
+		INIT_LIST_HEAD(&dev->active);
 
-		if (list_empty(&deferred))
-			return 0;
+		dev_dbg(dev, "re-probe device\n");
+		bus_for_each_driver(dev->bus, drv) {
+			if (match(drv, dev))
+				continue;
+			success = true;
+			break;
+		}
+	}
 
-		list_for_each_entry_safe(dev, tmp, &deferred, active) {
-			list_del(&dev->active);
-			INIT_LIST_HEAD(&dev->active);
+	return success;
+}
 
-			dev_dbg(dev, "re-probe device\n");
-			bus_for_each_driver(dev->bus, drv) {
-				if (match(drv, dev))
-					continue;
-				success = true;
-				break;
-			}
-		}
-	} while (success);
+static int device_probe_deferred(void)
+{
+	struct device_d *dev;
+
+	while (device_probe_deferred_match_all())
+		;
+
+	initcalls_done = true;
+
+	if (list_empty(&deferred))
+		return 0;
+	/*
+	 * Loop over all deferred devices to give various functions
+	 * that call driver_deferred_probe_check_state() a chance to
+	 * finally return -ENODEV as opposed to -EPROBE_DEFER
+	 */
+	device_probe_deferred_match_all();
 
 	list_for_each_entry(dev, &deferred, active)
 		dev_err(dev, "probe permanently deferred\n");
include/driver.h +2 -0
index 3d9970df53..385e410dd4 100644
@@ -151,6 +151,8 @@ void device_detect_all(void);
  */
 int unregister_device(struct device_d *);
 
+int driver_deferred_probe_check_state(struct device_d *dev);
+
 /* Iterate over a devices children
  */
 #define device_for_each_child(dev, child) \
Signature · 7 lines
2.20.1


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#7 lore raw

PATCH v2 7/18 regulator: Port ANATOP driver from Linux

In reply to Andrey Smirnov

Port a subset of Linux driver sufficient enough to support feature needed for PCIe on i.MX7.

---
 drivers/regulator/Kconfig            |   8 ++
 drivers/regulator/Makefile           |   3 +-
 drivers/regulator/anatop-regulator.c | 161 +++++++++++++++++++++++++++
 3 files changed, 171 insertions(+), 1 deletion(-)
 create mode 100644 drivers/regulator/anatop-regulator.c
drivers/regulator/Kconfig +8 -0
index 92db8dc0e0..c734ef5ef9 100644
@@ -21,4 +21,12 @@ config REGULATOR_PFUZE
 	depends on I2C
 	depends on ARCH_IMX6
 
+config REGULATOR_ANATOP
+	tristate "Freescale i.MX on-chip ANATOP LDO regulators"
+	depends on MFD_SYSCON
+	help
+	  Say y here to support Freescale i.MX on-chip ANATOP LDOs
+	  regulators. It is recommended that this option be
+	  enabled on i.MX6 platform.
+
 endif
drivers/regulator/Makefile +2 -1
index 36ce3e87f7..b2fc5b79b6 100644
@@ -1,4 +1,5 @@
 obj-$(CONFIG_REGULATOR) += core.o helpers.o
 obj-$(CONFIG_REGULATOR_FIXED) += fixed.o
 obj-$(CONFIG_REGULATOR_BCM283X) += bcm2835.o
-obj-$(CONFIG_REGULATOR_PFUZE) += pfuze.o
\ No newline at end of file
+obj-$(CONFIG_REGULATOR_PFUZE) += pfuze.o
+obj-$(CONFIG_REGULATOR_ANATOP) += anatop-regulator.o
\ No newline at end of file
drivers/regulator/anatop-regulator.c new file +161 -0

161 lines not on this page · raw message

Signature · 7 lines
2.20.1


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#9 lore raw

PATCH v2 9/18 soc: imx: Add GPCv2 power gating driver

In reply to Andrey Smirnov

Port of a Linux commit 03aa12629fc4f73acf28e519c9ee9cb1f5dd3706

Add code allowing for control of various power domains managed by GPCv2 IP block found in i.MX7 series of SoCs. Power domains covered by this patch are:

- PCIE PHY
- MIPI PHY
- USB HSIC PHY
- USB OTG1/2 PHY

Support for any other power domain controlled by GPC is not present, and can be added at some later point.

Testing of this code was done against a PCIe driver.

Linux commit 9e01e2d56db23485a75864b6aeee8e443f024ddb was squashed here as well:

soc: imx: gpcv2: fix regulator deferred probe

If a regulator requests a deferred probe, the power domain gets initialized twice. This leads to a list double add (without list debugging the kernel hangs due to the double add later):

    WARNING: CPU: 0 PID: 19 at lib/list_debug.c:31 __list_add_valid+0xbc/0xc4
    list_add double add: new=c1229754, prev=c12383b4, next=c1229754.

Initialize the power domain after we get the regulator. Also do not print an error in case the regulator defers probing.

Cc Fabio Estevam <[email protected]>
Cc Andrey Smirnov <[email protected]>
Fixes 03aa12629fc4 ("soc: imx: Add GPCv2 power gating driver")

Linux commit 3637f12faf507b0a4b8ac1e7115fc99583ab1db3 was squashed here as well

soc: imx: gpcv2: correct PGC offset

Correct MIPI/PCIe/USB_HSIC's PGC offset based on design RTL, the values in the Reference Manual (Rev. 1, 01/2018 and the older ones) are incorrect.

The correct offset values should be as below:

0x800 ~ 0x83F: PGC for core0 of A7 platform;
0x840 ~ 0x87F: PGC for core1 of A7 platform;
0x880 ~ 0x8BF: PGC for SCU of A7 platform;
0xA00 ~ 0xA3F: PGC for fastmix/megamix;
0xC00 ~ 0xC3F: PGC for MIPI PHY;
0xC40 ~ 0xC7F: PGC for PCIe_PHY;
0xC80 ~ 0xCBF: PGC for USB OTG1 PHY;
0xCC0 ~ 0xCFF: PGC for USB OTG2 PHY;
0xD00 ~ 0xD3F: PGC for USB HSIC PHY;

Fixes 03aa12629fc4 ("soc: imx: Add GPCv2 power gating driver")
---
 drivers/Kconfig          |   1 +
 drivers/Makefile         |   1 +
 drivers/soc/imx/Kconfig  |   9 ++
 drivers/soc/imx/Makefile |   1 +
 drivers/soc/imx/gpcv2.c  | 315 +++++++++++++++++++++++++++++++++++++++
 5 files changed, 327 insertions(+)
 create mode 100644 drivers/soc/imx/Kconfig
 create mode 100644 drivers/soc/imx/Makefile
 create mode 100644 drivers/soc/imx/gpcv2.c
drivers/Kconfig +1 -0
index c3bf9dfe18..c6c2eb14db 100644
@@ -38,5 +38,6 @@ source "drivers/firmware/Kconfig"
 source "drivers/phy/Kconfig"
 source "drivers/crypto/Kconfig"
 source "drivers/memory/Kconfig"
+source "drivers/soc/imx/Kconfig"
 
 endmenu
drivers/Makefile +1 -0
index 767789d541..752fd66242 100644
@@ -38,3 +38,4 @@ obj-$(CONFIG_HAB) += hab/
 obj-$(CONFIG_CRYPTO_HW) += crypto/
 obj-$(CONFIG_AIODEV) += aiodev/
 obj-y	+= memory/
+obj-y	+= soc/imx/
drivers/soc/imx/Kconfig new file +9 -0
new file mode 100644
index 0000000000..a78a9e3967
@@ -0,0 +1,9 @@
+menu "i.MX SoC drivers"
+
+config IMX7_PM_DOMAINS
+	bool "i.MX7 PM domains"
+	depends on ARCH_IMX7
+	select PM_GENERIC_DOMAINS
+	default y if ARCH_IMX7
+
+endmenu
drivers/soc/imx/Makefile new file +1 -0
new file mode 100644
index 0000000000..b039f77dc1
@@ -0,0 +1 @@
+obj-$(CONFIG_IMX7_PM_DOMAINS) += gpcv2.o
drivers/soc/imx/gpcv2.c new file +315 -0

315 lines not on this page · raw message

Signature · 7 lines
2.20.1


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#10 lore raw

PATCH v2 10/18 reset: Add i.MX7 SRC reset driver

In reply to Andrey Smirnov

Port of a Linux commit abf97755ae31aaaf35156438dd3036e96f66da83

Add reset controller driver exposing various reset faculties, implemented by System Reset Controller IP block.

Linux commit 26fce0557fa639fb7bbc33e31a57cff7df25c3a0 was squashed here as well:

reset: imx7: Fix always writing bits as 0

Right now the only user of reset-imx7 is pci-imx6 and the reset_control_assert and deassert calls on pciephy_reset don't toggle the PCIEPHY_BTN and PCIEPHY_G_RST bits as expected. Fix this by writing 1 or 0 respectively.

The reference manual is not very clear regarding SRC_PCIEPHY_RCR but for other registers like MIPIPHY and HSICPHY the bits are explicitly documented as "1 means assert, 0 means deassert".

The values are still reversed for IMX7_RESET_PCIE_CTRL_APPS_EN.

---
 drivers/reset/Kconfig      |  11 +++
 drivers/reset/Makefile     |   1 +
 drivers/reset/reset-imx7.c | 151 +++++++++++++++++++++++++++++++++++++
 3 files changed, 163 insertions(+)
 create mode 100644 drivers/reset/reset-imx7.c
drivers/reset/Kconfig +11 -0
index c9d04f7978..caf1dc9acb 100644
@@ -11,3 +11,14 @@ menuconfig RESET_CONTROLLER
 	  via GPIOs or SoC-internal reset controller modules.
 
 	  If unsure, say no.
+
+if RESET_CONTROLLER
+
+config RESET_IMX7
+	bool "i.MX7 Reset Driver"
+	default SOC_IMX7D
+	select MFD_SYSCON
+	help
+	  This enables the reset controller driver for i.MX7 SoCs.
+
+endif
drivers/reset/Makefile +1 -0
index 52b10cd480..0b55caa204 100644
@@ -1,2 +1,3 @@
 obj-$(CONFIG_RESET_CONTROLLER) += core.o
 obj-$(CONFIG_ARCH_SOCFPGA) += reset-socfpga.o
+obj-$(CONFIG_RESET_IMX7) += reset-imx7.o
drivers/reset/reset-imx7.c new file +151 -0

151 lines not on this page · raw message

Signature · 7 lines
2.20.1


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#11 lore raw

PATCH v2 11/18 reset: Mark local functions as static

In reply to Andrey Smirnov

There are no outside users of of_reset_control_get() or gpio_reset_control_get(), so mark them as static. This allows us to avoid "no previous prototype" warning as well.

---
 drivers/reset/core.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/reset/core.c +4 -4
index 59f75ca475..99b9c80655 100644
@@ -147,8 +147,8 @@ EXPORT_SYMBOL_GPL(reset_control_deassert);
  *
  * Use of id names is optional.
  */
-struct reset_control *of_reset_control_get(struct device_node *node,
-					   const char *id)
+static struct reset_control *of_reset_control_get(struct device_node *node,
+						  const char *id)
 {
 	struct reset_control *rstc = ERR_PTR(-ENODEV);
 	struct reset_controller_dev *r, *rcdev;
@@ -194,9 +194,9 @@ struct reset_control *of_reset_control_get(struct device_node *node,
 
 	return rstc;
 }
-EXPORT_SYMBOL_GPL(of_reset_control_get);
 
-struct reset_control *gpio_reset_control_get(struct device_d *dev, const char *id)
+static struct reset_control *
+gpio_reset_control_get(struct device_d *dev, const char *id)
 {
 	struct reset_control *rc;
 	int gpio;
Signature · 7 lines
2.20.1


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#8 lore raw

PATCH v2 8/18 drivers: base: Port power management code from Linux

In reply to Andrey Smirnov

Port an extremely abridged version of power management/power domain code from Linux as a dependency of i.MX7D PCIe work. Currenlty only bare minimum of functionality is implemented.

---
 drivers/Kconfig         |   1 +
 drivers/base/Kconfig    |   3 +
 drivers/base/Makefile   |   4 +-
 drivers/base/platform.c |   7 ++
 drivers/base/power.c    | 245 ++++++++++++++++++++++++++++++++++++++++
 include/pm_domain.h     |  82 ++++++++++++++
 6 files changed, 341 insertions(+), 1 deletion(-)
 create mode 100644 drivers/base/Kconfig
 create mode 100644 drivers/base/power.c
 create mode 100644 include/pm_domain.h
drivers/Kconfig +1 -0
index 1e0246da6d..c3bf9dfe18 100644
@@ -1,5 +1,6 @@
 menu "Drivers"
 
+source "drivers/base/Kconfig"
 source "drivers/efi/Kconfig"
 source "drivers/of/Kconfig"
 source "drivers/aiodev/Kconfig"
drivers/base/Kconfig new file +3 -0
new file mode 100644
index 0000000000..1e13e5ed9d
@@ -0,0 +1,3 @@
+
+config PM_GENERIC_DOMAINS
+	bool
drivers/base/Makefile +3 -1
index 4bd4217745..6d2cef8e1a 100644
@@ -2,4 +2,6 @@ obj-y	+= bus.o
 obj-y	+= driver.o
 obj-y	+= platform.o
 obj-y	+= resource.o
-obj-y	+= regmap/
\ No newline at end of file
+obj-y	+= regmap/
+
+obj-$(CONFIG_PM_GENERIC_DOMAINS) += power.o
drivers/base/platform.c +7 -0
index 85bdfb0149..1d3fa2eb44 100644
@@ -21,9 +21,16 @@
 #include <errno.h>
 #include <init.h>
 #include <of.h>
+#include <pm_domain.h>
 
 static int platform_probe(struct device_d *dev)
 {
+	int ret;
+
+	ret = genpd_dev_pm_attach(dev);
+	if (ret < 0)
+		return ret;
+
 	return dev->driver->probe(dev);
 }
 
drivers/base/power.c new file +245 -0

245 lines not on this page · raw message

include/pm_domain.h new file +82 -0

83 lines not on this page · raw message

Signature · 7 lines
2.20.1


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#13 lore raw

PATCH v2 13/18 PCI: imx6: Allow probe deferral by reset GPIO

In reply to Andrey Smirnov

Port of a Linux commit bde4a5a00e761f55be92f62378cf5024ced79ee3

Some designs implement reset GPIO via a GPIO expander connected to a peripheral bus. One such example would be i.MX7 Sabre board where said GPIO is provided by SPI shift register connected to a bitbanged SPI bus. To support such designs, allow reset GPIO request to defer probing of the driver.

---
 drivers/pci/pci-imx6.c | 19 +++++++++++--------
 1 file changed, 11 insertions(+), 8 deletions(-)
drivers/pci/pci-imx6.c +11 -8
index 6471f95b62..ce68b007ab 100644
@@ -562,8 +562,8 @@ static const struct dw_pcie_host_ops imx6_pcie_host_ops = {
 	.host_init = imx6_pcie_host_init,
 };
 
-static int __init imx6_add_pcie_port(struct imx6_pcie *imx6_pcie,
-				     struct device_d *dev)
+static int imx6_add_pcie_port(struct imx6_pcie *imx6_pcie,
+			      struct device_d *dev)
 {
 	struct dw_pcie *pci = imx6_pcie->pci;
 	struct pcie_port *pp = &pci->pp;
@@ -581,7 +581,7 @@ static int __init imx6_add_pcie_port(struct imx6_pcie *imx6_pcie,
 	return 0;
 }
 
-static int __init imx6_pcie_probe(struct device_d *dev)
+static int imx6_pcie_probe(struct device_d *dev)
 {
 	struct resource *iores;
 	struct dw_pcie *pci;
@@ -599,13 +599,11 @@ static int __init imx6_pcie_probe(struct device_d *dev)
 	imx6_pcie->variant =
 		(enum imx6_pcie_variants)of_device_get_match_data(dev);
 
-	iores = dev_request_mem_resource(dev, 0);
-	if (IS_ERR(iores))
-		return PTR_ERR(iores);
-	pci->dbi_base = IOMEM(iores->start);
-
 	/* Fetch GPIOs */
 	imx6_pcie->reset_gpio = of_get_named_gpio(np, "reset-gpio", 0);
+	if (imx6_pcie->reset_gpio == -EPROBE_DEFER)
+		return imx6_pcie->reset_gpio;
+
 	if (gpio_is_valid(imx6_pcie->reset_gpio)) {
 		ret = gpio_request_one(imx6_pcie->reset_gpio,
 					    GPIOF_OUT_INIT_LOW, "PCIe reset");
@@ -615,6 +613,11 @@ static int __init imx6_pcie_probe(struct device_d *dev)
 		}
 	}
 
+	iores = dev_request_mem_resource(dev, 0);
+	if (IS_ERR(iores))
+		return PTR_ERR(iores);
+	pci->dbi_base = IOMEM(iores->start);
+
 	/* Fetch clocks */
 	imx6_pcie->pcie_phy = clk_get(dev, "pcie_phy");
 	if (IS_ERR(imx6_pcie->pcie_phy)) {
Signature · 7 lines
2.20.1


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#14 lore raw

PATCH v2 14/18 PCI: imx6: Do not wait for speed change on i.MX7

In reply to Andrey Smirnov

Port of a Linux commit e6dcd87fff69a9d454104b65569074855cf95b1e

As can be seen from [1]:

"...the different behavior between iMX6Q PCIe and iMX7D PCIe maybe caused by the different controller version.

Regarding to the DOC description, the DIRECT_SPEED_CHANGE should be cleared after the speed change from GEN1 to GEN2. Unfortunately, when GEN1 device is used, the behavior is not documented.

So, IC design guys run the simulation and find out the following behaviors:

1. DIRECT_SPEED_CHANGE will be cleared in 7D after speed change from GEN1 to GEN2. This matches doc’s description

2. set MAX link speed(PCIE_CAP_TARGET_LINK_SPEED=0x01) as GEN1 and re-run the simulation, DIRECT_SPEED_CHANGE will not be cleared; remain as 1, this matches your result, but function test is passed, so this bit should not affect the normal PCIe function."

imx6_pcie_wait_for_speed_change() will report false failures for Gen1 -> Gen1 speed transition, so avoid doing that check and just rely on imx6_pcie_wait_for_link() only.

[1] https://community.nxp.com/message/867943

---
 drivers/pci/pci-imx6.c | 19 +++++++++++++++----
 1 file changed, 15 insertions(+), 4 deletions(-)
drivers/pci/pci-imx6.c +15 -4
index ce68b007ab..d121a20ce1 100644
@@ -508,10 +508,21 @@ static int imx6_pcie_establish_link(struct imx6_pcie *imx6_pcie)
 	tmp |= PORT_LOGIC_SPEED_CHANGE;
 	dw_pcie_writel_dbi(pci, PCIE_LINK_WIDTH_SPEED_CONTROL, tmp);
 
-	ret = imx6_pcie_wait_for_speed_change(imx6_pcie);
-	if (ret) {
-		dev_err(dev, "Failed to bring link up!\n");
-		goto err_reset_phy;
+	if (imx6_pcie->variant != IMX7D) {
+		/*
+		 * On i.MX7, DIRECT_SPEED_CHANGE behaves differently
+		 * from i.MX6 family when no link speed transition
+		 * occurs and we go Gen1 -> yep, Gen1. The difference
+		 * is that, in such case, it will not be cleared by HW
+		 * which will cause the following code to report false
+		 * failure.
+		 */
+
+		ret = imx6_pcie_wait_for_speed_change(imx6_pcie);
+		if (ret) {
+			dev_err(dev, "Failed to bring link up!\n");
+			goto err_reset_phy;
+		}
 	}
 
 	/* Make sure link training is finished as well! */
Signature · 7 lines
2.20.1


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#12 lore raw

PATCH v2 12/18 PCI: imx6: Add code to support i.MX7D

In reply to Andrey Smirnov

Port of a Linux commit 9b3fe6796d7c0e0c2b87243ce0c7f4744c54efad

Add various bits of code needed to support i.MX7D variant of the IP.

---
 arch/arm/mach-imx/Kconfig |   1 +
 drivers/pci/Kconfig       |   4 +-
 drivers/pci/pci-imx6.c    | 166 ++++++++++++++++++++++++++++----------
 3 files changed, 125 insertions(+), 46 deletions(-)
arch/arm/mach-imx/Kconfig +1 -0
index f14c9c3edf..3ad922c50c 100644
@@ -173,6 +173,7 @@ config ARCH_IMX7
 	select COMMON_CLK_OF_PROVIDER
 	select ARCH_HAS_FEC_IMX
 	select ARCH_HAS_IMX_GPT
+	select HW_HAS_PCI
 
 config ARCH_IMX8MQ
 	bool
drivers/pci/Kconfig +2 -2
index 1c45a1c225..d81afb3d29 100644
@@ -41,8 +41,8 @@ config PCI_TEGRA
 	select PCI
 
 config PCI_IMX6
-	bool "Freescale i.MX6 PCIe controller"
-	depends on ARCH_IMX6
+	bool "Freescale i.MX6/7 PCIe controller"
+	depends on ARCH_IMX6 || ARCH_IMX7
 	select PCIE_DW
 	select OF_PCI
 	select PCI
drivers/pci/pci-imx6.c +122 -44

245 lines not on this page · raw message

Signature · 7 lines
2.20.1


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#15 lore raw

PATCH v2 15/18 PCI: imx6: Do not switch speed if Gen2 is disabled

In reply to Andrey Smirnov

Port of a Linux commit 93b226f9c65a951a91617f87ba1f05f14e59f26f

Save a bit of time and avoid going through link speed change procedure in configuration where link max speed is limited to Gen1 in DT.

---
 drivers/pci/pci-imx6.c | 55 +++++++++++++++++++++---------------------
 1 file changed, 28 insertions(+), 27 deletions(-)
drivers/pci/pci-imx6.c +28 -27
index d121a20ce1..6bdc9465db 100644
@@ -496,41 +496,42 @@ static int imx6_pcie_establish_link(struct imx6_pcie *imx6_pcie)
 		tmp &= ~PCIE_RC_LCR_MAX_LINK_SPEEDS_MASK;
 		tmp |= PCIE_RC_LCR_MAX_LINK_SPEEDS_GEN2;
 		dw_pcie_writel_dbi(pci, PCIE_RC_LCR, tmp);
-	} else {
-		dev_info(dev, "Link: Gen2 disabled\n");
-	}
-
-	/*
-	 * Start Directed Speed Change so the best possible speed both link
-	 * partners support can be negotiated.
-	 */
-	tmp = dw_pcie_readl_dbi(pci, PCIE_LINK_WIDTH_SPEED_CONTROL);
-	tmp |= PORT_LOGIC_SPEED_CHANGE;
-	dw_pcie_writel_dbi(pci, PCIE_LINK_WIDTH_SPEED_CONTROL, tmp);
 
-	if (imx6_pcie->variant != IMX7D) {
 		/*
-		 * On i.MX7, DIRECT_SPEED_CHANGE behaves differently
-		 * from i.MX6 family when no link speed transition
-		 * occurs and we go Gen1 -> yep, Gen1. The difference
-		 * is that, in such case, it will not be cleared by HW
-		 * which will cause the following code to report false
-		 * failure.
+		 * Start Directed Speed Change so the best possible
+		 * speed both link partners support can be negotiated.
 		 */
+		tmp = dw_pcie_readl_dbi(pci, PCIE_LINK_WIDTH_SPEED_CONTROL);
+		tmp |= PORT_LOGIC_SPEED_CHANGE;
+		dw_pcie_writel_dbi(pci, PCIE_LINK_WIDTH_SPEED_CONTROL, tmp);
+
+		if (imx6_pcie->variant != IMX7D) {
+			/*
+			 * On i.MX7, DIRECT_SPEED_CHANGE behaves
+			 * differently from i.MX6 family when no link
+			 * speed transition occurs and we go Gen1 ->
+			 * yep, Gen1. The difference is that, in such
+			 * case, it will not be cleared by HW which
+			 * will cause the following code to report
+			 * false failure.
+			 */
+
+			ret = imx6_pcie_wait_for_speed_change(imx6_pcie);
+			if (ret) {
+				dev_err(dev, "Failed to bring link up!\n");
+				goto err_reset_phy;
+			}
+		}
 
-		ret = imx6_pcie_wait_for_speed_change(imx6_pcie);
+		/* Make sure link training is finished as well! */
+		ret = imx6_pcie_wait_for_link(imx6_pcie);
 		if (ret) {
 			dev_err(dev, "Failed to bring link up!\n");
 			goto err_reset_phy;
 		}
-	}
-
-	/* Make sure link training is finished as well! */
-	ret = imx6_pcie_wait_for_link(imx6_pcie);
-	if (ret) {
-		dev_err(dev, "Failed to bring link up!\n");
-		goto err_reset_phy;
-	}
+	} else {
+		dev_info(dev, "Link: Gen2 disabled\n");
+        }
 
 	tmp = dw_pcie_readl_dbi(pci, PCIE_RC_LCSR);
 	dev_info(dev, "Link up, Gen%i\n", (tmp >> 16) & 0xf);
Signature · 7 lines
2.20.1


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#16 lore raw

PATCH v2 16/18 PCI: imx6: Fix spelling mistake: "contol" -> "control"

In reply to Andrey Smirnov

Port of a Linux commit 7221547e55b7929e4d46983f6f3ca15f36ee4dac

Trivial fix to spelling mistake in dev_err message

---
 drivers/pci/pci-imx6.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/pci/pci-imx6.c +2 -2
index 6bdc9465db..9f3c9b69a5 100644
@@ -655,13 +655,13 @@ static int imx6_pcie_probe(struct device_d *dev)
 
 		imx6_pcie->pciephy_reset = reset_control_get(dev, "pciephy");
 		if (IS_ERR(imx6_pcie->pciephy_reset)) {
-			dev_err(dev, "Failed to get PCIEPHY reset contol\n");
+			dev_err(dev, "Failed to get PCIEPHY reset control\n");
 			return PTR_ERR(imx6_pcie->pciephy_reset);
 		}
 
 		imx6_pcie->apps_reset = reset_control_get(dev, "apps");
 		if (IS_ERR(imx6_pcie->apps_reset)) {
-			dev_err(dev, "Failed to get PCIE APPS reset contol\n");
+			dev_err(dev, "Failed to get PCIE APPS reset control\n");
 			return PTR_ERR(imx6_pcie->apps_reset);
 		}
 		break;
Signature · 7 lines
2.20.1


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#17 lore raw

PATCH v2 17/18 PCI: imx6: Drop unnecessary root_bus_nr setting

In reply to Andrey Smirnov

Port of a Linux commit 39f712e989c5e591c58b65b62981b85027ba3103

Function dw_pcie_host_init() already initializes the root_bus_nr field of 'struct pcie_port', so the -1 assignment prior to calling dw_pcie_host_init() in platform specific driver is not really needed. Drop it.

---
 drivers/pci/pci-imx6.c | 1 -
 1 file changed, 1 deletion(-)
drivers/pci/pci-imx6.c +0 -1
index 9f3c9b69a5..9aa307aabf 100644
@@ -581,7 +581,6 @@ static int imx6_add_pcie_port(struct imx6_pcie *imx6_pcie,
 	struct pcie_port *pp = &pci->pp;
 	int ret;
 
-	pp->root_bus_nr = -1;
 	pp->ops = &imx6_pcie_host_ops;
 
 	ret = dw_pcie_host_init(pp);
Signature · 7 lines
2.20.1


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#18 lore raw

PATCH v2 18/18 PCI: imx6: Port imx6_pcie_ltssm_enable()

In reply to Andrey Smirnov

Port imx6_pcie_ltssm_enable() from Linux kernel driver.

---
 drivers/pci/pci-imx6.c | 27 ++++++++++++++++++---------
 1 file changed, 18 insertions(+), 9 deletions(-)
drivers/pci/pci-imx6.c +18 -9
index 9aa307aabf..c1719093be 100644
@@ -457,6 +457,23 @@ static int imx6_pcie_wait_for_speed_change(struct imx6_pcie *imx6_pcie)
 	return -EINVAL;
 }
 
+static void imx6_pcie_ltssm_enable(struct device_d *dev)
+{
+	struct imx6_pcie *imx6_pcie = dev->priv;
+	u32 gpr12;
+
+	switch (imx6_pcie->variant) {
+	case IMX6Q:
+	case IMX6QP:
+		gpr12 = readl(imx6_pcie->iomuxc_gpr + IOMUXC_GPR12);
+		gpr12 |= IMX6Q_GPR12_PCIE_CTL_2;
+		writel(gpr12, imx6_pcie->iomuxc_gpr + IOMUXC_GPR12);
+		break;
+	case IMX7D:
+		reset_control_deassert(imx6_pcie->apps_reset);
+		break;
+	}
+}
 
 static int imx6_pcie_establish_link(struct imx6_pcie *imx6_pcie)
 {
@@ -464,7 +481,6 @@ static int imx6_pcie_establish_link(struct imx6_pcie *imx6_pcie)
 	struct device_d *dev = pci->dev;
 	uint32_t tmp;
 	int ret;
-	u32 gpr12;
 
 	/*
 	 * Force Gen1 operation when starting the link.  In case the link is
@@ -476,14 +492,7 @@ static int imx6_pcie_establish_link(struct imx6_pcie *imx6_pcie)
 	tmp |= PCIE_RC_LCR_MAX_LINK_SPEEDS_GEN1;
 	dw_pcie_writel_dbi(pci, PCIE_RC_LCR, tmp);
 
-	/* Start LTSSM. */
-	if (imx6_pcie->variant == IMX7D) {
-		reset_control_deassert(imx6_pcie->apps_reset);
-	} else {
-		gpr12 = readl(imx6_pcie->iomuxc_gpr + IOMUXC_GPR12);
-		gpr12 |= IMX6Q_GPR12_PCIE_CTL_2;
-		writel(gpr12, imx6_pcie->iomuxc_gpr + IOMUXC_GPR12);
-	}
+	imx6_pcie_ltssm_enable(dev);
 
 	ret = imx6_pcie_wait_for_link(imx6_pcie);
 	if (ret)
Signature · 7 lines
2.20.1


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#19 lore raw
In reply to Andrey Smirnov

Hi Andrey.

Quoted 1 line

Feedback is welcome!

I have looked through the patches - and nothing jumped at me. A few places could use a newline but not worth a re-spin.

I personal dislike filenames like "helpers.c" but thats pure bikeshedding.

Looks good with the simple regulator support, which most likely will prove useful later also for other drivers.
I hope we do not need deferred probe much...

With deferred probe ported from the kernel, I wonder how far we are from porting the devm_* functionlity too. Not the I think this will share code with deferred probe, just that this is another nice kernel idiom we could benefit from in barebox.

Sam

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox

#20 lore raw
Quoted 10 lines · Sam Ravnborg

Hi Andrey.

Quoted 1 line

Feedback is welcome!

I have looked through the patches - and nothing jumped at me. A few places could use a newline but not worth a re-spin.

I personal dislike filenames like "helpers.c" but thats pure bikeshedding.

One of my goals was to keep things as close to how they are in Linux as possible. That's how that file is called there, so you might have to take it with Mark Brown if you want to change that.

Quoted 10 lines

Looks good with the simple regulator support, which most likely will prove useful later also for other drivers.
I hope we do not need deferred probe much...

With deferred probe ported from the kernel, I wonder how far we are from porting the devm_* functionlity too. Not the I think this will share code with deferred probe, just that this is another nice kernel idiom we could benefit from in barebox.

Just to clarify, deferred probe was already a part of Barebox for a while, the patches in this series only change the fact that Barebox core now has a chance to "give up" on deferred device and declare it as non-existent.

As for devm_* functions, not far at all. I don't think it would be difficult to port and I've been meaning to do that for a while, just never had an opportunity to do it so far.

Thanks,
Andrey Smirnov

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox

#21 lore raw

Hi Andrey.

Quoted 6 lines · Andrey Smirnov
Quoted 5 lines · Sam Ravnborg

Hi Andrey.

Quoted 1 line

Feedback is welcome!

Quoted 8 lines
Quoted 5 lines

I have looked through the patches - and nothing jumped at me. A few places could use a newline but not worth a re-spin.

I personal dislike filenames like "helpers.c" but thats pure bikeshedding.

One of my goals was to keep things as close to how they are in Linux as possible. That's how that file is called there,

OK, and agreee on that.
Thanks for the explanation.

Quoted 11 lines
Quoted 10 lines

Looks good with the simple regulator support, which most likely will prove useful later also for other drivers.
I hope we do not need deferred probe much...

With deferred probe ported from the kernel, I wonder how far we are from porting the devm_* functionlity too. Not the I think this will share code with deferred probe, just that this is another nice kernel idiom we could benefit from in barebox.

Quoted 8 lines

Just to clarify, deferred probe was already a part of Barebox for a while, the patches in this series only change the fact that Barebox core now has a chance to "give up" on deferred device and declare it as non-existent.

As for devm_* functions, not far at all. I don't think it would be difficult to port and I've been meaning to do that for a while, just never had an opportunity to do it so far.

Looks forward for the patches if you find the reason to do it.

Sam

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox

maintainer
#22 lore raw
In reply to Andrey Smirnov
Quoted 27 lines · Andrey Smirnov
Quoted 10 lines · Sam Ravnborg

Hi Andrey.

Quoted 1 line

Feedback is welcome!

I have looked through the patches - and nothing jumped at me. A few places could use a newline but not worth a re-spin.

I personal dislike filenames like "helpers.c" but thats pure bikeshedding.

One of my goals was to keep things as close to how they are in Linux as possible. That's how that file is called there, so you might have to take it with Mark Brown if you want to change that.

Quoted 10 lines

Looks good with the simple regulator support, which most likely will prove useful later also for other drivers.
I hope we do not need deferred probe much...

With deferred probe ported from the kernel, I wonder how far we are from porting the devm_* functionlity too. Not the I think this will share code with deferred probe, just that this is another nice kernel idiom we could benefit from in barebox.

Quoted 8 lines

Just to clarify, deferred probe was already a part of Barebox for a while, the patches in this series only change the fact that Barebox core now has a chance to "give up" on deferred device and declare it as non-existent.

As for devm_* functions, not far at all. I don't think it would be difficult to port and I've been meaning to do that for a while, just never had an opportunity to do it so far.

There's another idea I'd like to explore before we go deeper into probe deferral.

Whenever a framework needs a device probed from some device tree node it could call a of_ensure_probed(struct device_node *np) function. This function would then go back into the driver core and probe the device behind this device node.

This would require some restructuring of the driver core, like for example all devices and drivers have to be registered before they are actually probed. This of course goes against non device tree based builds which have a hand crafted initcall order to resolve dependencies.

Maybe this is a crazy idea, but at least I'd like to know why this doesn't work ;)

Sascha

Signature · 9 lines
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#23 lore raw
Quoted 46 lines · Sascha Hauer
Quoted 27 lines · Andrey Smirnov
Quoted 10 lines · Sam Ravnborg

Hi Andrey.

Quoted 1 line

Feedback is welcome!

I have looked through the patches - and nothing jumped at me. A few places could use a newline but not worth a re-spin.

I personal dislike filenames like "helpers.c" but thats pure bikeshedding.

One of my goals was to keep things as close to how they are in Linux as possible. That's how that file is called there, so you might have to take it with Mark Brown if you want to change that.

Quoted 10 lines

Looks good with the simple regulator support, which most likely will prove useful later also for other drivers.
I hope we do not need deferred probe much...

With deferred probe ported from the kernel, I wonder how far we are from porting the devm_* functionlity too. Not the I think this will share code with deferred probe, just that this is another nice kernel idiom we could benefit from in barebox.

Quoted 8 lines

Just to clarify, deferred probe was already a part of Barebox for a while, the patches in this series only change the fact that Barebox core now has a chance to "give up" on deferred device and declare it as non-existent.

As for devm_* functions, not far at all. I don't think it would be difficult to port and I've been meaning to do that for a while, just never had an opportunity to do it so far.

There's another idea I'd like to explore before we go deeper into probe deferral.

Whenever a framework needs a device probed from some device tree node it could call a of_ensure_probed(struct device_node *np) function. This function would then go back into the driver core and probe the device behind this device node.

Quoted 8 lines

This would require some restructuring of the driver core, like for example all devices and drivers have to be registered before they are actually probed. This of course goes against non device tree based builds which have a hand crafted initcall order to resolve dependencies.

Maybe this is a crazy idea, but at least I'd like to know why this doesn't work ;)

I'd rather not spend any more time on this topic. Driver_deferred_probe_check_state() is not a hard requirement and there's a way to make the series work without it. Given the pushback against it, I'll drop it in v3 and adjust the rest of the code.

Thanks,
Andrey Smirnov

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox