linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] davinci: DA850 EVM: OHCI platform code
@ 2011-12-21  7:20 Manjunathappa, Prakash
  2011-12-21  9:56 ` Nori, Sekhar
  0 siblings, 1 reply; 6+ messages in thread
From: Manjunathappa, Prakash @ 2011-12-21  7:20 UTC (permalink / raw)
  To: davinci-linux-open-source
  Cc: nsekhar, linux-kernel, linux-arm-kernel, linux, Ajay Kumar Gupta,
	Manjunathappa, Prakash

From: Ajay Kumar Gupta <ajay.gupta@ti.com>

On this board the OHCI port's power control and over-current signals from
TPS2065 power switch are connected via GPIO2[4] and GPIO6[13] respectively,
so we can implement the DA8xx OHCI glue layer's hooks for overriding the
root hub port's power and over-current status bits.

We also have to properly set up the clocking mode in the CFGCHIP2 register,
so that internal 24 MHz reference clock is fed to the USB 2.0 (MUSB) PHY and
its output is used to clock the USB 1.1 (OHCI) PHY...

Signed-off-by: Ajay Kumar Gupta <ajay.gupta@ti.com>
Signed-off-by: Manjunathappa, Prakash <prakash.pm@ti.com>
---
Since v1:
Fixed Sergei's review comments.

 arch/arm/mach-davinci/board-da850-evm.c |  125 +++++++++++++++++++++++++++++++
 1 files changed, 125 insertions(+), 0 deletions(-)

diff --git a/arch/arm/mach-davinci/board-da850-evm.c b/arch/arm/mach-davinci/board-da850-evm.c
index 6659a90..c505992 100644
--- a/arch/arm/mach-davinci/board-da850-evm.c
+++ b/arch/arm/mach-davinci/board-da850-evm.c
@@ -22,6 +22,7 @@
 #include <linux/gpio.h>
 #include <linux/gpio_keys.h>
 #include <linux/platform_device.h>
+#include <linux/interrupt.h>
 #include <linux/mtd/mtd.h>
 #include <linux/mtd/nand.h>
 #include <linux/mtd/partitions.h>
@@ -42,6 +43,7 @@
 #include <mach/nand.h>
 #include <mach/mux.h>
 #include <mach/aemif.h>
+#include <mach/usb.h>
 #include <mach/spi.h>
 
 #define DA850_EVM_PHY_ID		"0:00"
@@ -734,6 +736,126 @@ static struct davinci_i2c_platform_data da850_evm_i2c_0_pdata = {
 	.bus_delay	= 0,	/* usec */
 };
 
+/*
+ * USB1 VBUS is controlled by GPIO2[4], over-current is reported on GPIO6[13].
+ */
+#define ON_BD_USB_DRV	GPIO_TO_PIN(2, 4)
+#define ON_BD_USB_OVC	GPIO_TO_PIN(6, 13)
+
+static const short da850_evm_usb11_pins[] = {
+	DA850_GPIO2_4, DA850_GPIO6_13,
+	-1
+};
+
+static da8xx_ocic_handler_t da850_evm_usb_ocic_handler;
+
+static int da850_evm_usb_set_power(unsigned port, int on)
+{
+	gpio_set_value(ON_BD_USB_DRV, on);
+	return 0;
+}
+
+static int da850_evm_usb_get_power(unsigned port)
+{
+	return gpio_get_value(ON_BD_USB_DRV);
+}
+
+static int da850_evm_usb_get_oci(unsigned port)
+{
+	return !gpio_get_value(ON_BD_USB_OVC);
+}
+
+static irqreturn_t da850_evm_usb_ocic_irq(int, void *);
+
+static int da850_evm_usb_ocic_notify(da8xx_ocic_handler_t handler)
+{
+	int irq		= gpio_to_irq(ON_BD_USB_OVC);
+	int error	= 0;
+
+	if (handler != NULL) {
+		da850_evm_usb_ocic_handler = handler;
+
+		error = request_irq(irq, da850_evm_usb_ocic_irq,
+				    IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING,
+				    "OHCI over-current indicator", NULL);
+		if (error)
+			printk(KERN_ERR "%s: could not request IRQ to watch "
+			       "over-current indicator changes\n", __func__);
+	} else
+		free_irq(irq, NULL);
+
+	return error;
+}
+
+static struct da8xx_ohci_root_hub da850_evm_usb11_pdata = {
+	.set_power	= da850_evm_usb_set_power,
+	.get_power	= da850_evm_usb_get_power,
+	.get_oci	= da850_evm_usb_get_oci,
+	.ocic_notify	= da850_evm_usb_ocic_notify,
+
+	/* TPS2065 switch @ 5V */
+	.potpgt		= (3 + 1) / 2,	/* 3 ms max */
+};
+
+static irqreturn_t da850_evm_usb_ocic_irq(int irq, void *dev_id)
+{
+	da850_evm_usb_ocic_handler(&da850_evm_usb11_pdata, 1);
+	return IRQ_HANDLED;
+}
+
+static __init void da850_evm_usb_init(void)
+{
+	u32 cfgchip2;
+	int ret;
+
+	/*
+	 * Set up USB clock/mode in the CFGCHIP2 register.
+	 * FYI:  CFGCHIP2 is 0x0000ef00 initially.
+	 */
+	cfgchip2 = __raw_readl(DA8XX_SYSCFG0_VIRT(DA8XX_CFGCHIP2_REG));
+
+	/* USB2.0 PHY reference clock is 24 MHz */
+	cfgchip2 &= ~CFGCHIP2_REFFREQ;
+	cfgchip2 |=  CFGCHIP2_REFFREQ_24MHZ;
+
+	/*
+	 * Select internal reference clock for USB 2.0 PHY
+	 * and use it as a clock source for USB 1.1 PHY
+	 * (this is the default setting anyway).
+	 */
+	cfgchip2 &= ~CFGCHIP2_USB1PHYCLKMUX;
+	cfgchip2 |=  CFGCHIP2_USB2PHYCLKMUX;
+
+	__raw_writel(cfgchip2, DA8XX_SYSCFG0_VIRT(DA8XX_CFGCHIP2_REG));
+
+	ret = davinci_cfg_reg_list(da850_evm_usb11_pins);
+	if (ret) {
+		pr_warning("%s: USB 1.1 PinMux setup failed: %d\n",
+			   __func__, ret);
+		return;
+	}
+
+	ret = gpio_request_one(ON_BD_USB_DRV, GPIOF_OUT_INIT_LOW,
+			"ON_BD_USB_DRV");
+	if (ret) {
+		pr_err("%s: failed to request GPIO for USB 1.1 port "
+		       "power control: %d\n", __func__, ret);
+		return;
+	}
+
+	ret = gpio_request_one(ON_BD_USB_OVC, GPIOF_IN, "ON_BD_USB_OVC");
+	if (ret) {
+		pr_err("%s: failed to request GPIO for USB 1.1 port "
+		       "over-current indicator: %d\n", __func__, ret);
+		return;
+	}
+
+	ret = da8xx_register_usb11(&da850_evm_usb11_pdata);
+	if (ret)
+		pr_warning("%s: USB 1.1 registration failed: %d\n",
+			   __func__, ret);
+}
+
 static struct davinci_uart_config da850_evm_uart_config __initdata = {
 	.enabled_uarts = 0x7,
 };
@@ -1386,6 +1508,9 @@ static __init void da850_evm_init(void)
 				ret);
 
 	da850_evm_setup_mac_addr();
+
+	/* initilaize usb module */
+	da850_evm_usb_init();
 }
 
 #ifdef CONFIG_SERIAL_8250_CONSOLE
-- 
1.7.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* RE: [PATCH v2] davinci: DA850 EVM: OHCI platform code
  2011-12-21  7:20 [PATCH v2] davinci: DA850 EVM: OHCI platform code Manjunathappa, Prakash
@ 2011-12-21  9:56 ` Nori, Sekhar
  2011-12-21 12:05   ` Sergei Shtylyov
  0 siblings, 1 reply; 6+ messages in thread
From: Nori, Sekhar @ 2011-12-21  9:56 UTC (permalink / raw)
  To: Manjunathappa, Prakash, davinci-linux-open-source, Sergei Shtylyov
  Cc: linux-kernel, linux-arm-kernel, linux, Gupta, Ajay Kumar

Hi Prakash,

On Wed, Dec 21, 2011 at 12:50:02, Manjunathappa, Prakash wrote:
> From: Ajay Kumar Gupta <ajay.gupta@ti.com>
> 
> On this board the OHCI port's power control and over-current signals from
> TPS2065 power switch are connected via GPIO2[4] and GPIO6[13] respectively,
> so we can implement the DA8xx OHCI glue layer's hooks for overriding the
> root hub port's power and over-current status bits.
> 
> We also have to properly set up the clocking mode in the CFGCHIP2 register,
> so that internal 24 MHz reference clock is fed to the USB 2.0 (MUSB) PHY and
> its output is used to clock the USB 1.1 (OHCI) PHY...
> 
> Signed-off-by: Ajay Kumar Gupta <ajay.gupta@ti.com>
> Signed-off-by: Manjunathappa, Prakash <prakash.pm@ti.com>

This is the third copy of OHCI platform setup code which is almost
the same except for the GPIO numbers. Can we attempt to consolidate
the GPIO case under drivers/usb/host/ohci-da8xx.c glue layer itself?
Of course, here should be a provision for non-GPIO based implementation
as well.

Sergei, any thoughts, comments?

Thanks,
Sekhar

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v2] davinci: DA850 EVM: OHCI platform code
  2011-12-21  9:56 ` Nori, Sekhar
