Skip to contentSkip to conversation

OMAP: Move SATA to use block driver model

PATCH New Jean-Jacques Hiblot 3 participants 18 messages Apr 14, 2017 – Apr 19, 2017

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

cover OMAP: Move SATA to use block driver model

This series adds support for SATA using the driver model on omap platforms. It is based on the work of Mugunthan V N <[email protected]> in Feb 2016

The first 2 patches are preparatory work.
The 3rd patch adds a new framework to handle PHYs in a generic manner. The idea is to move the phy initialization out of the board-specific code into a proper driver. The link between the phy device and the controller device is done in by device-tree as it's done in linux. The API to control a phy has been copied from linux, excpet that the functions are prefixed by 'generic_phy_' instead of just 'phy_' because phy_reset() is already used to handle the Ethernet phys. The 5th patch adds a phy driver for the pipe3 sata phy found in the omaps/am5x/dra7x SOCs.
The 6th patch allows the device under the node ocp2scp at 4a090000 to be probed. The 7th patch implements a driver for the SATA controller found in the omaps/am5x/dra7x SOCs.
The 8th patch is cosmetic and changes the interface of scsi_detect_dev() The 9th patch moves the call to part_init() out of scsi_detect_dev(). This is a preparatory work path #10.
The 10th patches fix a divide-by-0 error that happens in scsi_scan() when DM is used and split scsi_scan() in 2 functions for clarity. The last patch enables the DM sata by default for the dra7 platforms.

changes since v2:
* Added unit tests for generic PHY uclass.
* Changed the generic phy API to use a 'struct udevice*' to reference the phy device.
* Don't modify anymore the root Makefile.
* Updated the Kconfig with more details on the PHY framework.
* Use a Unique Lincense Identifier (SPDX)
* Use omap5-u-boot.dtsi to mark the ocp2scp bus as compatible with "simple-bus"
* Split scsi_scan() in 2 for clarity. The function was becoming too long.

changes since v1:
* changed the way the 'old' sata code is compiled out when DM_SCSI is enabled.
* added a new framework for PHY management.
* added a new driver for the PIPE3 phy and use it in the dwc_ahci driver.
* changed the interface of scsi_detect_dev() and moved the call part_init() out of it.
* modified the fix to scsi_scan() in order to call scsi_detect_dev() only once.
* the max_lun and max_id parameters are now taken from the device-tree.
* Updated the defconfig changes to include the PHY driver and its dependencies.

Jean-Jacques Hiblot (11):
arm: omap: sata: move enable sata clocks to enable_basic_clocks()
arm: omap: sata: compile out board-level sata code when CONFIG_DM_SCSI
is defined
drivers: phy: add generic PHY framework
dm: test: Add tests for the generic PHY uclass
drivers: phy: add PIPE3 phy driver
dra7: dtsi: mark ocp2scp bus compatible with "simple-bus"
drivers: block: dwc_ahci: Implement a driver for Synopsys DWC sata
device
scsi: make the LUN a parameter of scsi_detect_dev()
scsi: move the partition initialization out of the scsi detection
dm: scsi: fix divide-by-0 error in scsi_scan()
defconfig: dra7xx_evm: enable CONFIG_BLK and disk driver model for
SCSI

 arch/arm/dts/omap5-u-boot.dtsi      |   4 +
 arch/arm/mach-omap2/Makefile        |   2 +
 arch/arm/mach-omap2/omap5/hw_data.c |  12 ++
 arch/arm/mach-omap2/sata.c          |  23 ---
 arch/sandbox/dts/test.dts           |   9 +
 common/scsi.c                       |  98 +++++-----
 configs/dra7xx_evm_defconfig        |  12 +-
 configs/dra7xx_hs_evm_defconfig     |  11 +-
 configs/sandbox_defconfig           |   2 +
 configs/sandbox_noblk_defconfig     |   2 +
 configs/sandbox_spl_defconfig       |   3 +
 drivers/Kconfig                     |   2 +
 drivers/Makefile                    |   1 +
 drivers/block/Kconfig               |  10 +
 drivers/block/Makefile              |   1 +
 drivers/block/dwc_ahci.c            | 100 ++++++++++
 drivers/phy/Kconfig                 |  59 ++++++
 drivers/phy/Makefile                |   4 +
 drivers/phy/phy-uclass.c            |  64 +++++++
 drivers/phy/sandbox-phy.c           |  78 ++++++++
 drivers/phy/ti-pipe3-phy.c          | 365 ++++++++++++++++++++++++++++++++++++
 include/dm/uclass-id.h              |   1 +
 include/generic-phy.h               |  36 ++++
 test/dm/Makefile                    |   1 +
 test/dm/generic_phy.c               |  89 +++++++++
 25 files changed, 922 insertions(+), 67 deletions(-)
 create mode 100644 drivers/block/dwc_ahci.c
 create mode 100644 drivers/phy/Kconfig
 create mode 100644 drivers/phy/Makefile
 create mode 100644 drivers/phy/phy-uclass.c
 create mode 100644 drivers/phy/sandbox-phy.c
 create mode 100644 drivers/phy/ti-pipe3-phy.c
 create mode 100644 include/generic-phy.h
 create mode 100644 test/dm/generic_phy.c
Signature · 1 line
1.9.1
#1 lore raw

PATCH 1/11 arm: omap: sata: move enable sata clocks to enable_basic_clocks()

All the clocks which has to be enabled has to be done in enable_basic_clocks(), so moving enable sata clock to common clocks enable function.

---
 arch/arm/mach-omap2/omap5/hw_data.c | 12 ++++++++++++
 arch/arm/mach-omap2/sata.c          | 23 -----------------------
 2 files changed, 12 insertions(+), 23 deletions(-)
arch/arm/mach-omap2/omap5/hw_data.c +12 -0
index 5d956b5..a8a6b8a 100644
@@ -361,6 +361,9 @@ void enable_basic_clocks(void)
 		(*prcm)->cm_l4per_gpio6_clkctrl,
 		(*prcm)->cm_l4per_gpio7_clkctrl,
 		(*prcm)->cm_l4per_gpio8_clkctrl,
+#ifdef CONFIG_SCSI_AHCI_PLAT
+		(*prcm)->cm_l3init_ocp2scp3_clkctrl,
+#endif
 		0
 	};
 
@@ -379,6 +382,9 @@ void enable_basic_clocks(void)
 #ifdef CONFIG_TI_QSPI
 		(*prcm)->cm_l4per_qspi_clkctrl,
 #endif
+#ifdef CONFIG_SCSI_AHCI_PLAT
+		(*prcm)->cm_l3init_sata_clkctrl,
+#endif
 		0
 	};
 
@@ -411,6 +417,12 @@ void enable_basic_clocks(void)
 	setbits_le32((*prcm)->cm_l4per_qspi_clkctrl, (1<<24));
 #endif
 
+#ifdef CONFIG_SCSI_AHCI_PLAT
+	/* Enable optional functional clock for SATA */
+	setbits_le32((*prcm)->cm_l3init_sata_clkctrl,
+		     SATA_CLKCTRL_OPTFCLKEN_MASK);
+#endif
+
 	/* Enable SCRM OPT clocks for PER and CORE dpll */
 	setbits_le32((*prcm)->cm_wkupaon_scrm_clkctrl,
 			OPTFCLKEN_SCRM_PER_MASK);
arch/arm/mach-omap2/sata.c +0 -23
index 2c2d1bc..0c82689 100644
@@ -37,29 +37,6 @@ int init_sata(int dev)
 	int ret;
 	u32 val;
 
-	u32 const clk_domains_sata[] = {
-		0
-	};
-
-	u32 const clk_modules_hw_auto_sata[] = {
-		(*prcm)->cm_l3init_ocp2scp3_clkctrl,
-		0
-	};
-
-	u32 const clk_modules_explicit_en_sata[] = {
-		(*prcm)->cm_l3init_sata_clkctrl,
-		0
-	};
-
-	do_enable_clocks(clk_domains_sata,
-			 clk_modules_hw_auto_sata,
-			 clk_modules_explicit_en_sata,
-			 0);
-
-	/* Enable optional functional clock for SATA */
-	setbits_le32((*prcm)->cm_l3init_sata_clkctrl,
-		     SATA_CLKCTRL_OPTFCLKEN_MASK);
-
 	sata_phy.power_reg = (void __iomem *)(*ctrl)->control_phy_power_sata;
 
 	/* Power up the PHY */
Signature · 1 line
1.9.1
#2 lore raw

PATCH 2/11 arm: omap: sata: compile out board-level sata code when CONFIG_DM_SCSI is defined

In reply to Jean-Jacques Hiblot

When CONFIG_DM_SCSI is defined, the SATA initialization will be implemented in the scsi-uclass driver.

---
 arch/arm/mach-omap2/Makefile | 2 ++
 1 file changed, 2 insertions(+)
arch/arm/mach-omap2/Makefile +2 -0
index e814eb0..aa3986d 100644
@@ -29,9 +29,11 @@ obj-y	+= abb.o
 endif
 
 ifneq ($(CONFIG_OMAP54XX),)
+ifeq ($(CONFIG_DM_SCSI),)
 obj-y	+= pipe3-phy.o
 obj-$(CONFIG_SCSI_AHCI_PLAT) += sata.o
 endif
+endif
 
 ifeq ($(CONFIG_SYS_DCACHE_OFF),)
 obj-y	+= omap-cache.o
Signature · 1 line
1.9.1
#3 lore raw

PATCH 3/11 drivers: phy: add generic PHY framework

In reply to Jean-Jacques Hiblot

The PHY framework provides a set of APIs to control a PHY. This API is derived from the linux version of the generic PHY framework. Currently the API supports init(), deinit(), power_on, power_off() and reset(). The framework provides a way to get a reference to a phy from the device-tree.

