Re: [PATCH 05/17] pci: host: pcie-dra7xx: add support for pcie-dra7xx controller

2014-05-09 Thread Pavel Machek
  +   writel(value, base + offset);
  +}
  +
  +static int dra7xx_pcie_link_up(struct pcie_port *pp)
  +{
  +   struct dra7xx_pcie *dra7xx = to_dra7xx_pcie(pp);
  +   u32 reg = dra7xx_pcie_readl(dra7xx-base, PCIECTRL_DRA7XX_CONF_PHY_CS);
  +
  +   if (reg  LINK_UP)
  +   return true;
  +   return false;
 
 return reg  LINK_UP;

Function int returning true. I'd change the prototype and would
return !!(reg  ...);

Pavel


-- 
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) 
http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
--
To unsubscribe from this list: send the line unsubscribe linux-omap in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 05/17] pci: host: pcie-dra7xx: add support for pcie-dra7xx controller

2014-05-09 Thread Kishon Vijay Abraham I
Hi Arnd,

On Wednesday 07 May 2014 03:00 PM, Arnd Bergmann wrote:
 On Wednesday 07 May 2014 14:14:55 Kishon Vijay Abraham I wrote:
 +static void dra7xx_pcie_enable_interrupts(struct pcie_port *pp)
 +{
 +struct dra7xx_pcie *dra7xx = to_dra7xx_pcie(pp);
 +
 +dra7xx_pcie_writel(dra7xx-base, PCIECTRL_DRA7XX_CONF_IRQSTATUS_MAIN,
 +   ~INTERRUPTS);
 +dra7xx_pcie_writel(dra7xx-base,
 +   PCIECTRL_DRA7XX_CONF_IRQENABLE_SET_MAIN, 
 INTERRUPTS);
 +dra7xx_pcie_writel(dra7xx-base, PCIECTRL_DRA7XX_CONF_IRQSTATUS_MSI,
 +   ~LEG_EP_INTERRUPTS  ~MSI);
 +
 +if (IS_ENABLED(CONFIG_PCI_MSI))
 +dra7xx_pcie_writel(dra7xx-base,
 +   PCIECTRL_DRA7XX_CONF_IRQENABLE_SET_MSI, 
 MSI);
 +else
 +dra7xx_pcie_writel(dra7xx-base,
 +   PCIECTRL_DRA7XX_CONF_IRQENABLE_SET_MSI,
 +   LEG_EP_INTERRUPTS);

 Doesn't this just enable one or the other? In general I'd assume you need
 both INTx and MSI, at least if MSI is available.

 Not sure since the programming sequence in the TRM explicitly states either
 legacy interrupts or MSI interrupts should be enabled but not both.
 
 Hmm, I think that means you can't have MSI at all. You have to support
 legacy PCI devices that can't do MSI.
 
 Do you know if you have a modern GIC implementation with MSI support
 in these SoCs? It would be better anyway to use the GIC for doing

In DRA7 it is not there. I'm not sure in other platforms.
 MSI, so you can just ignore the internal MSI controller here.
 
 +static int add_pcie_port(struct dra7xx_pcie *dra7xx,
 +  struct platform_device *pdev)
 +{
 +int ret;
 +struct pcie_port *pp;
 +struct resource *res;
 +struct device *dev = pdev-dev;
 +
 +pp = dra7xx-pp;
 +pp-dev = dev;
 +pp-ops = dra7xx_pcie_host_ops;
 +
 +spin_lock_init(pp-conf_lock);
 +
 +pp-irq = platform_get_irq(pdev, 1);
 +if (pp-irq  0) {
 +dev_err(dev, missing IRQ resource\n);
 +return -EINVAL;
 +}


 The binding does not list a mandatory interrupts property, so
 this should not be treated as an error.

 actually the 'interrupts' property is documented in pci/designware-pcie.txt.
 
 Hmm, but you don't seem to use it the same way as documented there.
 I'm not sure what 'level interrupt, pulse interrupt, special interrupt'
 in the parent binding are, but they don't seem to be the ones you use
 here.

Yeah. I'll update my Documentation. Thanks for pointing this out.

Thanks
Kishon
--
To unsubscribe from this list: send the line unsubscribe linux-omap in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 05/17] pci: host: pcie-dra7xx: add support for pcie-dra7xx controller

2014-05-08 Thread Jingoo Han
On Wednesday, May 07, 2014 6:26 PM, Arnd Bergmann wrote:
 On Wednesday 07 May 2014 14:52:47 Kishon Vijay Abraham I wrote:
  On Tuesday 06 May 2014 10:05 PM, Jason Gunthorpe wrote:
   On Tue, May 06, 2014 at 07:03:51PM +0530, Kishon Vijay Abraham I wrote:
   +Example:
   +pcie@5100 {
   +compatible = ti,dra7xx-pcie;
   +reg = 0x51002000 0x14c, 0x5100 0x2000;
   +reg-names = ti_conf, rc_dbics;
   +interrupts = 0 232 0x4, 0 233 0x4;
   +#address-cells = ;
   +#size-cells = 2;
   +device_type = pci;
   +ti,device_type = ;
   +ranges = 0x0800 0 0x20001000 0x20001000 0 0x2000  /* 
   Configuration Space */
  
   Configuration space should not show up in the ranges, please don't
   copy that mistake from other drivers, put it in reg.
 
  But then it needs pcie-designware.c to be modified and it will be breaking
  other platforms no?
 
 I think the pcie-designware driver should be changed to allow either way.
 Ideally we would deprecate the existing method in a way that for new 
 front-ends
 it doesn't work, but the old front-ends can still deal with it but also work
 if you put it into the reg property.

(+cc Pratyush Anand, Thierry Reding)

Hi Arnd,

Thank you for your comment.
Do you mean the case of Tegra PCIe as below?

./arch/arm/boot/dts/tegra20.dts
pcie-controller@80003000 {
...
reg = 0x80003000 0x0800   /* PADS registers */
 0x80003800 0x0200   /* AFI registers */
 0x9000 0x1000; /* configuration space */
...
ranges = 0x8200 0 0x8000 0x8000 0 0x1000   /* 
port 0 registers */
0x8200 0 0x80001000 0x80001000 0 0x1000   /* 
port 1 registers */
0x8100 0 0  0x8200 0 0x0001   /* 
downstream I/O */
0x8200 0 0xa000 0xa000 0 0x0800   /* 
non-prefetchable memory */
0xc200 0 0xa800 0xa800 0 0x1800; /* 
prefetchable memory */
...

./drivers/pci/host/pci-tegra.c
/* request configuration space, but remap later, on demand */
res = platform_get_resource_byname(pdev, IORESOURCE_MEM, cs);
...
pcie-cs = devm_request_mem_region(pcie-dev, res-start,
resource_size(res), res-name);


Best regards,
Jingoo Han


--
To unsubscribe from this list: send the line unsubscribe linux-omap in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 05/17] pci: host: pcie-dra7xx: add support for pcie-dra7xx controller

2014-05-08 Thread Arnd Bergmann
On Thursday 08 May 2014 17:56:38 Jingoo Han wrote:
 On Wednesday, May 07, 2014 6:26 PM, Arnd Bergmann wrote:
  On Wednesday 07 May 2014 14:52:47 Kishon Vijay Abraham I wrote:
   On Tuesday 06 May 2014 10:05 PM, Jason Gunthorpe wrote:
On Tue, May 06, 2014 at 07:03:51PM +0530, Kishon Vijay Abraham I wrote:
+Example:
+pcie@5100 {
+compatible = ti,dra7xx-pcie;
+reg = 0x51002000 0x14c, 0x5100 0x2000;
+reg-names = ti_conf, rc_dbics;
+interrupts = 0 232 0x4, 0 233 0x4;
+#address-cells = ;
+#size-cells = 2;
+device_type = pci;
+ti,device_type = ;
+ranges = 0x0800 0 0x20001000 0x20001000 0 0x2000  /* 
Configuration Space */
   
Configuration space should not show up in the ranges, please don't
copy that mistake from other drivers, put it in reg.
  
   But then it needs pcie-designware.c to be modified and it will be breaking
   other platforms no?
  
  I think the pcie-designware driver should be changed to allow either way.
  Ideally we would deprecate the existing method in a way that for new 
  front-ends
  it doesn't work, but the old front-ends can still deal with it but also work
  if you put it into the reg property.
 
 (+cc Pratyush Anand, Thierry Reding)
 
 Hi Arnd,
 
 Thank you for your comment.
 Do you mean the case of Tegra PCIe as below?
 
 ./arch/arm/boot/dts/tegra20.dts
 pcie-controller@80003000 {
 ...
 reg = 0x80003000 0x0800   /* PADS registers */
  0x80003800 0x0200   /* AFI registers */
  0x9000 0x1000; /* configuration space */
 ...
 ranges = 0x8200 0 0x8000 0x8000 0 0x1000   
 /* port 0 registers */
 0x8200 0 0x80001000 0x80001000 0 0x1000   /* 
 port 1 registers */
 0x8100 0 0  0x8200 0 0x0001   /* 
 downstream I/O */
 0x8200 0 0xa000 0xa000 0 0x0800   /* 
 non-prefetchable memory */
 0xc200 0 0xa800 0xa800 0 0x1800; /* 
 prefetchable memory */
 ...
 
 ./drivers/pci/host/pci-tegra.c
 /* request configuration space, but remap later, on demand */
 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, cs);
 ...
 pcie-cs = devm_request_mem_region(pcie-dev, res-start,
 resource_size(res), 
 res-name);

Yes, that is how the config space should be handled normally.

Arnd
--
To unsubscribe from this list: send the line unsubscribe linux-omap in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 05/17] pci: host: pcie-dra7xx: add support for pcie-dra7xx controller

2014-05-07 Thread Kishon Vijay Abraham I
Hi,

On Tuesday 06 May 2014 07:14 PM, Marek Vasut wrote:
 On Tuesday, May 06, 2014 at 03:33:51 PM, Kishon Vijay Abraham I wrote:
 Added support for pcie controller in dra7xx. This driver re-uses
 the designware core code that is already present in kernel.
 
 [...]
 
 +#define to_dra7xx_pcie(x)   container_of((x), struct dra7xx_pcie, pp)
 +
 +static inline u32 dra7xx_pcie_readl(void __iomem *base, u32 offset)
 
 Just pass struct dra7xx_pcie * instead of *base here , it will make the code 
 below shorter.
 
 +{
 +return readl(base + offset);
 +}
 +
 +static inline void dra7xx_pcie_writel(void __iomem *base, u32 offset, u32
 value) +{
 
 DTTO.
 
 +writel(value, base + offset);
 +}
 +
 +static int dra7xx_pcie_link_up(struct pcie_port *pp)
 +{
 +struct dra7xx_pcie *dra7xx = to_dra7xx_pcie(pp);
 +u32 reg = dra7xx_pcie_readl(dra7xx-base, PCIECTRL_DRA7XX_CONF_PHY_CS);
 +
 +if (reg  LINK_UP)
 +return true;
 +return false;
 
 return reg  LINK_UP;
 
 +}
 +
 +static int dra7xx_pcie_establish_link(struct pcie_port *pp)
 +{
 +u32 reg;
 +int retries = 1000;
 +struct dra7xx_pcie *dra7xx = to_dra7xx_pcie(pp);
 +
 +if (dw_pcie_link_up(pp)) {
 +dev_err(pp-dev, link is already up\n);
 
 This will spew, since the .link_up (and thus this function) can be called 
 repeatedly. The subsystem will query if the link is up via this function.

*dra7xx_pcie_establish_link* is not the callback for link_up function, so it's
actually called only once.
 
 +return 0;
 +}
 +
 +reg = dra7xx_pcie_readl(dra7xx-base, PCIECTRL_DRA7XX_CONF_DEVICE_CMD);
 +reg |= LTSSM_EN;
 +dra7xx_pcie_writel(dra7xx-base, PCIECTRL_DRA7XX_CONF_DEVICE_CMD, reg);
 +
 +while (--retries) {
 
 Use retries--
 
 +reg = dra7xx_pcie_readl(dra7xx-base,
 +PCIECTRL_DRA7XX_CONF_PHY_CS);
 +if (reg  LINK_UP)
 +break;
 +usleep_range(10, 20);
 +}
 +
 +if (retries = 0) {
 
 Then check if retries == 0 and retries can be unsigned int.
 
 +dev_err(pp-dev, link is not up\n);
 +return -ETIMEDOUT;
 +}
 +
 +return 0;
 +}
 [...]
 +static int __init dra7xx_pcie_probe(struct platform_device *pdev)
 +{
 +u32 reg;
 +int ret;
 +int irq;
 +struct phy *phy;
 +void __iomem *base;
 +struct resource *res;
 +struct dra7xx_pcie *dra7xx;
 +struct device *dev = pdev-dev;
 +
 +dra7xx = devm_kzalloc(pdev-dev, sizeof(*dra7xx), GFP_KERNEL);
 +if (!dra7xx)
 +return -ENOMEM;
 +
 +irq = platform_get_irq(pdev, 0);
 +if (irq  0) {
 +dev_err(dev, missing IRQ resource\n);
 +return -EINVAL;
 +}
 +
 +ret = devm_request_irq(pdev-dev, irq, dra7xx_pcie_irq_handler,
 +   IRQF_SHARED, dra7xx-pcie-main, dra7xx);
 +if (ret) {
 +dev_err(pdev-dev, failed to request irq\n);
 +return ret;
 +}
 +
 +res = platform_get_resource_byname(pdev, IORESOURCE_MEM, ti_conf);
 +base = devm_ioremap_nocache(dev, res-start, resource_size(res));
 +if (!base)
 +return -ENOMEM;
 +
 +phy = devm_phy_get(dev, pcie-phy);
 +if (IS_ERR(phy))
 +return PTR_ERR(phy);
 +
 +ret = phy_init(phy);
 +if (ret  0)
 +return ret;
 +
 +ret = phy_power_on(phy);
 +if (ret  0)
 +goto err_power_on;
 +
 +dra7xx-base = base;
 +dra7xx-phy = phy;
 +dra7xx-dev = dev;
 +
 +pm_runtime_enable(pdev-dev);
 +ret = pm_runtime_get_sync(pdev-dev);
 +if (IS_ERR_VALUE(ret)) {
 +dev_err(dev, pm_runtime_get_sync failed\n);
 +goto err_runtime_get;
 +}
 +
 +reg = dra7xx_pcie_readl(dra7xx-base, PCIECTRL_DRA7XX_CONF_DEVICE_CMD);
 +reg = ~LTSSM_EN;
 +dra7xx_pcie_writel(dra7xx-base, PCIECTRL_DRA7XX_CONF_DEVICE_CMD, reg);
 
 platform_set_drvdata() should be here, before you add the port.
 
 +ret = add_pcie_port(dra7xx, pdev);
 +if (ret  0)
 +goto err_add_port;
 +
 +platform_set_drvdata(pdev, dra7xx);

Al-right. Will fix this and all your other comments.

Thanks
Kishon
--
To unsubscribe from this list: send the line unsubscribe linux-omap in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 05/17] pci: host: pcie-dra7xx: add support for pcie-dra7xx controller

2014-05-07 Thread Kishon Vijay Abraham I
Hi,

On Tuesday 06 May 2014 07:24 PM, Arnd Bergmann wrote:
 On Tuesday 06 May 2014 19:03:51 Kishon Vijay Abraham I wrote:
 Added support for pcie controller in dra7xx. This driver re-uses
 the designware core code that is already present in kernel.

 Cc: Bjorn Helgaas bhelg...@google.com
 Cc: Mohit Kumar mohit.ku...@st.com
 Cc: Jingoo Han jg1@samsung.com
 Cc: Marek Vasut ma...@denx.de
 Signed-off-by: Kishon Vijay Abraham I kis...@ti.com
 
 Looks pretty good overall, just a few details I noticed:
 
 diff --git a/Documentation/devicetree/bindings/pci/ti-pci.txt 
 b/Documentation/devicetree/bindings/pci/ti-pci.txt
 new file mode 100644
 index 000..6cb6f09
 --- /dev/null
 +++ b/Documentation/devicetree/bindings/pci/ti-pci.txt
 @@ -0,0 +1,33 @@
 +TI PCI Controllers
 +
 +PCIe Designware Controller
 +This node should have the properties described in designware-pcie.txt.
 + - compatible: Should be ti,dra7xx-pcie
 
 No xx in compatible strings please. Just make name this after the first
 chip to use this particular interface.

ok.
 
 + - reg : Address and length of the register set for the device.
 + - reg-names : ti_conf for the TI specific registers and rc_dbics for the
 +   designware registers.
 
 The description uses inconsistent quotation marks. You should also have
 a fixed order in the binding, such as
 
  - reg : Two register ranges as listed in the reg-names property
  - reg-names : The first entry must be ti-conf for the TI specific registers
  The second entry must be rc-dbics for the designware pcie 
 registers.

ok, looks better.
 
 + - phys : the phandle for the PHY device (used by generic PHY framework)
 + - phy-names : the names of the PHY corresponding to the PHYs present in the
 +   *phy* phandle.
 
 It's not just a phandle, it can be any phy specifier including additional
 argument cells.
 
 The second line should just read
 
  - phy-names : must be pcie-phy

will fix this.
 
 diff --git a/drivers/pci/host/Kconfig b/drivers/pci/host/Kconfig
 index a6f67ec..7be6393 100644
 --- a/drivers/pci/host/Kconfig
 +++ b/drivers/pci/host/Kconfig
 @@ -1,6 +1,16 @@
  menu PCI host controller drivers
  depends on PCI
  
 +config PCI_DRA7XX
 +bool TI DRA7xx PCIe controller
 +select PCIE_DW
 +depends on OF || HAS_IOMEM || TI_PIPE3
 
 I think you mean , not || here.

ah.. indeed.
 
 +static inline u32 x(void __iomem *base, u32 offset)
 +{
 +return readl(base + offset);
 +}
 +
 +static inline void dra7xx_pcie_writel(void __iomem *base, u32 offset, u32 
 value)
 +{
 +writel(value, base + offset);
 +}
 
 These don't actually seem to add any value, you need more characters
 to call the inline function than to open-code it.
 
 +static void dra7xx_pcie_enable_interrupts(struct pcie_port *pp)
 +{
 +struct dra7xx_pcie *dra7xx = to_dra7xx_pcie(pp);
 +
 +dra7xx_pcie_writel(dra7xx-base, PCIECTRL_DRA7XX_CONF_IRQSTATUS_MAIN,
 +   ~INTERRUPTS);
 +dra7xx_pcie_writel(dra7xx-base,
 +   PCIECTRL_DRA7XX_CONF_IRQENABLE_SET_MAIN, INTERRUPTS);
 +dra7xx_pcie_writel(dra7xx-base, PCIECTRL_DRA7XX_CONF_IRQSTATUS_MSI,
 +   ~LEG_EP_INTERRUPTS  ~MSI);
 +
 +if (IS_ENABLED(CONFIG_PCI_MSI))
 +dra7xx_pcie_writel(dra7xx-base,
 +   PCIECTRL_DRA7XX_CONF_IRQENABLE_SET_MSI, MSI);
 +else
 +dra7xx_pcie_writel(dra7xx-base,
 +   PCIECTRL_DRA7XX_CONF_IRQENABLE_SET_MSI,
 +   LEG_EP_INTERRUPTS);
 
 Doesn't this just enable one or the other? In general I'd assume you need
 both INTx and MSI, at least if MSI is available.

Not sure since the programming sequence in the TRM explicitly states either
legacy interrupts or MSI interrupts should be enabled but not both.
 
 It probably doesn't hurt to always turn them all on.
 
 +static int add_pcie_port(struct dra7xx_pcie *dra7xx,
 +  struct platform_device *pdev)
 +{
 +int ret;
 +struct pcie_port *pp;
 +struct resource *res;
 +struct device *dev = pdev-dev;
 +
 +pp = dra7xx-pp;
 +pp-dev = dev;
 +pp-ops = dra7xx_pcie_host_ops;
 +
 +spin_lock_init(pp-conf_lock);
 +
 +pp-irq = platform_get_irq(pdev, 1);
 +if (pp-irq  0) {
 +dev_err(dev, missing IRQ resource\n);
 +return -EINVAL;
 +}

 
 The binding does not list a mandatory interrupts property, so
 this should not be treated as an error.

actually the 'interrupts' property is documented in pci/designware-pcie.txt.
 
 +static int __init dra7xx_pcie_probe(struct platform_device *pdev)
 +{
 +irq = platform_get_irq(pdev, 0);
 +if (irq  0) {
 +dev_err(dev, missing IRQ resource\n);
 +return -EINVAL;
 +}
 +
 +ret = devm_request_irq(pdev-dev, irq, dra7xx_pcie_irq_handler,
 +   IRQF_SHARED, dra7xx-pcie-main, dra7xx);
 +if (ret) {
 +dev_err(pdev-dev, failed to request irq\n);
 +   

Re: [PATCH 05/17] pci: host: pcie-dra7xx: add support for pcie-dra7xx controller

2014-05-07 Thread Kishon Vijay Abraham I
Hi,

On Tuesday 06 May 2014 10:05 PM, Jason Gunthorpe wrote:
 On Tue, May 06, 2014 at 07:03:51PM +0530, Kishon Vijay Abraham I wrote:
 +Example:
 +pcie@5100 {
 +compatible = ti,dra7xx-pcie;
 +reg = 0x51002000 0x14c, 0x5100 0x2000;
 +reg-names = ti_conf, rc_dbics;
 +interrupts = 0 232 0x4, 0 233 0x4;
 +#address-cells = 3;
 +#size-cells = 2;
 +device_type = pci;
 +ti,device_type = 3;
 +ranges = 0x0800 0 0x20001000 0x20001000 0 0x2000  /* 
 Configuration Space */
 
 Configuration space should not show up in the ranges, please don't
 copy that mistake from other drivers, put it in reg.

But then it needs pcie-designware.c to be modified and it will be breaking
other platforms no?
 
 +interrupt-map-mask = 0 0 0 0;
 +interrupt-map = 0x0 0 gic 134;
 
 The HW cannot decode INTA/B/C/D?
 
 +#define PCIECTRL_DRA7XX_CONF_IRQSTATUS_MSI  0x0034
 +#define PCIECTRL_DRA7XX_CONF_IRQENABLE_SET_MSI  0x0038
 +#define INTABIT(0)
 +#define INTBBIT(1)
 +#define INTCBIT(2)
 +#define INTDBIT(3)
 +#define MSI BIT(4)
 +#define LEG_EP_INTERRUPTS (INTA | INTB | INTC | INTD)
 
 Oh, it can, it would be wise to export this from the driver. Look at
 the latest patches from Srikanth Thokala for the Xilinx PCI driver to
 see how this should look

ok.. will have a look at it.

Thanks
Kishon
--
To unsubscribe from this list: send the line unsubscribe linux-omap in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 05/17] pci: host: pcie-dra7xx: add support for pcie-dra7xx controller

2014-05-07 Thread Arnd Bergmann
On Wednesday 07 May 2014 14:52:47 Kishon Vijay Abraham I wrote:
 On Tuesday 06 May 2014 10:05 PM, Jason Gunthorpe wrote:
  On Tue, May 06, 2014 at 07:03:51PM +0530, Kishon Vijay Abraham I wrote:
  +Example:
  +pcie@5100 {
  +compatible = ti,dra7xx-pcie;
  +reg = 0x51002000 0x14c, 0x5100 0x2000;
  +reg-names = ti_conf, rc_dbics;
  +interrupts = 0 232 0x4, 0 233 0x4;
  +#address-cells = ;
  +#size-cells = 2;
  +device_type = pci;
  +ti,device_type = ;
  +ranges = 0x0800 0 0x20001000 0x20001000 0 0x2000  /* 
  Configuration Space */
  
  Configuration space should not show up in the ranges, please don't
  copy that mistake from other drivers, put it in reg.
 
 But then it needs pcie-designware.c to be modified and it will be breaking
 other platforms no?

I think the pcie-designware driver should be changed to allow either way.
Ideally we would deprecate the existing method in a way that for new front-ends
it doesn't work, but the old front-ends can still deal with it but also work
if you put it into the reg property.

Arnd
--
To unsubscribe from this list: send the line unsubscribe linux-omap in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 05/17] pci: host: pcie-dra7xx: add support for pcie-dra7xx controller

2014-05-07 Thread Arnd Bergmann
On Wednesday 07 May 2014 14:14:55 Kishon Vijay Abraham I wrote:
  +static void dra7xx_pcie_enable_interrupts(struct pcie_port *pp)
  +{
  +struct dra7xx_pcie *dra7xx = to_dra7xx_pcie(pp);
  +
  +dra7xx_pcie_writel(dra7xx-base, PCIECTRL_DRA7XX_CONF_IRQSTATUS_MAIN,
  +   ~INTERRUPTS);
  +dra7xx_pcie_writel(dra7xx-base,
  +   PCIECTRL_DRA7XX_CONF_IRQENABLE_SET_MAIN, 
  INTERRUPTS);
  +dra7xx_pcie_writel(dra7xx-base, PCIECTRL_DRA7XX_CONF_IRQSTATUS_MSI,
  +   ~LEG_EP_INTERRUPTS  ~MSI);
  +
  +if (IS_ENABLED(CONFIG_PCI_MSI))
  +dra7xx_pcie_writel(dra7xx-base,
  +   PCIECTRL_DRA7XX_CONF_IRQENABLE_SET_MSI, 
  MSI);
  +else
  +dra7xx_pcie_writel(dra7xx-base,
  +   PCIECTRL_DRA7XX_CONF_IRQENABLE_SET_MSI,
  +   LEG_EP_INTERRUPTS);
  
  Doesn't this just enable one or the other? In general I'd assume you need
  both INTx and MSI, at least if MSI is available.
 
 Not sure since the programming sequence in the TRM explicitly states either
 legacy interrupts or MSI interrupts should be enabled but not both.

Hmm, I think that means you can't have MSI at all. You have to support
legacy PCI devices that can't do MSI.

Do you know if you have a modern GIC implementation with MSI support
in these SoCs? It would be better anyway to use the GIC for doing
MSI, so you can just ignore the internal MSI controller here.

  +static int add_pcie_port(struct dra7xx_pcie *dra7xx,
  +  struct platform_device *pdev)
  +{
  +int ret;
  +struct pcie_port *pp;
  +struct resource *res;
  +struct device *dev = pdev-dev;
  +
  +pp = dra7xx-pp;
  +pp-dev = dev;
  +pp-ops = dra7xx_pcie_host_ops;
  +
  +spin_lock_init(pp-conf_lock);
  +
  +pp-irq = platform_get_irq(pdev, 1);
  +if (pp-irq  0) {
  +dev_err(dev, missing IRQ resource\n);
  +return -EINVAL;
  +}
 
  
  The binding does not list a mandatory interrupts property, so
  this should not be treated as an error.
 
 actually the 'interrupts' property is documented in pci/designware-pcie.txt.

Hmm, but you don't seem to use it the same way as documented there.
I'm not sure what 'level interrupt, pulse interrupt, special interrupt'
in the parent binding are, but they don't seem to be the ones you use
here.

Arnd
--
To unsubscribe from this list: send the line unsubscribe linux-omap in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 05/17] pci: host: pcie-dra7xx: add support for pcie-dra7xx controller

2014-05-06 Thread Kishon Vijay Abraham I
Added support for pcie controller in dra7xx. This driver re-uses
the designware core code that is already present in kernel.

Cc: Bjorn Helgaas bhelg...@google.com
Cc: Mohit Kumar mohit.ku...@st.com
Cc: Jingoo Han jg1@samsung.com
Cc: Marek Vasut ma...@denx.de
Signed-off-by: Kishon Vijay Abraham I kis...@ti.com
---
 Documentation/devicetree/bindings/pci/ti-pci.txt |   33 ++
 drivers/pci/host/Kconfig |   10 +
 drivers/pci/host/Makefile|1 +
 drivers/pci/host/pci-dra7xx.c|  385 ++
 4 files changed, 429 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/pci/ti-pci.txt
 create mode 100644 drivers/pci/host/pci-dra7xx.c

diff --git a/Documentation/devicetree/bindings/pci/ti-pci.txt 
b/Documentation/devicetree/bindings/pci/ti-pci.txt
new file mode 100644
index 000..6cb6f09
--- /dev/null
+++ b/Documentation/devicetree/bindings/pci/ti-pci.txt
@@ -0,0 +1,33 @@
+TI PCI Controllers
+
+PCIe Designware Controller
+This node should have the properties described in designware-pcie.txt.
+ - compatible: Should be ti,dra7xx-pcie
+ - reg : Address and length of the register set for the device.
+ - reg-names : ti_conf for the TI specific registers and rc_dbics for the
+   designware registers.
+ - phys : the phandle for the PHY device (used by generic PHY framework)
+ - phy-names : the names of the PHY corresponding to the PHYs present in the
+   *phy* phandle.
+
+Example:
+pcie@5100 {
+   compatible = ti,dra7xx-pcie;
+   reg = 0x51002000 0x14c, 0x5100 0x2000;
+   reg-names = ti_conf, rc_dbics;
+   interrupts = 0 232 0x4, 0 233 0x4;
+   #address-cells = 3;
+   #size-cells = 2;
+   device_type = pci;
+   ti,device_type = 3;
+   ranges = 0x0800 0 0x20001000 0x20001000 0 0x2000  /* 
Configuration Space */
+ 0x8100 0 0  0x20003000 0 0x0001  /* IO Space 
*/
+ 0x8200 0 0x20013000 0x20013000 0 0xffed000; /* MEM Space 
*/
+   #interrupt-cells = 1;
+   num-lanes = 1;
+   interrupt-map-mask = 0 0 0 0;
+   interrupt-map = 0x0 0 gic 134;
+   ti,hwmods = pcie1;
+   phys = pcie1_phy;
+   phy-names = pcie-phy;
+};
diff --git a/drivers/pci/host/Kconfig b/drivers/pci/host/Kconfig
index a6f67ec..7be6393 100644
--- a/drivers/pci/host/Kconfig
+++ b/drivers/pci/host/Kconfig
@@ -1,6 +1,16 @@
 menu PCI host controller drivers
depends on PCI
 
+config PCI_DRA7XX
+   bool TI DRA7xx PCIe controller
+   select PCIE_DW
+   depends on OF || HAS_IOMEM || TI_PIPE3
+   help
+Enables support for the PCIE controller present in DRA7xx SoC. There
+are two instances of PCIE controller in DRA7xx. This controller can
+act both as EP and RC. This reuses the same Designware core as used
+by other SoCs.
+
 config PCI_MVEBU
bool Marvell EBU PCIe controller
depends on ARCH_MVEBU || ARCH_DOVE || ARCH_KIRKWOOD
diff --git a/drivers/pci/host/Makefile b/drivers/pci/host/Makefile
index 13fb333..5216f55 100644
--- a/drivers/pci/host/Makefile
+++ b/drivers/pci/host/Makefile
@@ -1,4 +1,5 @@
 obj-$(CONFIG_PCIE_DW) += pcie-designware.o
+obj-$(CONFIG_PCI_DRA7XX) += pci-dra7xx.o
 obj-$(CONFIG_PCI_EXYNOS) += pci-exynos.o
 obj-$(CONFIG_PCI_IMX6) += pci-imx6.o
 obj-$(CONFIG_PCI_MVEBU) += pci-mvebu.o
diff --git a/drivers/pci/host/pci-dra7xx.c b/drivers/pci/host/pci-dra7xx.c
new file mode 100644
index 000..a37c25c
--- /dev/null
+++ b/drivers/pci/host/pci-dra7xx.c
@@ -0,0 +1,385 @@
+/*
+ * pcie-dra7xx - PCIe controller driver for TI DRA7xx SoCs
+ *
+ * Copyright (C) 2013-2014 Texas Instruments Incorporated - http://www.ti.com
+ *
+ * Authors: Kishon Vijay Abraham I kis...@ti.com
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#include linux/delay.h
+#include linux/err.h
+#include linux/interrupt.h
+#include linux/kernel.h
+#include linux/module.h
+#include linux/pci.h
+#include linux/phy/phy.h
+#include linux/platform_device.h
+#include linux/pm_runtime.h
+#include linux/resource.h
+#include linux/types.h
+
+#include pcie-designware.h
+
+/* PCIe controller wrapper DRA7XX configuration registers */
+
+#definePCIECTRL_DRA7XX_CONF_IRQSTATUS_MAIN 0x0024
+#definePCIECTRL_DRA7XX_CONF_IRQENABLE_SET_MAIN 0x0028
+#defineERR_SYS BIT(0)
+#defineERR_FATAL   BIT(1)
+#defineERR_NONFATALBIT(2)
+#defineERR_COR BIT(3)
+#defineERR_AXI BIT(4)
+#defineERR_ECRCBIT(5)
+#definePME_TURN_OFF

Re: [PATCH 05/17] pci: host: pcie-dra7xx: add support for pcie-dra7xx controller

2014-05-06 Thread Marek Vasut
On Tuesday, May 06, 2014 at 03:33:51 PM, Kishon Vijay Abraham I wrote:
 Added support for pcie controller in dra7xx. This driver re-uses
 the designware core code that is already present in kernel.

[...]

 +#define to_dra7xx_pcie(x)container_of((x), struct dra7xx_pcie, pp)
 +
 +static inline u32 dra7xx_pcie_readl(void __iomem *base, u32 offset)

Just pass struct dra7xx_pcie * instead of *base here , it will make the code 
below shorter.

 +{
 + return readl(base + offset);
 +}
 +
 +static inline void dra7xx_pcie_writel(void __iomem *base, u32 offset, u32
 value) +{

DTTO.

 + writel(value, base + offset);
 +}
 +
 +static int dra7xx_pcie_link_up(struct pcie_port *pp)
 +{
 + struct dra7xx_pcie *dra7xx = to_dra7xx_pcie(pp);
 + u32 reg = dra7xx_pcie_readl(dra7xx-base, PCIECTRL_DRA7XX_CONF_PHY_CS);
 +
 + if (reg  LINK_UP)
 + return true;
 + return false;

return reg  LINK_UP;

 +}
 +
 +static int dra7xx_pcie_establish_link(struct pcie_port *pp)
 +{
 + u32 reg;
 + int retries = 1000;
 + struct dra7xx_pcie *dra7xx = to_dra7xx_pcie(pp);
 +
 + if (dw_pcie_link_up(pp)) {
 + dev_err(pp-dev, link is already up\n);

This will spew, since the .link_up (and thus this function) can be called 
repeatedly. The subsystem will query if the link is up via this function.

 + return 0;
 + }
 +
 + reg = dra7xx_pcie_readl(dra7xx-base, PCIECTRL_DRA7XX_CONF_DEVICE_CMD);
 + reg |= LTSSM_EN;
 + dra7xx_pcie_writel(dra7xx-base, PCIECTRL_DRA7XX_CONF_DEVICE_CMD, reg);
 +
 + while (--retries) {

Use retries--

 + reg = dra7xx_pcie_readl(dra7xx-base,
 + PCIECTRL_DRA7XX_CONF_PHY_CS);
 + if (reg  LINK_UP)
 + break;
 + usleep_range(10, 20);
 + }
 +
 + if (retries = 0) {

Then check if retries == 0 and retries can be unsigned int.

 + dev_err(pp-dev, link is not up\n);
 + return -ETIMEDOUT;
 + }
 +
 + return 0;
 +}
[...]
 +static int __init dra7xx_pcie_probe(struct platform_device *pdev)
 +{
 + u32 reg;
 + int ret;
 + int irq;
 + struct phy *phy;
 + void __iomem *base;
 + struct resource *res;
 + struct dra7xx_pcie *dra7xx;
 + struct device *dev = pdev-dev;
 +
 + dra7xx = devm_kzalloc(pdev-dev, sizeof(*dra7xx), GFP_KERNEL);
 + if (!dra7xx)
 + return -ENOMEM;
 +
 + irq = platform_get_irq(pdev, 0);
 + if (irq  0) {
 + dev_err(dev, missing IRQ resource\n);
 + return -EINVAL;
 + }
 +
 + ret = devm_request_irq(pdev-dev, irq, dra7xx_pcie_irq_handler,
 +IRQF_SHARED, dra7xx-pcie-main, dra7xx);
 + if (ret) {
 + dev_err(pdev-dev, failed to request irq\n);
 + return ret;
 + }
 +
 + res = platform_get_resource_byname(pdev, IORESOURCE_MEM, ti_conf);
 + base = devm_ioremap_nocache(dev, res-start, resource_size(res));
 + if (!base)
 + return -ENOMEM;
 +
 + phy = devm_phy_get(dev, pcie-phy);
 + if (IS_ERR(phy))
 + return PTR_ERR(phy);
 +
 + ret = phy_init(phy);
 + if (ret  0)
 + return ret;
 +
 + ret = phy_power_on(phy);
 + if (ret  0)
 + goto err_power_on;
 +
 + dra7xx-base = base;
 + dra7xx-phy = phy;
 + dra7xx-dev = dev;
 +
 + pm_runtime_enable(pdev-dev);
 + ret = pm_runtime_get_sync(pdev-dev);
 + if (IS_ERR_VALUE(ret)) {
 + dev_err(dev, pm_runtime_get_sync failed\n);
 + goto err_runtime_get;
 + }
 +
 + reg = dra7xx_pcie_readl(dra7xx-base, PCIECTRL_DRA7XX_CONF_DEVICE_CMD);
 + reg = ~LTSSM_EN;
 + dra7xx_pcie_writel(dra7xx-base, PCIECTRL_DRA7XX_CONF_DEVICE_CMD, reg);

platform_set_drvdata() should be here, before you add the port.

 + ret = add_pcie_port(dra7xx, pdev);
 + if (ret  0)
 + goto err_add_port;
 +
 + platform_set_drvdata(pdev, dra7xx);
 + return 0;
[...]
--
To unsubscribe from this list: send the line unsubscribe linux-omap in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 05/17] pci: host: pcie-dra7xx: add support for pcie-dra7xx controller

2014-05-06 Thread Arnd Bergmann
On Tuesday 06 May 2014 19:03:51 Kishon Vijay Abraham I wrote:
 Added support for pcie controller in dra7xx. This driver re-uses
 the designware core code that is already present in kernel.
 
 Cc: Bjorn Helgaas bhelg...@google.com
 Cc: Mohit Kumar mohit.ku...@st.com
 Cc: Jingoo Han jg1@samsung.com
 Cc: Marek Vasut ma...@denx.de
 Signed-off-by: Kishon Vijay Abraham I kis...@ti.com

Looks pretty good overall, just a few details I noticed:

 diff --git a/Documentation/devicetree/bindings/pci/ti-pci.txt 
 b/Documentation/devicetree/bindings/pci/ti-pci.txt
 new file mode 100644
 index 000..6cb6f09
 --- /dev/null
 +++ b/Documentation/devicetree/bindings/pci/ti-pci.txt
 @@ -0,0 +1,33 @@
 +TI PCI Controllers
 +
 +PCIe Designware Controller
 +This node should have the properties described in designware-pcie.txt.
 + - compatible: Should be ti,dra7xx-pcie

No xx in compatible strings please. Just make name this after the first
chip to use this particular interface.

 + - reg : Address and length of the register set for the device.
 + - reg-names : ti_conf for the TI specific registers and rc_dbics for the
 +   designware registers.

The description uses inconsistent quotation marks. You should also have
a fixed order in the binding, such as

 - reg : Two register ranges as listed in the reg-names property
 - reg-names : The first entry must be ti-conf for the TI specific registers
   The second entry must be rc-dbics for the designware pcie 
registers.

 + - phys : the phandle for the PHY device (used by generic PHY framework)
 + - phy-names : the names of the PHY corresponding to the PHYs present in the
 +   *phy* phandle.

It's not just a phandle, it can be any phy specifier including additional
argument cells.

The second line should just read

 - phy-names : must be pcie-phy

 diff --git a/drivers/pci/host/Kconfig b/drivers/pci/host/Kconfig
 index a6f67ec..7be6393 100644
 --- a/drivers/pci/host/Kconfig
 +++ b/drivers/pci/host/Kconfig
 @@ -1,6 +1,16 @@
  menu PCI host controller drivers
   depends on PCI
  
 +config PCI_DRA7XX
 + bool TI DRA7xx PCIe controller
 + select PCIE_DW
 + depends on OF || HAS_IOMEM || TI_PIPE3

I think you mean , not || here.

 +static inline u32 x(void __iomem *base, u32 offset)
 +{
 + return readl(base + offset);
 +}
 +
 +static inline void dra7xx_pcie_writel(void __iomem *base, u32 offset, u32 
 value)
 +{
 + writel(value, base + offset);
 +}

These don't actually seem to add any value, you need more characters
to call the inline function than to open-code it.

 +static void dra7xx_pcie_enable_interrupts(struct pcie_port *pp)
 +{
 + struct dra7xx_pcie *dra7xx = to_dra7xx_pcie(pp);
 +
 + dra7xx_pcie_writel(dra7xx-base, PCIECTRL_DRA7XX_CONF_IRQSTATUS_MAIN,
 +~INTERRUPTS);
 + dra7xx_pcie_writel(dra7xx-base,
 +PCIECTRL_DRA7XX_CONF_IRQENABLE_SET_MAIN, INTERRUPTS);
 + dra7xx_pcie_writel(dra7xx-base, PCIECTRL_DRA7XX_CONF_IRQSTATUS_MSI,
 +~LEG_EP_INTERRUPTS  ~MSI);
 +
 + if (IS_ENABLED(CONFIG_PCI_MSI))
 + dra7xx_pcie_writel(dra7xx-base,
 +PCIECTRL_DRA7XX_CONF_IRQENABLE_SET_MSI, MSI);
 + else
 + dra7xx_pcie_writel(dra7xx-base,
 +PCIECTRL_DRA7XX_CONF_IRQENABLE_SET_MSI,
 +LEG_EP_INTERRUPTS);

Doesn't this just enable one or the other? In general I'd assume you need
both INTx and MSI, at least if MSI is available.

It probably doesn't hurt to always turn them all on.

 +static int add_pcie_port(struct dra7xx_pcie *dra7xx,
 +   struct platform_device *pdev)
 +{
 + int ret;
 + struct pcie_port *pp;
 + struct resource *res;
 + struct device *dev = pdev-dev;
 +
 + pp = dra7xx-pp;
 + pp-dev = dev;
 + pp-ops = dra7xx_pcie_host_ops;
 +
 + spin_lock_init(pp-conf_lock);
 +
 + pp-irq = platform_get_irq(pdev, 1);
 + if (pp-irq  0) {
 + dev_err(dev, missing IRQ resource\n);
 + return -EINVAL;
 + }


The binding does not list a mandatory interrupts property, so
this should not be treated as an error.

 +static int __init dra7xx_pcie_probe(struct platform_device *pdev)
 +{
 + irq = platform_get_irq(pdev, 0);
 + if (irq  0) {
 + dev_err(dev, missing IRQ resource\n);
 + return -EINVAL;
 + }
 +
 + ret = devm_request_irq(pdev-dev, irq, dra7xx_pcie_irq_handler,
 +IRQF_SHARED, dra7xx-pcie-main, dra7xx);
 + if (ret) {
 + dev_err(pdev-dev, failed to request irq\n);
 + return ret;
 + }

Same here.

 +
 + res = platform_get_resource_byname(pdev, IORESOURCE_MEM, ti_conf);
 + base = devm_ioremap_nocache(dev, res-start, resource_size(res));

Just use devm_ioremap() instead of devm_ioremap_nocache(). The second
one is just there for historic reasons, and they always do the same

Re: [PATCH 05/17] pci: host: pcie-dra7xx: add support for pcie-dra7xx controller

2014-05-06 Thread Jason Gunthorpe
On Tue, May 06, 2014 at 07:03:51PM +0530, Kishon Vijay Abraham I wrote:
 +Example:
 +pcie@5100 {
 + compatible = ti,dra7xx-pcie;
 + reg = 0x51002000 0x14c, 0x5100 0x2000;
 + reg-names = ti_conf, rc_dbics;
 + interrupts = 0 232 0x4, 0 233 0x4;
 + #address-cells = 3;
 + #size-cells = 2;
 + device_type = pci;
 + ti,device_type = 3;
 + ranges = 0x0800 0 0x20001000 0x20001000 0 0x2000  /* 
 Configuration Space */

Configuration space should not show up in the ranges, please don't
copy that mistake from other drivers, put it in reg.

 + interrupt-map-mask = 0 0 0 0;
 + interrupt-map = 0x0 0 gic 134;

The HW cannot decode INTA/B/C/D?

 +#define  PCIECTRL_DRA7XX_CONF_IRQSTATUS_MSI  0x0034
 +#define  PCIECTRL_DRA7XX_CONF_IRQENABLE_SET_MSI  0x0038
 +#define  INTABIT(0)
 +#define  INTBBIT(1)
 +#define  INTCBIT(2)
 +#define  INTDBIT(3)
 +#define  MSI BIT(4)
 +#define  LEG_EP_INTERRUPTS (INTA | INTB | INTC | INTD)

Oh, it can, it would be wise to export this from the driver. Look at
the latest patches from Srikanth Thokala for the Xilinx PCI driver to
see how this should look

 +static int dra7xx_pcie_establish_link(struct pcie_port *pp)
 +{
 + u32 reg;
 + int retries = 1000;
 + struct dra7xx_pcie *dra7xx = to_dra7xx_pcie(pp);
 +
 + if (dw_pcie_link_up(pp)) {
 + dev_err(pp-dev, link is already up\n);
 + return 0;
 + }
 +
 + reg = dra7xx_pcie_readl(dra7xx-base, PCIECTRL_DRA7XX_CONF_DEVICE_CMD);
 + reg |= LTSSM_EN;
 + dra7xx_pcie_writel(dra7xx-base, PCIECTRL_DRA7XX_CONF_DEVICE_CMD, reg);
 +
 + while (--retries) {
 + reg = dra7xx_pcie_readl(dra7xx-base,
 + PCIECTRL_DRA7XX_CONF_PHY_CS);
 + if (reg  LINK_UP)
 + break;
 + usleep_range(10, 20);
 + }
 +
 + if (retries = 0) {
 + dev_err(pp-dev, link is not up\n);
 + return -ETIMEDOUT;
 + }
 +
 + return 0;
 +}

It would be really nice to see the link bring up process live in the
PCI core, every driver seems to have its own take on this.

The PCI-E spec requires a 100ms delay after link bring up (aka hot
reset) before sending any configuration TLPs.

Jason
--
To unsubscribe from this list: send the line unsubscribe linux-omap in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html