@ 2011-12-21 12:05   ` Sergei Shtylyov
  2011-12-21 12:24     ` Sergei Shtylyov
  0 siblings, 1 reply; 6+ messages in thread
From: Sergei Shtylyov @ 2011-12-21 12:05 UTC (permalink / raw)
  To: Nori, Sekhar
  Cc: Manjunathappa, Prakash, davinci-linux-open-source, linux-kernel,
	linux-arm-kernel, linux, Gupta, Ajay Kumar

Hello.

On 21-12-2011 13:56, Nori, Sekhar wrote:

> On Wed, Dec 21, 2011 at 12:50:02, Manjunathappa, Prakash wrote:
>> From: Ajay Kumar Gupta<ajay.gupta@ti.com>

>> On this board the OHCI port's power control and over-current signals from
>> TPS2065 power switch are connected via GPIO2[4] and GPIO6[13] respectively,
>> so we can implement the DA8xx OHCI glue layer's hooks for overriding the
>> root hub port's power and over-current status bits.

>> We also have to properly set up the clocking mode in the CFGCHIP2 register,
>> so that internal 24 MHz reference clock is fed to the USB 2.0 (MUSB) PHY and
>> its output is used to clock the USB 1.1 (OHCI) PHY...

>> Signed-off-by: Ajay Kumar Gupta<ajay.gupta@ti.com>
>> Signed-off-by: Manjunathappa, Prakash<prakash.pm@ti.com>