---
 drivers/Kconfig          |  2 ++
 drivers/Makefile         |  1 +
 drivers/phy/Kconfig      | 32 ++++++++++++++++++++++++
 drivers/phy/Makefile     |  2 ++
 drivers/phy/phy-uclass.c | 64 ++++++++++++++++++++++++++++++++++++++++++++++++
 include/dm/uclass-id.h   |  1 +
 include/generic-phy.h    | 36 +++++++++++++++++++++++++++
 7 files changed, 138 insertions(+)
 create mode 100644 drivers/phy/Kconfig
 create mode 100644 drivers/phy/Makefile
 create mode 100644 drivers/phy/phy-uclass.c
 create mode 100644 include/generic-phy.h
drivers/Kconfig +2 -0
index 0e5d97d..a90ceca 100644
@@ -88,6 +88,8 @@ source "drivers/video/Kconfig"
 
 source "drivers/watchdog/Kconfig"
 
+source "drivers/phy/Kconfig"
+
 config PHYS_TO_BUS
 	bool "Custom physical to bus address mapping"
 	help
drivers/Makefile +1 -0
index 5d8baa5..0be0624 100644
@@ -7,6 +7,7 @@ obj-$(CONFIG_$(SPL_)CLK)	+= clk/
 obj-$(CONFIG_$(SPL_)LED)	+= led/
 obj-$(CONFIG_$(SPL_)PINCTRL)	+= pinctrl/
 obj-$(CONFIG_$(SPL_)RAM)	+= ram/
+obj-$(CONFIG_$(SPL_)GENERIC_PHY) += phy/
 
 ifdef CONFIG_SPL_BUILD
 
drivers/phy/Kconfig new file +32 -0
new file mode 100644
index 0000000..d66c9e3
@@ -0,0 +1,32 @@
+
+menu "PHY Subsystem"
+
+config GENERIC_PHY
+	bool "PHY Core"
+	depends on DM
+	help
+	  Generic PHY support.
+
+	  This framework is designed to provide a generic interface for PHY
+	  devices. PHYs are commonly used for high speed interfaces such as
+	  SATA or PCIe.
+	  The API provides functions to initialize/deinitialize the
+	  phy, power on/off the phy, and reset the phy. It's meant to be as
+	  compatible as possible with the equivalent framework found in the
+	  linux kernel.
+
+config SPL_GENERIC_PHY
+	bool "PHY Core in SPL"
+	depends on DM
+	help
+	  Generic PHY support in SPL.
+
+	  This framework is designed to provide a generic interface for PHY
+	  devices. PHYs are commonly used for high speed interfaces such as
+	  SATA or PCIe.
+	  The API provides functions to initialize/deinitialize the
+	  phy, power on/off the phy, and reset the phy. It's meant to be as
+	  compatible as possible with the equivalent framework found in the
+	  linux kernel.
+
+endmenu
drivers/phy/Makefile new file +2 -0
new file mode 100644
index 0000000..b29a8b9
@@ -0,0 +1,2 @@
+obj-$(CONFIG_$(SPL_)GENERIC_PHY) += phy-uclass.o
+
drivers/phy/phy-uclass.c new file +64 -0

64 lines not on this page · raw message

