staging: mt7621-pci: some required changes after first review
Subsystems (2)
v2 cover staging: mt7621-pci: some required changes after first review
Hi,
Some things must be updated before get this a new attempt to get this mainlined:
- Device tree bindings need to move som stuff into child root nodes.
- Use relaxed version of readl and writel.
- Other minor stuff.
After this is merged in staging tree, I will move with 'git mv' this driver into 'drivers/pci/controller' as I've been suggested to do by Bjorn.
Thanks in advance for your time.
Best regards,
Sergio Paracuellos
Changes in v2:
- Add PATCH 6/6 making use of 'pcie_port_write'.
Sergio Paracuellos (6):
staging: mt7621-pci: make cleaner 'mt7621_pcie_enable_ports'
staging: mt7621-pci: remove 'RALINK_PCI_BAR0SETUP_ADDR' definition
staging: mt7621-pci: use {readl|writel}_relaxed instead of
readl/writel
staging: mt7621-dts: move some properties into root port child nodes
staging: mt7621-pci: parse some dt properties from root port child
nodes
staging: mt7621-pci: make use of 'pcie_port_write'
drivers/staging/mt7621-dts/mt7621.dtsi | 21 ++++---- drivers/staging/mt7621-pci/pci-mt7621.c | 66 ++++++++++--------------- 2 files changed, 39 insertions(+), 48 deletions(-)
Signature · 1 line
2.25.1
PATCH v2 1/6 staging: mt7621-pci: make cleaner 'mt7621_pcie_enable_ports'
Function 'mt7621_pcie_enable_ports' call 'mt7621_pcie_enable_port' for each available pcie port. Instead of having two for loops there just move needed initialization. There is one setting that can be removed which is the set for 'PCI_COMMAND_MASTER' bit. Pci drivers are in charge of set that bit if it is really needed and should be not a mission of the controller to do that.
--- drivers/staging/mt7621-pci/pci-mt7621.c | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-)
drivers/staging/mt7621-pci/pci-mt7621.c +8 -16
@@ -499,15 +499,18 @@ static void mt7621_pcie_enable_port(struct mt7621_pcie_port *port)/* configure class code and revision ID */ pcie_write (pcie,PCIE_CLASS_CODE |PCIE_REVISION_ID , offset +RALINK_PCI_CLASS ); + +/* configure RC FTS number to 250 when it leaves L0s */ + val =read_config (pcie, slot,PCIE_FTS_NUM ); + val &= ~PCIE_FTS_NUM_MASK ; + val |=PCIE_FTS_NUM_L0 (0x50 ); +write_config (pcie, slot,PCIE_FTS_NUM , val); }static int mt7621_pcie_enable_ports (struct mt7621_pcie *pcie) {struct device *dev = pcie->dev;struct mt7621_pcie_port *port; -u8 num_slots_enabled =0 ; -u32 slot; -u32 val;int err;/* Setup MEMWIN and IOWIN */
@@ -518,27 +521,16 @@ static int mt7621_pcie_enable_ports(struct mt7621_pcie *pcie)if (port->enabled) { err =clk_prepare_enable (port->clk);if (err) { -dev_err (dev,"enabling clk pcie%d\n" , slot); +dev_err (dev,"enabling clk pcie%d\n" , + port->slot);return err; }mt7621_pcie_enable_port (port);dev_info (dev,"PCIE%d enabled\n" , port->slot); - num_slots_enabled++; } } -for (slot =0 ; slot < num_slots_enabled; slot++) { - val =read_config (pcie, slot,PCI_COMMAND ); - val |=PCI_COMMAND_MASTER ; -write_config (pcie, slot,PCI_COMMAND , val); -/* configure RC FTS number to 250 when it leaves L0s */ - val =read_config (pcie, slot,PCIE_FTS_NUM ); - val &= ~PCIE_FTS_NUM_MASK ; - val |=PCIE_FTS_NUM_L0 (0x50 ); -write_config (pcie, slot,PCIE_FTS_NUM , val); - } -return 0 ; }
Signature · 1 line
2.25.1
PATCH v2 2/6 staging: mt7621-pci: remove 'RALINK_PCI_BAR0SETUP_ADDR' definition
In reply to Sergio ParacuellosInstead of define RALINK_PCI_BAR0SETUP_ADDR just use standard pci defnition for this which is 'PCI_BASE_ADDRESS_0'.
--- drivers/staging/mt7621-pci/pci-mt7621.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/staging/mt7621-pci/pci-mt7621.c +1 -2
@@ -47,7 +47,6 @@#define MT7621_PCIE_OFFSET 0x2000#define MT7621_NEXT_PORT 0x1000 -#define RALINK_PCI_BAR0SETUP_ADDR 0x0010#define RALINK_PCI_ID 0x0030#define RALINK_PCI_CLASS 0x0034#define RALINK_PCI_SUBID 0x0038
@@ -494,7 +493,7 @@ static void mt7621_pcie_enable_port(struct mt7621_pcie_port *port)/* map 2G DDR region */ pcie_write (pcie,PCIE_BAR_MAP_MAX |PCIE_BAR_ENABLE , - offset +RALINK_PCI_BAR0SETUP_ADDR ); + offset +PCI_BASE_ADDRESS_0 );/* configure class code and revision ID */ pcie_write(pcie, PCIE_CLASS_CODE | PCIE_REVISION_ID,
Signature · 1 line
2.25.1
PATCH v2 3/6 staging: mt7621-pci: use {readl|writel}_relaxed instead of readl/writel
In reply to Sergio ParacuellosThe driver does not perform DMA, so it's safe to use the relaxed version for both readl and writel operations.
--- drivers/staging/mt7621-pci/pci-mt7621.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-)
drivers/staging/mt7621-pci/pci-mt7621.c +7 -7
@@ -109,32 +109,32 @@ struct mt7621_pcie {static inline u32 pcie_read (struct mt7621_pcie *pcie,u32 reg) { -return readl (pcie->base + reg); +return readl_relaxed (pcie->base + reg); }static inline void pcie_write (struct mt7621_pcie *pcie,u32 val,u32 reg) { -writel (val, pcie->base + reg); +writel_relaxed (val, pcie->base + reg); }static inline void pcie_rmw (struct mt7621_pcie *pcie,u32 reg,u32 clr,u32 set) { -u32 val =readl (pcie->base + reg); +u32 val =readl_relaxed (pcie->base + reg); val &= ~clr; val |= set; -writel (val, pcie->base + reg); +writel_relaxed (val, pcie->base + reg); }static inline u32 pcie_port_read (struct mt7621_pcie_port *port,u32 reg) { -return readl (port->base + reg); +return readl_relaxed (port->base + reg); }static inline void pcie_port_write (struct mt7621_pcie_port *port,u32 val,u32 reg) { -writel (val, port->base + reg); +writel_relaxed (val, port->base + reg); } static inline u32 mt7621_pci_get_cfgaddr(unsigned int bus, unsigned int slot,
@@ -151,7 +151,7 @@ static void __iomem *mt7621_pcie_map_bus(struct pci_bus *bus,u32 address =mt7621_pci_get_cfgaddr (bus->number,PCI_SLOT (devfn),PCI_FUNC (devfn), where); -writel (address, pcie->base +RALINK_PCI_CONFIG_ADDR ); +writel_relaxed (address, pcie->base +RALINK_PCI_CONFIG_ADDR );return pcie->base +RALINK_PCI_CONFIG_DATA + (where &3 ); }
Signature · 1 line
2.25.1
PATCH v2 4/6 staging: mt7621-dts: move some properties into root port child nodes
In reply to Sergio ParacuellosAfter a review of the bindings 'clocks', 'resets' and 'phys' must be moved into root port child nodes. Hence, move all of them.
--- drivers/staging/mt7621-dts/mt7621.dtsi | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-)
drivers/staging/mt7621-dts/mt7621.dtsi +12 -9
@@ -500,15 +500,6 @@ pcie: pcie@1e140000 { status = "disabled"; - resets = <&rstctrl 24>, <&rstctrl 25>, <&rstctrl 26>; - reset-names = "pcie0", "pcie1", "pcie2"; - clocks = <&sysc MT7621_CLK_PCIE0>, - <&sysc MT7621_CLK_PCIE1>, - <&sysc MT7621_CLK_PCIE2>; - clock-names = "pcie0", "pcie1", "pcie2"; - phys = <&pcie0_phy 1>, <&pcie2_phy 0>; - phy-names = "pcie-phy0", "pcie-phy2"; - reset-gpios = <&gpio 19 GPIO_ACTIVE_LOW>; pcie@0,0 {
@@ -519,6 +510,10 @@ pcie@0,0 { #interrupt-cells = <1>; interrupt-map-mask = <0 0 0 0>; interrupt-map = <0 0 0 0 &gic GIC_SHARED 4 IRQ_TYPE_LEVEL_HIGH>; + resets = <&rstctrl 24>; + clocks = <&sysc MT7621_CLK_PCIE0>; + phys = <&pcie0_phy 1>; + phy-names = "pcie-phy0"; ranges; };
@@ -530,6 +525,10 @@ pcie@1,0 { #interrupt-cells = <1>; interrupt-map-mask = <0 0 0 0>; interrupt-map = <0 0 0 0 &gic GIC_SHARED 24 IRQ_TYPE_LEVEL_HIGH>; + resets = <&rstctrl 25>; + clocks = <&sysc MT7621_CLK_PCIE1>; + phys = <&pcie0_phy 1>; + phy-names = "pcie-phy1"; ranges; };
@@ -541,6 +540,10 @@ pcie@2,0 { #interrupt-cells = <1>; interrupt-map-mask = <0 0 0 0>; interrupt-map = <0 0 0 0 &gic GIC_SHARED 25 IRQ_TYPE_LEVEL_HIGH>; + resets = <&rstctrl 26>; + clocks = <&sysc MT7621_CLK_PCIE2>; + phys = <&pcie2_phy 0>; + phy-names = "pcie-phy2"; ranges; }; };
Signature · 1 line
2.25.1
PATCH v2 5/6 staging: mt7621-pci: parse some dt properties from root port child nodes
In reply to Sergio ParacuellosProperties 'clocks', 'resets' and 'phys' have been moved from parent node to the root port children. Hence we have to adapt the way device tree is parsed in driver code to properly align things and make all the stuff work.
--- drivers/staging/mt7621-pci/pci-mt7621.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-)
drivers/staging/mt7621-pci/pci-mt7621.c +8 -7
@@ -290,6 +290,7 @@ static int mt7621_pci_parse_request_of_pci_ranges(struct pci_host_bridge *host) }static int mt7621_pcie_parse_port (struct mt7621_pcie *pcie, +struct device_node *node,int slot) {struct mt7621_pcie_port *port;
@@ -305,24 +306,24 @@ static int mt7621_pcie_parse_port(struct mt7621_pcie *pcie,if (IS_ERR (port->base))return PTR_ERR (port->base); -snprintf (name,sizeof (name),"pcie%d" , slot); - port->clk =devm_clk_get (dev, name); + port->clk =devm_get_clk_from_child (dev, node,NULL );if (IS_ERR (port->clk)) {dev_err (dev,"failed to get pcie%d clock\n" , slot);return PTR_ERR (port->clk); } -snprintf (name,sizeof (name),"pcie%d" , slot); - port->pcie_rst =devm_reset_control_get_exclusive (dev, name); + port->pcie_rst =of_reset_control_get_exclusive (node,NULL );if (PTR_ERR (port->pcie_rst) == -EPROBE_DEFER ) {dev_err (dev,"failed to get pcie%d reset control\n" , slot);return PTR_ERR (port->pcie_rst); }snprintf (name,sizeof (name),"pcie-phy%d" , slot); - port->phy =devm_phy_get (dev, name); -if (IS_ERR (port->phy) && slot !=1 ) + port->phy =devm_of_phy_get (dev, node, name); +if (IS_ERR (port->phy)) { +dev_err (dev,"failed to get pcie-phy%d\n" , slot);return PTR_ERR (port->phy); + } port->gpio_rst =devm_gpiod_get_index_optional (dev,"reset" , slot,GPIOD_OUT_LOW );
@@ -363,7 +364,7 @@ static int mt7621_pcie_parse_dt(struct mt7621_pcie *pcie) slot =PCI_SLOT (err); - err =mt7621_pcie_parse_port (pcie, slot); + err =mt7621_pcie_parse_port (pcie, child, slot);if (err) {of_node_put (child);return err;
Signature · 1 line
2.25.1
PATCH v2 6/6 staging: mt7621-pci: make use of 'pcie_port_write'
In reply to Sergio ParacuellosFunction 'mt7621_pcie_enable_port' is calculating an offset to write some port related registers. Instead of doing that just make use of already existent 'pcie_write_port' function and use virtualy mapped base address with registers. This increase readability and allow us to remove also two defitions not used else where.
--- drivers/staging/mt7621-pci/pci-mt7621.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-)
drivers/staging/mt7621-pci/pci-mt7621.c +4 -8
@@ -44,9 +44,6 @@#define RALINK_PCI_IOBASE 0x002C/* PCIe RC control registers */ -#define MT7621_PCIE_OFFSET 0x2000 -#define MT7621_NEXT_PORT 0x1000 -#define RALINK_PCI_ID 0x0030#define RALINK_PCI_CLASS 0x0034#define RALINK_PCI_SUBID 0x0038
@@ -484,7 +481,6 @@ static void mt7621_pcie_enable_port(struct mt7621_pcie_port *port) {struct mt7621_pcie *pcie = port->pcie;u32 slot = port->slot; -u32 offset =MT7621_PCIE_OFFSET + (slot *MT7621_NEXT_PORT );u32 val;/* enable pcie interrupt */
@@ -493,12 +489,12 @@ static void mt7621_pcie_enable_port(struct mt7621_pcie_port *port)pcie_write (pcie, val,RALINK_PCI_PCIMSK_ADDR );/* map 2G DDR region */ -pcie_write (pcie,PCIE_BAR_MAP_MAX |PCIE_BAR_ENABLE , - offset +PCI_BASE_ADDRESS_0 ); +pcie_port_write (port,PCIE_BAR_MAP_MAX |PCIE_BAR_ENABLE , +PCI_BASE_ADDRESS_0 );/* configure class code and revision ID */ -pcie_write (pcie,PCIE_CLASS_CODE |PCIE_REVISION_ID , - offset +RALINK_PCI_CLASS ); +pcie_port_write (port,PCIE_CLASS_CODE |PCIE_REVISION_ID , +RALINK_PCI_CLASS );/* configure RC FTS number to 250 when it leaves L0s */ val =read_config (pcie, slot,PCIE_FTS_NUM );
Signature · 1 line
2.25.1