> This is the third copy of OHCI platform setup code which is almost
> the same except for the GPIO numbers.

    Well, in my counting, it's only second, DA830 EVM being the first one.
What's the third?

> Can we attempt to consolidate
> the GPIO case under drivers/usb/host/ohci-da8xx.c glue layer itself?
> Of course, here should be a provision for non-GPIO based implementation
> as well.

> Sergei, any thoughts, comments?

    I designed the hub interface to be as abstract as I could, and now you're 
proposing to add GPIO to it? No, I have no clear idea how to keeep it abstract 
and add GPIO support at the same time. I would have been grateful to
TI if I didn't have to invent this at all and they stop saving on OHCI pins.

> Thanks,
> Sekhar

WBR, Sergei

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v2] davinci: DA850 EVM: OHCI platform code
  2011-12-21 12:05   ` Sergei Shtylyov
@ 2011-12-21 12:24     ` Sergei Shtylyov
  2011-12-22 12:27       ` Nori, Sekhar
  0 siblings, 1 reply; 6+ messages in thread
From: Sergei Shtylyov @ 2011-12-21 12:24 UTC (permalink / raw)
  To: Nori, Sekhar
  Cc: Manjunathappa, Prakash, davinci-linux-open-source, linux-kernel,
	linux-arm-kernel, linux, Gupta, Ajay Kumar

Hello.

On 21-12-2011 16:05, I wrote:

>> On Wed, Dec 21, 2011 at 12:50:02, Manjunathappa, Prakash wrote:
>>> From: Ajay Kumar Gupta<ajay.gupta@ti.com>

>>> On this board the OHCI port's power control and over-current signals from
>>> TPS2065 power switch are connected via GPIO2[4] and GPIO6[13] respectively,
>>> so we can implement the DA8xx OHCI glue layer's hooks for overriding the
>>> root hub port's power and over-current status bits.

>>> We also have to properly set up the clocking mode in the CFGCHIP2 register,
>>> so that internal 24 MHz reference clock is fed to the USB 2.0 (MUSB) PHY and
>>> its output is used to clock the USB 1.1 (OHCI) PHY...

>>> Signed-off-by: Ajay Kumar Gupta<ajay.gupta@ti.com>
>>> Signed-off-by: Manjunathappa, Prakash<prakash.pm@ti.com>

>> This is the third copy of OHCI platform setup code which is almost
>> the same except for the GPIO numbers.

> Well, in my counting, it's only second, DA830 EVM being the first one.
> What's the third?

    Ah, I missed Hawkboard... :-)

 >    I designed the hub interface to be as abstract as I could, and now you're
 > proposing to add GPIO to it? No, I have no clear idea how to keeep it
 > abstract and add GPIO support at the same time. I would have been grateful to
 > TI if I didn't have to invent this at all and they stop saving on OHCI pins.

    Well, I have one idea. We can create a separate module in 
arch/arm/mach-davinci/, named say ohci.c, put the shared code there and pass 
to it the GPIOs actually used via a function call. Or maybe use existing 
arch/arm/mach-davinci/usb.c.

WBR, Sergei

^ permalink raw reply	[flat|nested] 6+ messages in thread

* RE: [PATCH v2] davinci: DA850 EVM: OHCI platform code
  2011-12-21 12:24     ` Sergei Shtylyov