include/dm/uclass-id.h +1 -0
index 8c92d0b..9d34a32 100644
@@ -83,6 +83,7 @@ enum uclass_id {
 	UCLASS_VIDEO,		/* Video or LCD device */
 	UCLASS_VIDEO_BRIDGE,	/* Video bridge, e.g. DisplayPort to LVDS */
 	UCLASS_VIDEO_CONSOLE,	/* Text console driver for video device */
+	UCLASS_PHY,		/* generic PHY device */
 
 	UCLASS_COUNT,
 	UCLASS_INVALID = -1,
include/generic-phy.h new file +36 -0
new file mode 100644
index 0000000..24475f0
@@ -0,0 +1,36 @@
+/*
+ * Copyright (C) 2017 Texas Instruments Incorporated - http://www.ti.com/
+ * Written by Jean-Jacques Hiblot  <[email protected]>
+ *
+ * SPDX-License-Identifier:	GPL-2.0+
+ */
+
+#ifndef __GENERIC_PHY_H
+#define __GENERIC_PHY_H
+
+/*
+ * struct udevice_ops - set of function pointers for phy operations
+ * @init: operation to be performed for initializing phy (optionnal)
+ * @exit: operation to be performed while exiting (optionnal)
+ * @reset: reset the phy (optionnal).
+ * @power_on: powering on the phy (optionnal)
+ * @power_off: powering off the phy (optionnal)
+ */
+struct generic_phy_ops {
+	int	(*init)(struct udevice *phy);
+	int	(*exit)(struct udevice *phy);
+	int	(*reset)(struct udevice *phy);
+	int	(*power_on)(struct udevice *phy);
+	int	(*power_off)(struct udevice *phy);
+};
+
+
+int generic_phy_init(struct udevice *phy);
+int generic_phy_reset(struct udevice *phy);
+int generic_phy_exit(struct udevice *phy);
+int generic_phy_power_on(struct udevice *phy);
+int generic_phy_power_off(struct udevice *phy);
+
+struct udevice *dm_generic_phy_get(struct udevice *parent, const char *string);
+
+#endif /*__GENERIC_PHY_H */
Signature · 1 line
1.9.1
#4 lore raw

PATCH 3/11 drivers: phy: add generic PHY framework

Hi Jean-Jacques,

Quoted 7 lines · Jean-Jacques Hiblot

The PHY framework provides a set of APIs to control a PHY. This API is derived from the linux version of the generic PHY framework. Currently the API supports init(), deinit(), power_on, power_off() and reset(). The framework provides a way to get a reference to a phy from the device-tree.

Quoted 13 lines
---
 drivers/Kconfig          |  2 ++
 drivers/Makefile         |  1 +
 drivers/phy/Kconfig      | 32 ++++++++++++++++++++++++
 drivers/phy/Makefile     |  2 ++
 drivers/phy/phy-uclass.c | 64 ++++++++++++++++++++++++++++++++++++++++++++++++
 include/dm/uclass-id.h   |  1 +
 include/generic-phy.h    | 36 +++++++++++++++++++++++++++
 7 files changed, 138 insertions(+)
 create mode 100644 drivers/phy/Kconfig
 create mode 100644 drivers/phy/Makefile
 create mode 100644 drivers/phy/phy-uclass.c
 create mode 100644 include/generic-phy.h

I mostly have minor things at this point. Note that I've applied the patches from your series that I can, so please rebase on master.

Also can you please:
- check your version number (I think you might be up to v3 now)
- include a change log with each patch (patman might help you)
- rebase on u-boot-dm/master

I'm sorry if this comes across as a bit pedantic. But you are creating a new uclass which I think will be quite important in U-Boot. I suspect it will be used by USB, perhaps Ethernet and other systems, so careful design and documentation is pretty important.

Quoted 19 lines
drivers/Kconfig +2 -0
index 0e5d97d..a90ceca 100644
@@ -88,6 +88,8 @@ source "drivers/video/Kconfig"
 
 source "drivers/watchdog/Kconfig"
 
+source "drivers/phy/Kconfig"
+
 config PHYS_TO_BUS
        bool "Custom physical to bus address mapping"
        help
drivers/Makefile +0 -0
index 5d8baa5..0be0624 100644

drivers/Makefile obj-$(CONFIG_$(SPL_)CLK) += clk/ · line 10

Quoted 4 lines
drivers/Makefile +1 -0
@@ -7,6 +7,7 @@ obj-$(CONFIG_$(SPL_)CLK)        += clk/
 obj-$(CONFIG_$(SPL_)LED)       += led/
 obj-$(CONFIG_$(SPL_)PINCTRL)   += pinctrl/
 obj-$(CONFIG_$(SPL_)RAM)       += ram/
+obj-$(CONFIG_$(SPL_)GENERIC_PHY) += phy/

Please maintain the ordering here

Quoted 9 lines
drivers/Makefile +0 -0
 ifdef CONFIG_SPL_BUILD
 
drivers/phy/Kconfig new file +0 -0
new file mode 100644
index 0000000..d66c9e3

drivers/phy/Kconfig line 10

Quoted 10 lines
drivers/phy/Kconfig new file +10 -0
@@ -0,0 +1,32 @@
+
+menu "PHY Subsystem"
+
+config GENERIC_PHY
+       bool "PHY Core"
+       depends on DM
+       help
+         Generic PHY support.
+
+         This framework is designed to provide a generic interface for PHY

PHY means?

drivers/phy/Kconfig line 12

Quoted 2 lines
drivers/phy/Kconfig new file +2 -0
+         devices. PHYs are commonly used for high speed interfaces such as
+         SATA or PCIe.

Please write out SATA and PCIe in full at least once. This is help so we should not assume much.

drivers/phy/Kconfig line 14

Quoted 2 lines
drivers/phy/Kconfig new file +2 -0
+         The API provides functions to initialize/deinitialize the
+         phy, power on/off the phy, and reset the phy. It's meant to be as

Is it PHY or phy?

Quoted 34 lines
drivers/phy/Kconfig new file +18 -0
+         compatible as possible with the equivalent framework found in the
+         linux kernel.
+
+config SPL_GENERIC_PHY
+       bool "PHY Core in SPL"
+       depends on DM
+       help
+         Generic PHY support in SPL.
+
+         This framework is designed to provide a generic interface for PHY
+         devices. PHYs are commonly used for high speed interfaces such as
+         SATA or PCIe.
+         The API provides functions to initialize/deinitialize the
+         phy, power on/off the phy, and reset the phy. It's meant to be as
+         compatible as possible with the equivalent framework found in the
+         linux kernel.
+
+endmenu
drivers/phy/Makefile new file +2 -0
new file mode 100644
index 0000000..b29a8b9
@@ -0,0 +1,2 @@
+obj-$(CONFIG_$(SPL_)GENERIC_PHY) += phy-uclass.o
+
drivers/phy/phy-uclass.c new file +2 -0
new file mode 100644
index 0000000..e15ed43
@@ -0,0 +1,64 @@
+/*
+ * Copyright (C) 2017 Texas Instruments Incorporated - http://www.ti.com/

drivers/phy/phy-uclass.c line 12

Quoted 10 lines
drivers/phy/phy-uclass.c new file +10 -0
+ * Written by Jean-Jacques Hiblot  <[email protected]>
+ *
+ * SPDX-License-Identifier:    GPL-2.0+
+ */
+
+#include <common.h>
+#include <dm.h>
+#include <generic-phy.h>
+
+struct udevice *dm_generic_phy_get(struct udevice *parent, const char *string)

Can you make this return an error code instead, and the device pointer as a parameter? This is how it is generally down in DM. See uclass_first_device() for example.

Also I think you should drop the dm_ in the name. That prefix is used for core driver model functions, and DM versions of function that have a non-DM analogue.

Also I think 'get' is too short. We normally use that for getting by index. How about generic_phy_get_by_name() or, phy_get_by_name() if you rename it?

Quoted 6 lines
drivers/phy/phy-uclass.c new file +6 -0
+{
+       struct udevice *dev;
+
+       int rc = uclass_get_device_by_phandle(UCLASS_PHY, parent,
+                                          string, &dev);
+       if (rc) {

drivers/phy/phy-uclass.c line 28

Quoted 10 lines
drivers/phy/phy-uclass.c new file +10 -0
+               debug("unable to find generic_phy device (err: %d)\n", rc);
+               return ERR_PTR(rc);
+       }
+
+       return dev;
+}
+
+int generic_phy_init(struct udevice *dev)
+{
+       struct generic_phy_ops const *ops = dev->driver->ops;

Please use a header-file macro to access ops. See clk-uclass.c for an example.

drivers/phy/phy-uclass.c line 30

Quoted 2 lines
drivers/phy/phy-uclass.c new file +2 -0
+
+       return (ops && ops->init) ? ops->init(dev) : 0;

You don't need to check ops since it is invalid not to have one. So:

return ops->init ? ops->init(dev) : 0;

Quoted 22 lines
drivers/phy/phy-uclass.c new file +22 -0
+}
+
+int generic_phy_reset(struct udevice *dev)
+{
+       struct generic_phy_ops const *ops = dev->driver->ops;
+
+       return (ops && ops->reset) ? ops->reset(dev) : 0;
+}
+
+int generic_phy_exit(struct udevice *dev)
+{
+       struct generic_phy_ops const *ops = dev->driver->ops;
+
+       return (ops && ops->exit) ? ops->exit(dev) : 0;
+}
+
+int generic_phy_power_on(struct udevice *dev)
+{
+       struct generic_phy_ops const *ops = dev->driver->ops;
+
+       return (ops && ops->power_on) ? ops->power_on(dev) : 0;
+}

drivers/phy/phy-uclass.c line 62

Quoted 10 lines
drivers/phy/phy-uclass.c new file +10 -0
+
+int generic_phy_power_off(struct udevice *dev)
+{
+       struct generic_phy_ops const *ops = dev->driver->ops;
+
+       return (ops && ops->power_off) ? ops->power_off(dev) : 0;
+}
+
+UCLASS_DRIVER(generic_phy) = {
+       .id             = UCLASS_PHY,

I would like the uclass name to match the header file and the uclass name. So if you are calling this generic_phy, then the uclass should be named this too. Same with the directory drivers/phy. If you want to rename it all to 'phy' then that is fine too.

include/dm/uclass-id.h enum uclass_id { · line 86

Quoted 11 lines
drivers/phy/phy-uclass.c new file +2 -0
+       .name           = "generic_phy",
+};
include/dm/uclass-id.h +1 -0
index 8c92d0b..9d34a32 100644
@@ -83,6 +83,7 @@ enum uclass_id {
        UCLASS_VIDEO,           /* Video or LCD device */
        UCLASS_VIDEO_BRIDGE,    /* Video bridge, e.g. DisplayPort to LVDS */
        UCLASS_VIDEO_CONSOLE,   /* Text console driver for video device */
+       UCLASS_PHY,             /* generic PHY device */

Physical layer device? Can you make your comment a bit more useful?

Quoted 12 lines
include/dm/uclass-id.h +0 -0
        UCLASS_COUNT,
        UCLASS_INVALID = -1,
include/generic-phy.h new file +3 -0
new file mode 100644
index 0000000..24475f0
@@ -0,0 +1,36 @@
+/*
+ * Copyright (C) 2017 Texas Instruments Incorporated - http://www.ti.com/
+ * Written by Jean-Jacques Hiblot  <[email protected]>

include/generic-phy.h line 13

Quoted 10 lines
include/generic-phy.h new file +10 -0
+ *
+ * SPDX-License-Identifier:    GPL-2.0+
+ */
+
+#ifndef __GENERIC_PHY_H
+#define __GENERIC_PHY_H
+
+/*
+ * struct udevice_ops - set of function pointers for phy operations
+ * @init: operation to be performed for initializing phy (optionnal)

optional

Can you please put these comments in front of each function in struct generic_phy_ops as is done with other uclasses? Your description should explain what the operation does. For example, what happens for init()? Since the phy has already been probed, what should you not do in probe() but do in init()?

include/generic-phy.h line 14

Quoted 1 line
include/generic-phy.h new file +1 -0
+ * @exit: operation to be performed while exiting (optionnal)

exiting what? Please add some more detail.

include/generic-phy.h line 17

Quoted 3 lines
include/generic-phy.h new file +3 -0
+ * @reset: reset the phy (optionnal).
+ * @power_on: powering on the phy (optionnal)
+ * @power_off: powering off the phy (optionnal)

Are these optional because the phy might be powered on during one of the other operations? Otherwise it doesn't seem helpful to have the thing not ever power on.

include/generic-phy.h line 28

Quoted 11 lines
include/generic-phy.h new file +11 -0
+ */
+struct generic_phy_ops {
+       int     (*init)(struct udevice *phy);
+       int     (*exit)(struct udevice *phy);
+       int     (*reset)(struct udevice *phy);
+       int     (*power_on)(struct udevice *phy);
+       int     (*power_off)(struct udevice *phy);
+};
+
+
+int generic_phy_init(struct udevice *phy);

Here you need to repeat your comments from above - see other uclasses for an example.

include/generic-phy.h line 34

Quoted 6 lines
include/generic-phy.h new file +6 -0
+int generic_phy_reset(struct udevice *phy);
+int generic_phy_exit(struct udevice *phy);
+int generic_phy_power_on(struct udevice *phy);
+int generic_phy_power_off(struct udevice *phy);
+
+struct udevice *dm_generic_phy_get(struct udevice *parent, const char *string);

This function need a comment. Also instead of string can you think of a descriptive name, e.g. phy_name?

Quoted 5 lines
include/generic-phy.h new file +2 -1
+
+#endif /*__GENERIC_PHY_H */
--

1.9.1

Regards,
Simon

#5 lore raw

PATCH 3/11 drivers: phy: add generic PHY framework

Quoted 197 lines · Simon Glass

Hi Jean-Jacques,

Quoted 16 lines · Jean-Jacques Hiblot

The PHY framework provides a set of APIs to control a PHY. This API is derived from the linux version of the generic PHY framework. Currently the API supports init(), deinit(), power_on, power_off() and reset(). The framework provides a way to get a reference to a phy from the device-tree.

---
  drivers/Kconfig          |  2 ++
  drivers/Makefile         |  1 +
  drivers/phy/Kconfig      | 32 ++++++++++++++++++++++++
  drivers/phy/Makefile     |  2 ++
  drivers/phy/phy-uclass.c | 64 ++++++++++++++++++++++++++++++++++++++++++++++++
  include/dm/uclass-id.h   |  1 +
  include/generic-phy.h    | 36 +++++++++++++++++++++++++++
  7 files changed, 138 insertions(+)
Quoted 4 lines

create mode 100644 drivers/phy/Kconfig
create mode 100644 drivers/phy/Makefile
create mode 100644 drivers/phy/phy-uclass.c
create mode 100644 include/generic-phy.h

I mostly have minor things at this point. Note that I've applied the patches from your series that I can, so please rebase on master.

Also can you please:
- check your version number (I think you might be up to v3 now)
- include a change log with each patch (patman might help you)
- rebase on u-boot-dm/master

I'm sorry if this comes across as a bit pedantic. But you are creating a new uclass which I think will be quite important in U-Boot. I suspect it will be used by USB, perhaps Ethernet and other systems, so careful design and documentation is pretty important.

Quoted 18 lines
drivers/Kconfig +2 -0
index 0e5d97d..a90ceca 100644
@@ -88,6 +88,8 @@ source "drivers/video/Kconfig"
 
  source "drivers/watchdog/Kconfig"
 
+source "drivers/phy/Kconfig"
+
  config PHYS_TO_BUS
         bool "Custom physical to bus address mapping"
         help
drivers/Makefile +0 -0
index 5d8baa5..0be0624 100644

drivers/Makefile obj-$(CONFIG_$(SPL_)CLK) += clk/ · line 10

Quoted 4 lines
drivers/Makefile +1 -0
@@ -7,6 +7,7 @@ obj-$(CONFIG_$(SPL_)CLK)        += clk/
  obj-$(CONFIG_$(SPL_)LED)       += led/
  obj-$(CONFIG_$(SPL_)PINCTRL)   += pinctrl/
  obj-$(CONFIG_$(SPL_)RAM)       += ram/
+obj-$(CONFIG_$(SPL_)GENERIC_PHY) += phy/

Please maintain the ordering here

Quoted 8 lines
drivers/Makefile +0 -0
  ifdef CONFIG_SPL_BUILD
 
drivers/phy/Kconfig new file +0 -0
new file mode 100644
index 0000000..d66c9e3

drivers/phy/Kconfig line 10

Quoted 10 lines
drivers/phy/Kconfig new file +10 -0
@@ -0,0 +1,32 @@
+
+menu "PHY Subsystem"
+
+config GENERIC_PHY
+       bool "PHY Core"
+       depends on DM
+       help
+         Generic PHY support.
+
+         This framework is designed to provide a generic interface for PHY

PHY means?

drivers/phy/Kconfig line 12

Quoted 2 lines
drivers/phy/Kconfig new file +2 -0
+         devices. PHYs are commonly used for high speed interfaces such as
+         SATA or PCIe.

Please write out SATA and PCIe in full at least once. This is help so we should not assume much.

drivers/phy/Kconfig line 14

Quoted 2 lines
drivers/phy/Kconfig new file +2 -0
+         The API provides functions to initialize/deinitialize the
+         phy, power on/off the phy, and reset the phy. It's meant to be as

Is it PHY or phy?

Quoted 34 lines
drivers/phy/Kconfig new file +18 -0
+         compatible as possible with the equivalent framework found in the
+         linux kernel.
+
+config SPL_GENERIC_PHY
+       bool "PHY Core in SPL"
+       depends on DM
+       help
+         Generic PHY support in SPL.
+
+         This framework is designed to provide a generic interface for PHY
+         devices. PHYs are commonly used for high speed interfaces such as
+         SATA or PCIe.
+         The API provides functions to initialize/deinitialize the
+         phy, power on/off the phy, and reset the phy. It's meant to be as
+         compatible as possible with the equivalent framework found in the
+         linux kernel.
+
+endmenu
drivers/phy/Makefile new file +2 -0
new file mode 100644
index 0000000..b29a8b9
@@ -0,0 +1,2 @@
+obj-$(CONFIG_$(SPL_)GENERIC_PHY) += phy-uclass.o
+
drivers/phy/phy-uclass.c new file +2 -0
new file mode 100644
index 0000000..e15ed43
@@ -0,0 +1,64 @@
+/*
+ * Copyright (C) 2017 Texas Instruments Incorporated - http://www.ti.com/

drivers/phy/phy-uclass.c line 12

Quoted 10 lines
drivers/phy/phy-uclass.c new file +10 -0
+ * Written by Jean-Jacques Hiblot  <[email protected]>
+ *
+ * SPDX-License-Identifier:    GPL-2.0+
+ */
+
+#include <common.h>
+#include <dm.h>
+#include <generic-phy.h>
+
+struct udevice *dm_generic_phy_get(struct udevice *parent, const char *string)

Can you make this return an error code instead, and the device pointer as a parameter? This is how it is generally down in DM. See uclass_first_device() for example.

Also I think you should drop the dm_ in the name. That prefix is used for core driver model functions, and DM versions of function that have a non-DM analogue.

Also I think 'get' is too short. We normally use that for getting by index. How about generic_phy_get_by_name() or, phy_get_by_name() if you rename it?

Quoted 6 lines
drivers/phy/phy-uclass.c new file +6 -0
+{
+       struct udevice *dev;
+
+       int rc = uclass_get_device_by_phandle(UCLASS_PHY, parent,
+                                          string, &dev);
+       if (rc) {

drivers/phy/phy-uclass.c line 28

Quoted 10 lines
drivers/phy/phy-uclass.c new file +10 -0
+               debug("unable to find generic_phy device (err: %d)\n", rc);
+               return ERR_PTR(rc);
+       }
+
+       return dev;
+}
+
+int generic_phy_init(struct udevice *dev)
+{
+       struct generic_phy_ops const *ops = dev->driver->ops;

Please use a header-file macro to access ops. See clk-uclass.c for an example.

drivers/phy/phy-uclass.c line 30

Quoted 2 lines
drivers/phy/phy-uclass.c new file +2 -0
+
+       return (ops && ops->init) ? ops->init(dev) : 0;

You don't need to check ops since it is invalid not to have one. So:

return ops->init ? ops->init(dev) : 0;

Quoted 28 lines
drivers/phy/phy-uclass.c new file +28 -0
+}
+
+int generic_phy_reset(struct udevice *dev)
+{
+       struct generic_phy_ops const *ops = dev->driver->ops;
+
+       return (ops && ops->reset) ? ops->reset(dev) : 0;
+}
+
+int generic_phy_exit(struct udevice *dev)
+{
+       struct generic_phy_ops const *ops = dev->driver->ops;
+
+       return (ops && ops->exit) ? ops->exit(dev) : 0;
+}
+
+int generic_phy_power_on(struct udevice *dev)
+{
+       struct generic_phy_ops const *ops = dev->driver->ops;
+
+       return (ops && ops->power_on) ? ops->power_on(dev) : 0;
+}
+
+int generic_phy_power_off(struct udevice *dev)
+{
+       struct generic_phy_ops const *ops = dev->driver->ops;
+
+       return (ops && ops->power_off) ? ops->power_off(dev) : 0;
Quoted 8 lines

drivers/phy/phy-uclass.c line 62

Quoted 4 lines
drivers/phy/phy-uclass.c new file +4 -0
+}
+
+UCLASS_DRIVER(generic_phy) = {
+       .id             = UCLASS_PHY,

I would like the uclass name to match the header file and the uclass name. So if you are calling this generic_phy, then the uclass should be named this too. Same with the directory drivers/phy. If you want to rename it all to 'phy' then that is fine too.

IMO 'phy' would be the best option.
Unfortunately there are already tons of functions starting with 'phy_' and they're used for the ethernet phy. So I would propose to use 'phy' everywhere except for the API where 'generic_phy_' can be used to prefix the functions.
What do you think ?

Quoted 36 lines

include/dm/uclass-id.h enum uclass_id { · line 86

Quoted 11 lines
drivers/phy/phy-uclass.c new file +2 -0
+       .name           = "generic_phy",
+};
include/dm/uclass-id.h +1 -0
index 8c92d0b..9d34a32 100644
@@ -83,6 +83,7 @@ enum uclass_id {
         UCLASS_VIDEO,           /* Video or LCD device */
         UCLASS_VIDEO_BRIDGE,    /* Video bridge, e.g. DisplayPort to LVDS */
         UCLASS_VIDEO_CONSOLE,   /* Text console driver for video device */
+       UCLASS_PHY,             /* generic PHY device */

Physical layer device? Can you make your comment a bit more useful?

Quoted 11 lines
include/dm/uclass-id.h +0 -0
         UCLASS_COUNT,
         UCLASS_INVALID = -1,
include/generic-phy.h new file +3 -0
new file mode 100644
index 0000000..24475f0
@@ -0,0 +1,36 @@
+/*
+ * Copyright (C) 2017 Texas Instruments Incorporated - http://www.ti.com/
+ * Written by Jean-Jacques Hiblot  <[email protected]>

include/generic-phy.h line 13

Quoted 10 lines
include/generic-phy.h new file +10 -0
+ *
+ * SPDX-License-Identifier:    GPL-2.0+
+ */
+
+#ifndef __GENERIC_PHY_H
+#define __GENERIC_PHY_H
+
+/*
+ * struct udevice_ops - set of function pointers for phy operations
+ * @init: operation to be performed for initializing phy (optionnal)

optional

Quoted 5 lines

Can you please put these comments in front of each function in struct generic_phy_ops as is done with other uclasses? Your description should explain what the operation does. For example, what happens for init()? Since the phy has already been probed, what should you not do in probe() but do in init()?

I'll work on documenting this. Too bad that linux also lacks this documentation.
The core idea is that probe() does not do much hardware-wise, it sets up everyting (irqs, mapping, clocks) but the actual initialization of the hardware is done in init().

Jean-Jacques

Quoted 41 lines

include/generic-phy.h line 14

Quoted 1 line
include/generic-phy.h new file +1 -0
+ * @exit: operation to be performed while exiting (optionnal)

exiting what? Please add some more detail.

include/generic-phy.h line 17

Quoted 3 lines
include/generic-phy.h new file +3 -0
+ * @reset: reset the phy (optionnal).
+ * @power_on: powering on the phy (optionnal)
+ * @power_off: powering off the phy (optionnal)

Are these optional because the phy might be powered on during one of the other operations? Otherwise it doesn't seem helpful to have the thing not ever power on.

include/generic-phy.h line 28

Quoted 11 lines
include/generic-phy.h new file +11 -0
+ */
+struct generic_phy_ops {
+       int     (*init)(struct udevice *phy);
+       int     (*exit)(struct udevice *phy);
+       int     (*reset)(struct udevice *phy);
+       int     (*power_on)(struct udevice *phy);
+       int     (*power_off)(struct udevice *phy);
+};
+
+
+int generic_phy_init(struct udevice *phy);

Here you need to repeat your comments from above - see other uclasses for an example.

include/generic-phy.h line 34

Quoted 6 lines
include/generic-phy.h new file +6 -0
+int generic_phy_reset(struct udevice *phy);
+int generic_phy_exit(struct udevice *phy);
+int generic_phy_power_on(struct udevice *phy);
+int generic_phy_power_off(struct udevice *phy);
+
+struct udevice *dm_generic_phy_get(struct udevice *parent, const char *string);

This function need a comment. Also instead of string can you think of a descriptive name, e.g. phy_name?

Quoted 5 lines
include/generic-phy.h new file +2 -1
+
+#endif /*__GENERIC_PHY_H */
--

1.9.1

Regards,
Simon

#6 lore raw

PATCH 3/11 drivers: phy: add generic PHY framework

Hi

,[..]

Quoted 8 lines
Quoted 7 lines

drivers/phy/phy-uclass.c line 62

Quoted 2 lines
drivers/phy/phy-uclass.c new file +2 -0
+UCLASS_DRIVER(generic_phy) = {
+       .id             = UCLASS_PHY,

I would like the uclass name to match the header file and the uclass name. So if you are calling this generic_phy, then the uclass should be named this too. Same with the directory drivers/phy. If you want to rename it all to 'phy' then that is fine too.

Quoted 6 lines

IMO 'phy' would be the best option.
Unfortunately there are already tons of functions starting with 'phy_' and they're used for the ethernet phy. So I would propose to use 'phy' everywhere except for the API where 'generic_phy_' can be used to prefix the functions.
What do you think ?

Sounds good. That would be easy to clean up later once Ethernet Phy is done.

Quoted 48 lines
Quoted 42 lines
Quoted 10 lines
drivers/phy/phy-uclass.c new file +2 -0
+       .name           = "generic_phy",
+};
include/dm/uclass-id.h +0 -0
index 8c92d0b..9d34a32 100644
@@ -83,6 +83,7 @@ enum uclass_id {
         UCLASS_VIDEO,           /* Video or LCD device */
         UCLASS_VIDEO_BRIDGE,    /* Video bridge, e.g. DisplayPort to
Quoted 4 lines

LVDS */
UCLASS_VIDEO_CONSOLE, /* Text console driver for video device
*/
+ UCLASS_PHY, /* generic PHY device */

Physical layer device? Can you make your comment a bit more useful?

Quoted 15 lines

UCLASS_COUNT,
UCLASS_INVALID = -1,

include/generic-phy.h new file +2 -0
new file mode 100644
index 0000000..24475f0
@@ -0,0 +1,36 @@
+/*
+ * Copyright (C) 2017 Texas Instruments Incorporated -

http://www.ti.com/
+ * Written by Jean-Jacques Hiblot <[email protected]>
+ *
+ * SPDX-License-Identifier: GPL-2.0+
+ */

include/generic-phy.h line 13

Quoted 7 lines
include/generic-phy.h new file +7 -0
+
+#ifndef __GENERIC_PHY_H
+#define __GENERIC_PHY_H
+
+/*
+ * struct udevice_ops - set of function pointers for phy operations
+ * @init: operation to be performed for initializing phy (optionnal)

optional

Quoted 5 lines

Can you please put these comments in front of each function in struct generic_phy_ops as is done with other uclasses? Your description should explain what the operation does. For example, what happens for init()? Since the phy has already been probed, what should you not do in probe() but do in init()?

Quoted 5 lines

I'll work on documenting this. Too bad that linux also lacks this documentation.
The core idea is that probe() does not do much hardware-wise, it sets up everyting (irqs, mapping, clocks) but the actual initialization of the hardware is done in init().

OK sounds good.

Regards,
Simon

#7 lore raw

PATCH 4/11 dm: test: Add tests for the generic PHY uclass

In reply to Jean-Jacques Hiblot

Those tests check:
- the ability for a phy-user to get a phy device a reference in the device-tree
- the ability to perform operations on the phy (init,deinit,on,off)
- the behavior of the uclass when optional operations are not implemented

---
 arch/sandbox/dts/test.dts       |  9 +++++
 configs/sandbox_defconfig       |  2 +
 configs/sandbox_noblk_defconfig |  2 +
 configs/sandbox_spl_defconfig   |  3 ++
 drivers/phy/Kconfig             |  9 +++++
 drivers/phy/Makefile            |  1 +
 drivers/phy/sandbox-phy.c       | 78 ++++++++++++++++++++++++++++++++++++
 test/dm/Makefile                |  1 +
 test/dm/generic_phy.c           | 89 +++++++++++++++++++++++++++++++++++++++++
 9 files changed, 194 insertions(+)
 create mode 100644 drivers/phy/sandbox-phy.c
 create mode 100644 test/dm/generic_phy.c
arch/sandbox/dts/test.dts +9 -0
index fff175d..918c899 100644
@@ -59,6 +59,15 @@
 		ping-add = <3>;
 	};
 
+	gen_phy: gen_phy {
+		compatible = "sandbox,phy";
+	};
+
+	gen_phy_user: gen_phy_user {
+		compatible = "simple-bus";
+		phy = <&gen_phy>;
+	};
+
 	some-bus {
 		#address-cells = <1>;
 		#size-cells = <0>;
configs/sandbox_defconfig +2 -0
index 7f3f5ac..42116cf 100644
@@ -164,6 +164,8 @@ CONFIG_CONSOLE_ROTATION=y
 CONFIG_CONSOLE_TRUETYPE=y
 CONFIG_CONSOLE_TRUETYPE_CANTORAONE=y
 CONFIG_VIDEO_SANDBOX_SDL=y
+CONFIG_GENERIC_PHY=y
+CONFIG_PHY_SANDBOX=y
 CONFIG_CMD_DHRYSTONE=y
 CONFIG_TPM=y
 CONFIG_LZ4=y
configs/sandbox_noblk_defconfig +2 -0
index 3f8e70d..7a5cd4b 100644
@@ -166,6 +166,8 @@ CONFIG_CONSOLE_ROTATION=y
 CONFIG_CONSOLE_TRUETYPE=y
 CONFIG_CONSOLE_TRUETYPE_CANTORAONE=y
 CONFIG_VIDEO_SANDBOX_SDL=y
+CONFIG_GENERIC_PHY=y
+CONFIG_PHY_SANDBOX=y
 CONFIG_CMD_DHRYSTONE=y
 CONFIG_TPM=y
 CONFIG_LZ4=y
configs/sandbox_spl_defconfig +3 -0
index ade6714..9b4cf39 100644
@@ -170,6 +170,9 @@ CONFIG_CONSOLE_ROTATION=y
 CONFIG_CONSOLE_TRUETYPE=y
 CONFIG_CONSOLE_TRUETYPE_CANTORAONE=y
 CONFIG_VIDEO_SANDBOX_SDL=y
+CONFIG_GENERIC_PHY=y
+CONFIG_SPL_GENERIC_PHY=y
+CONFIG_PHY_SANDBOX=y
 CONFIG_CMD_DHRYSTONE=y
 CONFIG_TPM=y
 CONFIG_LZ4=y
drivers/phy/Kconfig +9 -0
index d66c9e3..032b932 100644
@@ -29,4 +29,13 @@ config SPL_GENERIC_PHY
 	  compatible as possible with the equivalent framework found in the
 	  linux kernel.
 
+config PHY_SANDBOX
+	bool "Sandbox PHY support"
+	depends on SANDBOX
+	depends on GENERIC_PHY
+	help
+	  This select a dummy sandbox PHY driver. It used only to implement
+	  unit tests for the generic phy framework
+
+
 endmenu
drivers/phy/Makefile +1 -0
index b29a8b9..0125844 100644
@@ -1,2 +1,3 @@
 obj-$(CONFIG_$(SPL_)GENERIC_PHY) += phy-uclass.o
+obj-$(CONFIG_PHY_SANDBOX) += sandbox-phy.o
 
drivers/phy/sandbox-phy.c new file +78 -0

78 lines not on this page · raw message

test/dm/Makefile +1 -0
index 1885e17..e2b7d43 100644
@@ -41,4 +41,5 @@ obj-$(CONFIG_TIMER) += timer.o
 obj-$(CONFIG_DM_VIDEO) += video.o
 obj-$(CONFIG_ADC) += adc.o
 obj-$(CONFIG_SPMI) += spmi.o
+obj-$(CONFIG_GENERIC_PHY) += generic_phy.o
 endif
test/dm/generic_phy.c new file +89 -0

89 lines not on this page · raw message

Signature · 1 line
1.9.1
#8 lore raw

PATCH 4/11 dm: test: Add tests for the generic PHY uclass

Hi Jean-Jacques,

Quoted 7 lines · Jean-Jacques Hiblot

Those tests check:
- the ability for a phy-user to get a phy device a reference in the device-tree
- the ability to perform operations on the phy (init,deinit,on,off)
- the behavior of the uclass when optional operations are not implemented

Quoted 13 lines
---
 arch/sandbox/dts/test.dts       |  9 +++++
 configs/sandbox_defconfig       |  2 +
 configs/sandbox_noblk_defconfig |  2 +
 configs/sandbox_spl_defconfig   |  3 ++
 drivers/phy/Kconfig             |  9 +++++
 drivers/phy/Makefile            |  1 +
 drivers/phy/sandbox-phy.c       | 78 ++++++++++++++++++++++++++++++++++++
 test/dm/Makefile                |  1 +
 test/dm/generic_phy.c           | 89 +++++++++++++++++++++++++++++++++++++++++
 9 files changed, 194 insertions(+)
 create mode 100644 drivers/phy/sandbox-phy.c
 create mode 100644 test/dm/generic_phy.c

This looks really good, just some nits.

Quoted 97 lines
arch/sandbox/dts/test.dts +9 -0
index fff175d..918c899 100644
@@ -59,6 +59,15 @@
                ping-add = <3>;
        };
 
+       gen_phy: gen_phy {
+               compatible = "sandbox,phy";
+       };
+
+       gen_phy_user: gen_phy_user {
+               compatible = "simple-bus";
+               phy = <&gen_phy>;
+       };
+
        some-bus {
                #address-cells = <1>;
                #size-cells = <0>;
configs/sandbox_defconfig +2 -0
index 7f3f5ac..42116cf 100644
@@ -164,6 +164,8 @@ CONFIG_CONSOLE_ROTATION=y
 CONFIG_CONSOLE_TRUETYPE=y
 CONFIG_CONSOLE_TRUETYPE_CANTORAONE=y
 CONFIG_VIDEO_SANDBOX_SDL=y
+CONFIG_GENERIC_PHY=y
+CONFIG_PHY_SANDBOX=y
 CONFIG_CMD_DHRYSTONE=y
 CONFIG_TPM=y
 CONFIG_LZ4=y
configs/sandbox_noblk_defconfig +2 -0
index 3f8e70d..7a5cd4b 100644
@@ -166,6 +166,8 @@ CONFIG_CONSOLE_ROTATION=y
 CONFIG_CONSOLE_TRUETYPE=y
 CONFIG_CONSOLE_TRUETYPE_CANTORAONE=y
 CONFIG_VIDEO_SANDBOX_SDL=y
+CONFIG_GENERIC_PHY=y
+CONFIG_PHY_SANDBOX=y
 CONFIG_CMD_DHRYSTONE=y
 CONFIG_TPM=y
 CONFIG_LZ4=y
configs/sandbox_spl_defconfig +3 -0
index ade6714..9b4cf39 100644
@@ -170,6 +170,9 @@ CONFIG_CONSOLE_ROTATION=y
 CONFIG_CONSOLE_TRUETYPE=y
 CONFIG_CONSOLE_TRUETYPE_CANTORAONE=y
 CONFIG_VIDEO_SANDBOX_SDL=y
+CONFIG_GENERIC_PHY=y
+CONFIG_SPL_GENERIC_PHY=y
+CONFIG_PHY_SANDBOX=y
 CONFIG_CMD_DHRYSTONE=y
 CONFIG_TPM=y
 CONFIG_LZ4=y
drivers/phy/Kconfig +9 -0
index d66c9e3..032b932 100644
@@ -29,4 +29,13 @@ config SPL_GENERIC_PHY
          compatible as possible with the equivalent framework found in the
          linux kernel.
 
+config PHY_SANDBOX
+       bool "Sandbox PHY support"
+       depends on SANDBOX
+       depends on GENERIC_PHY
+       help
+         This select a dummy sandbox PHY driver. It used only to implement
+         unit tests for the generic phy framework
+
+
 endmenu
drivers/phy/Makefile +1 -0
index b29a8b9..0125844 100644
@@ -1,2 +1,3 @@
 obj-$(CONFIG_$(SPL_)GENERIC_PHY) += phy-uclass.o
+obj-$(CONFIG_PHY_SANDBOX) += sandbox-phy.o
 
drivers/phy/sandbox-phy.c new file +4 -0
new file mode 100644
index 0000000..1c60308
@@ -0,0 +1,78 @@
+/*
+ * Copyright (C) 2017 Texas Instruments Incorporated - http://www.ti.com/
+ * Written by Jean-Jacques Hiblot  <[email protected]>
+ *

drivers/phy/sandbox-phy.c line 14

Quoted 10 lines
drivers/phy/sandbox-phy.c new file +10 -0
+ * SPDX-License-Identifier:    GPL-2.0+
+ */
+
+#include <common.h>
+#include <dm.h>
+#include <generic-phy.h>
+
+struct sandbox_phy_priv {
+       int initialized;
+       int on;

bool?

drivers/phy/sandbox-phy.c line 19

Quoted 5 lines
drivers/phy/sandbox-phy.c new file +5 -0
+};
+
+static int sandbox_phy_power_on(struct udevice *dev)
+{
+       struct sandbox_phy_priv *priv = dev_get_priv(dev);

blank line between decls and rest of code

drivers/phy/sandbox-phy.c line 22

Quoted 3 lines
drivers/phy/sandbox-phy.c new file +3 -0
+       if (!priv->initialized)
+               return -EIO;
+       priv->on = 1;

blank line before return
true/false better than 0/1 I think

Quoted 61 lines
drivers/phy/sandbox-phy.c new file +56 -0
+       return 0;
+}
+
+static int sandbox_phy_power_off(struct udevice *dev)
+{
+       struct sandbox_phy_priv *priv = dev_get_priv(dev);
+       if (!priv->initialized)
+               return -EIO;
+       priv->on = 0;
+       return 0;
+}
+
+static int sandbox_phy_init(struct udevice *dev)
+{
+       struct sandbox_phy_priv *priv = dev_get_priv(dev);
+       priv->initialized = 1;
+       priv->on = 0;
+       return 0;
+}
+
+static int sandbox_phy_exit(struct udevice *dev)
+{
+       struct sandbox_phy_priv *priv = dev_get_priv(dev);
+       priv->initialized = 0;
+       priv->on = 0;
+       return 0;
+}
+
+static int sandbox_phy_probe(struct udevice *dev)
+{
+       struct sandbox_phy_priv *priv = dev_get_priv(dev);
+       priv->initialized = 0;
+       priv->on = 0;
+       return 0;
+}
+
+static struct generic_phy_ops sandbox_phy_ops = {
+       .power_on = sandbox_phy_power_on,
+       .power_off = sandbox_phy_power_off,
+       .init = sandbox_phy_init,
+       .exit = sandbox_phy_exit,
+};
+
+static const struct udevice_id sandbox_phy_ids[] = {
+       { .compatible = "sandbox,phy" },
+       { }
+};
+
+U_BOOT_DRIVER(phy_sandbox) = {
+       .name           = "phy_sandbox",
+       .id             = UCLASS_PHY,
+       .of_match       = sandbox_phy_ids,
+       .ops            = &sandbox_phy_ops,
+       .probe          = sandbox_phy_probe,
+       .priv_auto_alloc_size = sizeof(struct sandbox_phy_priv),
+};
test/dm/Makefile +0 -0
index 1885e17..e2b7d43 100644

test/dm/Makefile obj-$(CONFIG_TIMER) += timer.o · line 44

Quoted 4 lines
test/dm/Makefile +1 -0
@@ -41,4 +41,5 @@ obj-$(CONFIG_TIMER) += timer.o
 obj-$(CONFIG_DM_VIDEO) += video.o
 obj-$(CONFIG_ADC) += adc.o
 obj-$(CONFIG_SPMI) += spmi.o
+obj-$(CONFIG_GENERIC_PHY) += generic_phy.o

check ordering

Quoted 9 lines
test/dm/Makefile +0 -0
 endif
test/dm/generic_phy.c new file +2 -0
new file mode 100644
index 0000000..08b862a
@@ -0,0 +1,89 @@
+/*
+ * Copyright (C) 2017 Texas Instruments Incorporated - http://www.ti.com/

test/dm/generic_phy.c line 12

Quoted 10 lines
test/dm/generic_phy.c new file +10 -0
+ * Written by Jean-Jacques Hiblot  <[email protected]>
+ *
+ * SPDX-License-Identifier:    GPL-2.0+
+ */
+
+#include <common.h>
+#include <dm.h>
+#include <dm/test.h>
+#include <test/ut.h>
+#include <generic-phy.h>

This should go below dm.h

test/dm/generic_phy.c line 23

Quoted 11 lines
test/dm/generic_phy.c new file +11 -0
+
+DECLARE_GLOBAL_DATA_PTR;
+
+/* Base test of the phy uclass */
+static int dm_test_phy_base(struct unit_test_state *uts)
+{
+       struct udevice *dev_method1;
+       struct udevice *dev_method2;
+       struct udevice *parent;
+
+

drop extra blank ilne

test/dm/generic_phy.c line 35

Quoted 12 lines
test/dm/generic_phy.c new file +12 -0
+       /* Get the device using the phy device*/
+       ut_assertok(uclass_get_device_by_name(UCLASS_SIMPLE_BUS,
+                                             "gen_phy_user", &parent));
+       /* Get the phy device with std uclass function */
+       ut_assertok(uclass_get_device_by_name(UCLASS_PHY, "gen_phy",
+                                             &dev_method1));
+
+       /*
+        * Get the phy device from user device and compare with the one
+        * obtained with the previous method.
+        */
+       dev_method2 = dm_generic_phy_get(parent, "phy");

This should be able to use ut_assertok() once the function returns an error code.

Quoted 55 lines
test/dm/generic_phy.c new file +54 -1
+       ut_assertnonnull(dev_method2);
+       ut_assertok_ptr(dev_method2);
+       ut_asserteq_ptr(dev_method1, dev_method2);
+
+       /* Try to get a non-existing phy */
+       ut_asserteq(-ENODEV, uclass_get_device(UCLASS_PHY, 1, &dev_method2));
+       dev_method2 = dm_generic_phy_get(parent, "phy_not_existing");
+       ut_assert(IS_ERR_OR_NULL(dev_method2));
+
+       return 0;
+}
+DM_TEST(dm_test_phy_base, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
+
+/* Test of the phy uclass using the sandbox phy driver operations */
+static int dm_test_phy_ops(struct unit_test_state *uts)
+{
+       struct udevice *dev;
+       struct udevice *parent;
+
+       ut_assertok(uclass_get_device_by_name(UCLASS_SIMPLE_BUS,
+                                             "gen_phy_user", &parent));
+       dev = dm_generic_phy_get(parent, "phy");
+       ut_assertnonnull(dev);
+       ut_assertok_ptr(dev);
+
+       /* test normal operations */
+       ut_assertok(generic_phy_init(dev));
+       ut_assertok(generic_phy_power_on(dev));
+       ut_assertok(generic_phy_power_off(dev));
+
+       /*
+        * test operations after exit().
+        * The sandbox phy driver does not allow it.
+        */
+       ut_assertok(generic_phy_exit(dev));
+       ut_assert(generic_phy_power_on(dev) != 0);
+       ut_assert(generic_phy_power_off(dev) != 0);
+
+       /*
+        * test normal operations again (after re-init)
+        */
+       ut_assertok(generic_phy_init(dev));
+       ut_assertok(generic_phy_power_on(dev));
+       ut_assertok(generic_phy_power_off(dev));
+
+       /*
+        * test calling unimplemented feature.
+        * The call is expected to succeed
+        */
+       ut_assertok(generic_phy_reset(dev));
+
+       return 0;
+}
+DM_TEST(dm_test_phy_ops, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
--
Quoted 2 lines

1.9.1

Great test, thanks.

Regards,
Simon

#9 lore raw

PATCH 5/11 drivers: phy: add PIPE3 phy driver

In reply to Jean-Jacques Hiblot

This phy is found on omap platforms with sata capabilities. Except for the part related to the DM and the PHY framework, the code is basically a copy paste from arch/arm/mach-omap2/pipe3-phy.c

---
 drivers/phy/Kconfig        |  18 +++
 drivers/phy/Makefile       |   1 +
 drivers/phy/ti-pipe3-phy.c | 365 +++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 384 insertions(+)
 create mode 100644 drivers/phy/ti-pipe3-phy.c
drivers/phy/Kconfig +18 -0
index 032b932..b9a8093 100644
@@ -38,4 +38,22 @@ config PHY_SANDBOX
 	  unit tests for the generic phy framework
 
 
+config PIPE3_PHY
+	bool "Support omap's PIPE3 PHY"
+	depends on GENERIC_PHY && ARCH_OMAP2
+	help
+	  Support for the omap PIPE3 phy for sata
+
+	  This PHY is found on omap devices supporting SATA such as dra7, am57x
+	  and omap5
+
+config SPL_PIPE3_PHY
+	bool "Support omap's PIPE3 PHY in SPL"
+	depends on SPL_GENERIC_PHY && ARCH_OMAP2
+	help
+	  Support for the omap PIPE3 phy for sata in SPL
+
+	  This PHY is found on omap devices supporting SATA such as dra7, am57x
+	  and omap5
+
 endmenu
drivers/phy/Makefile +1 -0
index 0125844..701f7c8 100644
@@ -1,3 +1,4 @@
 obj-$(CONFIG_$(SPL_)GENERIC_PHY) += phy-uclass.o
 obj-$(CONFIG_PHY_SANDBOX) += sandbox-phy.o
+obj-$(CONFIG_$(SPL_)PIPE3_PHY) += ti-pipe3-phy.o
 
drivers/phy/ti-pipe3-phy.c new file +365 -0

365 lines not on this page · raw message

Signature · 1 line
1.9.1
#10 lore raw

PATCH 6/11 dra7: dtsi: mark ocp2scp bus compatible with "simple-bus"

In reply to Jean-Jacques Hiblot

This is needed to probe devices under that bus such as the SATA PHY.

---
 arch/arm/dts/omap5-u-boot.dtsi | 4 ++++
 1 file changed, 4 insertions(+)
arch/arm/dts/omap5-u-boot.dtsi +4 -0
index 6305f57..9247314 100644
@@ -10,6 +10,10 @@
 /{
 	ocp {
 		u-boot,dm-pre-reloc;
+
+		ocp2scp at 4a090000 {
+			compatible = "ti,omap-ocp2scp", "simple-bus";
+		};
 	};
 };
 
Signature · 1 line
1.9.1
#11 lore raw

PATCH 6/11 dra7: dtsi: mark ocp2scp bus compatible with "simple-bus"

Quoted 3 lines · Jean-Jacques Hiblot

This is needed to probe devices under that bus such as the SATA PHY.

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20170414/c053806e/attachment.sig>
#12 lore raw

PATCH 7/11 drivers: block: dwc_ahci: Implement a driver for Synopsys DWC sata device

In reply to Jean-Jacques Hiblot

Implement a sata driver for Synopsys DWC sata device based on U-boot driver model.

---
 drivers/block/Kconfig    |  10 +++++
 drivers/block/Makefile   |   1 +
 drivers/block/dwc_ahci.c | 100 +++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 111 insertions(+)
 create mode 100644 drivers/block/dwc_ahci.c
drivers/block/Kconfig +10 -0
index 88e66e2..b3d35bd 100644
@@ -48,4 +48,14 @@ config SATA_CEVA
 	  ZynqMP. Support up to 2 external devices. Complient with SATA 3.1 and
 	  AHCI 1.3 specifications with hot-plug detect feature.
 
+
+config DWC_AHCI
+	bool "Enable Synopsys DWC AHCI driver support"
+	select SCSI_AHCI
+	select GENERIC_PHY
+	depends on DM_SCSI
+	help
+	  Enable this driver to support Sata devices through
+	  Synopsys DWC AHCI module.
+
 endmenu
drivers/block/Makefile +1 -0
index a72feec..cffe498 100644
@@ -11,6 +11,7 @@ ifndef CONFIG_BLK
 obj-y += blk_legacy.o
 endif
 
+obj-$(CONFIG_DWC_AHCI) += dwc_ahci.o
 obj-$(CONFIG_AHCI) += ahci-uclass.o
 obj-$(CONFIG_DM_SCSI) += scsi-uclass.o
 obj-$(CONFIG_SCSI_AHCI) += ahci.o
drivers/block/dwc_ahci.c new file +100 -0

100 lines not on this page · raw message

Signature · 1 line
1.9.1
#13 lore raw

PATCH 8/11 scsi: make the LUN a parameter of scsi_detect_dev()

In reply to Jean-Jacques Hiblot

This is a cosmetic change. target and LUN have kind of the same role in this function. One of them was passed as a parameter and the other was embedded in a structure. For consistency, pass both of them as parameters.

---
 common/scsi.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)
common/scsi.c +7 -7
index fb5b407..d55ba89 100644
@@ -473,14 +473,15 @@ static void scsi_init_dev_desc(struct blk_desc *dev_desc, int devnum)
  * scsi_detect_dev - Detect scsi device
  *
  * @target: target id
+ * @lun: target lun
  * @dev_desc: block device description
  *
  * The scsi_detect_dev detects and fills a dev_desc structure when the device is
- * detected. The LUN number is taken from the struct blk_desc *dev_desc.
+ * detected.
  *
  * Return: 0 on success, error value otherwise
  */
-static int scsi_detect_dev(int target, struct blk_desc *dev_desc)
+static int scsi_detect_dev(int target, int lun, struct blk_desc *dev_desc)
 {
 	unsigned char perq, modi;
 	lbaint_t capacity;
@@ -488,7 +489,7 @@ static int scsi_detect_dev(int target, struct blk_desc *dev_desc)
 	ccb *pccb = (ccb *)&tempccb;
 
 	pccb->target = target;
-	pccb->lun = dev_desc->lun;
+	pccb->lun = lun;
 	pccb->pdata = (unsigned char *)&tempbuff;
 	pccb->datalen = 512;
 	scsi_setup_inquiry(pccb);
@@ -599,8 +600,7 @@ int scsi_scan(int mode)
 				bdesc = dev_get_uclass_platdata(bdev);
 
 				scsi_init_dev_desc_priv(bdesc);
-				bdesc->lun = lun;
-				ret = scsi_detect_dev(i, bdesc);
+				ret = scsi_detect_dev(i, lun, bdesc);
 				if (ret) {
 					device_unbind(bdev);
 					continue;
@@ -630,8 +630,8 @@ int scsi_scan(int mode)
 	scsi_max_devs = 0;
 	for (i = 0; i < CONFIG_SYS_SCSI_MAX_SCSI_ID; i++) {
 		for (lun = 0; lun < CONFIG_SYS_SCSI_MAX_LUN; lun++) {
-			scsi_dev_desc[scsi_max_devs].lun = lun;
-			ret = scsi_detect_dev(i, &scsi_dev_desc[scsi_max_devs]);
+			ret = scsi_detect_dev(i, lun,
+					      &scsi_dev_desc[scsi_max_devs]);
 			if (ret)
 				continue;
 
Signature · 1 line
1.9.1
#14 lore raw

PATCH 9/11 scsi: move the partition initialization out of the scsi detection

In reply to Jean-Jacques Hiblot

We might want to get information about the scsi device without initializing the partition.

---
 common/scsi.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
common/scsi.c +2 -1
index d55ba89..972ef338 100644
@@ -540,7 +540,6 @@ static int scsi_detect_dev(int target, int lun, struct blk_desc *dev_desc)
 	dev_desc->blksz = blksz;
 	dev_desc->log2blksz = LOG2(dev_desc->blksz);
 	dev_desc->type = perq;
-	part_init(&dev_desc[0]);
 removable:
 	return 0;
 }
@@ -605,6 +604,7 @@ int scsi_scan(int mode)
 					device_unbind(bdev);
 					continue;
 				}
+				part_init(bdesc);
 
 				if (mode == 1) {
 					printf("  Device %d: ", 0);
@@ -634,6 +634,7 @@ int scsi_scan(int mode)
 					      &scsi_dev_desc[scsi_max_devs]);
 			if (ret)
 				continue;
+			part_init(&scsi_dev_desc[scsi_max_devs]);
 
 			if (mode == 1) {
 				printf("  Device %d: ", 0);
Signature · 1 line
1.9.1
#15 lore raw

PATCH 10/11 dm: scsi: fix divide-by-0 error in scsi_scan()

In reply to Jean-Jacques Hiblot

With DM_SCSI enabled, blk_create_devicef() is called with blkz = 0, leading to a divide-by-0 exception.
scsi_detect_dev() can be used to get the required parameters (block size and number of blocks) from the drive before calling blk_create_devicef().

---
 common/scsi.c | 85 ++++++++++++++++++++++++++++++++++-------------------------
 1 file changed, 49 insertions(+), 36 deletions(-)
common/scsi.c +49 -36
index 972ef338..c456f5a 100644
@@ -549,6 +549,52 @@ removable:
  * to the user if mode = 1
  */
 #if defined(CONFIG_DM_SCSI)
+static int do_scsi_scan_one(struct udevice *dev, int id, int lun, int mode)
+{
+	int ret;
+	struct udevice *bdev;
+	struct blk_desc bd;
+	struct blk_desc *bdesc;
+	char str[10];
+
+	/*
+	 * detect the scsi driver to get information about its geometry (block
+	 * size, number of blocks) and other parameters (ids, type, ...)
+	 */
+	scsi_init_dev_desc_priv(&bd);
+	if (scsi_detect_dev(id, lun, &bd))
+		return -ENODEV;
+
+	/*
+	* Create only one block device and do detection
+	* to make sure that there won't be a lot of
+	* block devices created
+	*/
+	snprintf(str, sizeof(str), "id%dlun%d", id, lun);
+	ret = blk_create_devicef(dev, "scsi_blk", str, IF_TYPE_SCSI, -1,
+			bd.blksz, bd.blksz * bd.lba, &bdev);
+	if (ret) {
+		debug("Can't create device\n");
+		return ret;
+	}
+
+	bdesc = dev_get_uclass_platdata(bdev);
+	bdesc->target = id;
+	bdesc->lun = lun;
+	bdesc->removable = bd.removable;
+	bdesc->type = bd.type;
+	memcpy(&bdesc->vendor, &bd.vendor, sizeof(bd.vendor));
+	memcpy(&bdesc->product, &bd.product, sizeof(bd.product));
+	memcpy(&bdesc->revision, &bd.revision,	sizeof(bd.revision));
+	part_init(bdesc);
+
+	if (mode == 1) {
+		printf("  Device %d: ", 0);
+		dev_print(bdesc);
+	}
+	return 0;
+}
+
 int scsi_scan(int mode)
 {
 	unsigned char i, lun;
@@ -576,42 +622,9 @@ int scsi_scan(int mode)
 		/* Get controller platdata */
 		plat = dev_get_platdata(dev);
 
-		for (i = 0; i < plat->max_id; i++) {
-			for (lun = 0; lun < plat->max_lun; lun++) {
-				struct udevice *bdev; /* block device */
-				/* block device description */
-				struct blk_desc *bdesc;
-				char str[10];
-
-				/*
-				 * Create only one block device and do detection
-				 * to make sure that there won't be a lot of
-				 * block devices created
-				 */
-				snprintf(str, sizeof(str), "id%dlun%d", i, lun);
-				ret = blk_create_devicef(dev, "scsi_blk",
-							  str, IF_TYPE_SCSI,
-							  -1, 0, 0, &bdev);
-				if (ret) {
-					debug("Can't create device\n");
-					return ret;
-				}
-				bdesc = dev_get_uclass_platdata(bdev);
-
-				scsi_init_dev_desc_priv(bdesc);
-				ret = scsi_detect_dev(i, lun, bdesc);
-				if (ret) {
-					device_unbind(bdev);
-					continue;
-				}
-				part_init(bdesc);
-
-				if (mode == 1) {
-					printf("  Device %d: ", 0);
-					dev_print(bdesc);
-				} /* if mode */
-			} /* next LUN */
-		}
+		for (i = 0; i < plat->max_id; i++)
+			for (lun = 0; lun < plat->max_lun; lun++)
+				do_scsi_scan_one(dev, i, lun, mode);
 	}
 
 	return 0;
Signature · 1 line
1.9.1
#16 lore raw

PATCH 11/11 defconfig: dra7xx_evm: enable CONFIG_BLK and disk driver model for SCSI

In reply to Jean-Jacques Hiblot

Enable disk driver model for dra7xx_evm as dwc_ahci supports driver model. As a consequence we must also enable CONFIG_BLK and CONFIG_DM_USB.

---
 configs/dra7xx_evm_defconfig    | 12 +++++++++++-
 configs/dra7xx_hs_evm_defconfig | 11 ++++++++++-
 2 files changed, 21 insertions(+), 2 deletions(-)
configs/dra7xx_evm_defconfig +11 -1
index 42f87b3..8bc395f 100644
@@ -59,7 +59,13 @@ CONFIG_SPL_OF_CONTROL=y
 CONFIG_OF_LIST="dra7-evm dra72-evm dra72-evm-revc dra71-evm"
 CONFIG_DM=y
 CONFIG_SPL_DM=y
-# CONFIG_BLK is not set
+CONFIG_REGMAP=y
+CONFIG_SPL_REGMAP=y
+CONFIG_SYSCON=y
+CONFIG_SPL_SYSCON=y
+CONFIG_BLK=y
+CONFIG_DM_SCSI=y
+CONFIG_DWC_AHCI=y
 CONFIG_DFU_MMC=y
 CONFIG_DFU_RAM=y
 CONFIG_DFU_SF=y
@@ -89,6 +95,7 @@ CONFIG_TI_QSPI=y
 CONFIG_TIMER=y
 CONFIG_OMAP_TIMER=y
 CONFIG_USB=y
+CONFIG_DM_USB=y
 CONFIG_USB_XHCI_HCD=y
 CONFIG_USB_XHCI_DWC3=y
 CONFIG_USB_DWC3=y
@@ -101,3 +108,6 @@ CONFIG_USB_GADGET_DOWNLOAD=y
 CONFIG_G_DNL_MANUFACTURER="Texas Instruments"
 CONFIG_G_DNL_VENDOR_NUM=0x0451
 CONFIG_G_DNL_PRODUCT_NUM=0xd022
+CONFIG_SPL_GENERIC_PHY=y
+CONFIG_PIPE3_PHY=y
+CONFIG_SPL_PIPE3_PHY=y
configs/dra7xx_hs_evm_defconfig +10 -1
index 871604f..40ac3d5 100644
@@ -64,7 +64,12 @@ CONFIG_SPL_OF_CONTROL=y
 CONFIG_OF_LIST="dra7-evm dra72-evm dra72-evm-revc dra71-evm"
 CONFIG_DM=y
 CONFIG_SPL_DM=y
-# CONFIG_BLK is not set
+CONFIG_REGMAP=y
+CONFIG_SPL_REGMAP=y
+CONFIG_SYSCON=y
+CONFIG_SPL_SYSCON=y
+CONFIG_DM_SCSI=y
+CONFIG_DWC_AHCI=y
 CONFIG_DFU_MMC=y
 CONFIG_DFU_RAM=y
 CONFIG_DFU_SF=y
@@ -94,6 +99,7 @@ CONFIG_TI_QSPI=y
 CONFIG_TIMER=y
 CONFIG_OMAP_TIMER=y
 CONFIG_USB=y
+CONFIG_DM_USB=y
 CONFIG_USB_XHCI_HCD=y
 CONFIG_USB_XHCI_DWC3=y
 CONFIG_USB_DWC3=y
@@ -106,3 +112,6 @@ CONFIG_USB_GADGET_DOWNLOAD=y
 CONFIG_G_DNL_MANUFACTURER="Texas Instruments"
 CONFIG_G_DNL_VENDOR_NUM=0x0451
 CONFIG_G_DNL_PRODUCT_NUM=0xd022
+CONFIG_SPL_GENERIC_PHY=y
+CONFIG_PIPE3_PHY=y
+CONFIG_SPL_PIPE3_PHY=y
Signature · 1 line
1.9.1
#17 lore raw

cover OMAP: Move SATA to use block driver model

In reply to Jean-Jacques Hiblot

Hi all,

This is the VERSION 3 of the series. Sorry for the confusion, I messed up while preparing the patches.

Jean-Jacques

Quoted 93 lines · Jean-Jacques Hiblot

This series adds support for SATA using the driver model on omap platforms. It is based on the work of Mugunthan V N <[email protected]> in Feb 2016

The first 2 patches are preparatory work.
The 3rd patch adds a new framework to handle PHYs in a generic manner. The idea is to move the phy initialization out of the board-specific code into a proper driver. The link between the phy device and the controller device is done in by device-tree as it's done in linux. The API to control a phy has been copied from linux, excpet that the functions are prefixed by 'generic_phy_' instead of just 'phy_' because phy_reset() is already used to handle the Ethernet phys. The 5th patch adds a phy driver for the pipe3 sata phy found in the omaps/am5x/dra7x SOCs.
The 6th patch allows the device under the node ocp2scp at 4a090000 to be probed. The 7th patch implements a driver for the SATA controller found in the omaps/am5x/dra7x SOCs.
The 8th patch is cosmetic and changes the interface of scsi_detect_dev() The 9th patch moves the call to part_init() out of scsi_detect_dev(). This is a preparatory work path #10.
The 10th patches fix a divide-by-0 error that happens in scsi_scan() when DM is used and split scsi_scan() in 2 functions for clarity. The last patch enables the DM sata by default for the dra7 platforms.

changes since v2:
* Added unit tests for generic PHY uclass.
* Changed the generic phy API to use a 'struct udevice*' to reference the phy device.
* Don't modify anymore the root Makefile.
* Updated the Kconfig with more details on the PHY framework.
* Use a Unique Lincense Identifier (SPDX)
* Use omap5-u-boot.dtsi to mark the ocp2scp bus as compatible with "simple-bus"
* Split scsi_scan() in 2 for clarity. The function was becoming too long.

changes since v1:
* changed the way the 'old' sata code is compiled out when DM_SCSI is enabled.
* added a new framework for PHY management.
* added a new driver for the PIPE3 phy and use it in the dwc_ahci driver.
* changed the interface of scsi_detect_dev() and moved the call part_init() out of it.
* modified the fix to scsi_scan() in order to call scsi_detect_dev() only once.
* the max_lun and max_id parameters are now taken from the device-tree.
* Updated the defconfig changes to include the PHY driver and its dependencies.

Jean-Jacques Hiblot (11):
arm: omap: sata: move enable sata clocks to enable_basic_clocks()
arm: omap: sata: compile out board-level sata code when CONFIG_DM_SCSI
is defined
drivers: phy: add generic PHY framework
dm: test: Add tests for the generic PHY uclass
drivers: phy: add PIPE3 phy driver
dra7: dtsi: mark ocp2scp bus compatible with "simple-bus"
drivers: block: dwc_ahci: Implement a driver for Synopsys DWC sata
device
scsi: make the LUN a parameter of scsi_detect_dev()
scsi: move the partition initialization out of the scsi detection
dm: scsi: fix divide-by-0 error in scsi_scan()
defconfig: dra7xx_evm: enable CONFIG_BLK and disk driver model for
SCSI

  arch/arm/dts/omap5-u-boot.dtsi      |   4 +
  arch/arm/mach-omap2/Makefile        |   2 +
  arch/arm/mach-omap2/omap5/hw_data.c |  12 ++
  arch/arm/mach-omap2/sata.c          |  23 ---
  arch/sandbox/dts/test.dts           |   9 +
  common/scsi.c                       |  98 +++++-----
  configs/dra7xx_evm_defconfig        |  12 +-
  configs/dra7xx_hs_evm_defconfig     |  11 +-
  configs/sandbox_defconfig           |   2 +
  configs/sandbox_noblk_defconfig     |   2 +
  configs/sandbox_spl_defconfig       |   3 +
  drivers/Kconfig                     |   2 +
  drivers/Makefile                    |   1 +
  drivers/block/Kconfig               |  10 +
  drivers/block/Makefile              |   1 +
  drivers/block/dwc_ahci.c            | 100 ++++++++++
  drivers/phy/Kconfig                 |  59 ++++++
  drivers/phy/Makefile                |   4 +
  drivers/phy/phy-uclass.c            |  64 +++++++
  drivers/phy/sandbox-phy.c           |  78 ++++++++
  drivers/phy/ti-pipe3-phy.c          | 365 ++++++++++++++++++++++++++++++++++++
  include/dm/uclass-id.h              |   1 +
  include/generic-phy.h               |  36 ++++
  test/dm/Makefile                    |   1 +
  test/dm/generic_phy.c               |  89 +++++++++
  25 files changed, 922 insertions(+), 67 deletions(-)

create mode 100644 drivers/block/dwc_ahci.c
create mode 100644 drivers/phy/Kconfig
create mode 100644 drivers/phy/Makefile
create mode 100644 drivers/phy/phy-uclass.c
create mode 100644 drivers/phy/sandbox-phy.c
create mode 100644 drivers/phy/ti-pipe3-phy.c
create mode 100644 include/generic-phy.h
create mode 100644 test/dm/generic_phy.c