@ 2011-12-22 12:27       ` Nori, Sekhar
  2011-12-23 13:15         ` Manjunathappa, Prakash
  0 siblings, 1 reply; 6+ messages in thread
From: Nori, Sekhar @ 2011-12-22 12:27 UTC (permalink / raw)
  To: Sergei Shtylyov, Manjunathappa, Prakash
  Cc: davinci-linux-open-source, linux-kernel, linux-arm-kernel, linux,
	Gupta, Ajay Kumar

On Wed, Dec 21, 2011 at 17:54:49, Sergei Shtylyov wrote:
> Hello.
> 
> On 21-12-2011 16:05, I wrote:
> 
> >> On Wed, Dec 21, 2011 at 12:50:02, Manjunathappa, Prakash wrote:
> >>> From: Ajay Kumar Gupta<ajay.gupta@ti.com>
> 
> >>> On this board the OHCI port's power control and over-current signals from
> >>> TPS2065 power switch are connected via GPIO2[4] and GPIO6[13] respectively,
> >>> so we can implement the DA8xx OHCI glue layer's hooks for overriding the
> >>> root hub port's power and over-current status bits.
> 
> >>> We also have to properly set up the clocking mode in the CFGCHIP2 register,
> >>> so that internal 24 MHz reference clock is fed to the USB 2.0 (MUSB) PHY and
> >>> its output is used to clock the USB 1.1 (OHCI) PHY...
> 
> >>> Signed-off-by: Ajay Kumar Gupta<ajay.gupta@ti.com>
> >>> Signed-off-by: Manjunathappa, Prakash<prakash.pm@ti.com>
> 
> >> This is the third copy of OHCI platform setup code which is almost
> >> the same except for the GPIO numbers.
> 
> > Well, in my counting, it's only second, DA830 EVM being the first one.
> > What's the third?
> 
>     Ah, I missed Hawkboard... :-)
> 
>  >    I designed the hub interface to be as abstract as I could, and now you're
>  > proposing to add GPIO to it? No, I have no clear idea how to keeep it
>  > abstract and add GPIO support at the same time. I would have been grateful to
>  > TI if I didn't have to invent this at all and they stop saving on OHCI pins.
> 
>     Well, I have one idea. We can create a separate module in 
> arch/arm/mach-davinci/, named say ohci.c, put the shared code there and pass 
> to it the GPIOs actually used via a function call. Or maybe use existing 
> arch/arm/mach-davinci/usb.c.

Thanks Sergei. I think using the existing usb.c would be a better idea.

Prakash,

Can you please go ahead with this approach and post updated patches.

Thanks,
Sekhar

^ permalink raw reply	[flat|nested] 6+ messages in thread

* RE: [PATCH v2] davinci: DA850 EVM: OHCI platform code
  2011-12-22 12:27       ` Nori, Sekhar
@ 2011-12-23 13:15         ` Manjunathappa, Prakash
  0 siblings, 0 replies; 6+ messages in thread
From: Manjunathappa, Prakash @ 2011-12-23 13:15 UTC (permalink / raw)
  To: Nori, Sekhar, Sergei Shtylyov
  Cc: davinci-linux-open-source, linux-kernel, linux-arm-kernel, linux,
	Gupta, Ajay Kumar

On Thu, Dec 22, 2011 at 17:57:16, Nori, Sekhar wrote:
[...]
> > 
> >     Well, I have one idea. We can create a separate module in 
> > arch/arm/mach-davinci/, named say ohci.c, put the shared code there and pass 
> > to it the GPIOs actually used via a function call. Or maybe use existing 
> > arch/arm/mach-davinci/usb.c.
> 
> Thanks Sergei. I think using the existing usb.c would be a better idea.
> 
> Prakash,
> 
> Can you please go ahead with this approach and post updated patches.
> 
> Thanks,
> Sekhar
> 

Ok I will create abstract function and post the new set of patches.

Thanks,
Prakash

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2011-12-23 13:15 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-12-21  7:20 [PATCH v2] davinci: DA850 EVM: OHCI platform code Manjunathappa, Prakash
2011-12-21  9:56 ` Nori, Sekhar
2011-12-21 12:05   ` Sergei Shtylyov
2011-12-21 12:24     ` Sergei Shtylyov
2011-12-22 12:27       ` Nori, Sekhar
2011-12-23 13:15         ` Manjunathappa, Prakash

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).