Re: [PATCH 07/17] usb: musb: omap2430: use *syscon* framework to write to mailbox register

2015-06-24 Thread Kishon Vijay Abraham I
Hi,

On Wednesday 24 June 2015 05:09 PM, Roger Quadros wrote:
> On Tue, 23 Jun 2015 17:28:52 +0530
> Kishon Vijay Abraham I  wrote:
> 
>> Deprecate using phy-omap-control driver to write to the mailbox register
>> and start using *syscon* framework to do the same.
>>
>> Signed-off-by: Kishon Vijay Abraham I 
>> ---
>>  Documentation/devicetree/bindings/usb/omap-usb.txt |7 +-
>>  drivers/usb/musb/omap2430.c|  118 
>> 
>>  2 files changed, 102 insertions(+), 23 deletions(-)
>>
>> diff --git a/Documentation/devicetree/bindings/usb/omap-usb.txt 
>> b/Documentation/devicetree/bindings/usb/omap-usb.txt
>> index 38d9bb8..c001306 100644
>> --- a/Documentation/devicetree/bindings/usb/omap-usb.txt
>> +++ b/Documentation/devicetree/bindings/usb/omap-usb.txt
>> @@ -20,10 +20,15 @@ OMAP MUSB GLUE
>>   - phy-names : the names of the PHY corresponding to the PHYs present in the
>> *phy* phandle.
>>  
>> -Optional properties:
>> +Optional Properties:
>> +Deprecated properties:
>>   - ctrl-module : phandle of the control module this glue uses to write to
>> mailbox
>>  
>> +Recommended properies:
>> + - syscon-otghs : phandle/offset pair. Phandle to the system control module 
>> and the
>> +   register offset of the mailbox.
>> +
>>  SOC specific device node entry
>>  usb_otg_hs: usb_otg_hs@4a0ab000 {
>>  compatible = "ti,omap4-musb";
>> diff --git a/drivers/usb/musb/omap2430.c b/drivers/usb/musb/omap2430.c
>> index cc752d8..bcd6d1e 100644
>> --- a/drivers/usb/musb/omap2430.c
>> +++ b/drivers/usb/musb/omap2430.c
>> @@ -39,16 +39,27 @@
>>  #include 
>>  #include 
>>  #include 
>> +#include 
>> +#include 
>>  
>>  #include "musb_core.h"
>>  #include "omap2430.h"
>>  
>> +#define OMAP2430_MUSB_MODE_MASK 0x1f
>> +#define OMAP2430_MUSB_AVALID(0x1 << 0)
>> +#define OMAP2430_MUSB_BVALID(0x1 << 1)
>> +#define OMAP2430_MUSB_VBUSVALID (0x1 << 2)
>> +#define OMAP2430_MUSB_SESSEND   (0x1 << 3)
>> +#define OMAP2430_MUSB_IDDIG (0x1 << 4)
>> +
>>  struct omap2430_glue {
>>  struct device   *dev;
>>  struct platform_device  *musb;
>>  enum omap_musb_vbus_id_status status;
>>  struct work_struct  omap_musb_mailbox_work;
>>  struct device   *control_otghs;
>> +struct regmap   *syscon_otghs; /* ctrl. reg. acces */
>> +unsigned intotghs_reg; /* otghs reg. index within syscon */
>>  };
>>  #define glue_to_musb(g) platform_get_drvdata(g->musb)
>>  
>> @@ -253,6 +264,47 @@ void omap_musb_mailbox(enum omap_musb_vbus_id_status 
>> status)
>>  }
>>  EXPORT_SYMBOL_GPL(omap_musb_mailbox);
>>  
>> +static void omap2430_musb_set_usbmode(struct omap2430_glue *glue,
>> +  enum omap_control_usb_mode mode)
>> +{
>> +u32 val;
>> +int ret;
>> +
>> +if (glue->syscon_otghs) {
>> +switch (mode) {
>> +case USB_MODE_HOST:
>> +val = OMAP2430_MUSB_AVALID | OMAP2430_MUSB_VBUSVALID;
>> +break;
>> +
>> +case USB_MODE_DEVICE:
>> +val = OMAP2430_MUSB_IDDIG | OMAP2430_MUSB_AVALID |
>> +OMAP2430_MUSB_VBUSVALID;
>> +break;
>> +
>> +case USB_MODE_DISCONNECT:
>> +val = OMAP2430_MUSB_IDDIG | OMAP2430_MUSB_SESSEND;
>> +break;
>> +
>> +default:
>> +dev_dbg(glue->dev, "Invalid mode\n");
>> +goto err_regmap_update;
>> +}
>> +
>> +ret = regmap_update_bits(glue->syscon_otghs,
>> + glue->otghs_reg,
>> + OMAP2430_MUSB_MODE_MASK, val);
>> +if (ret < 0)
>> +goto err_regmap_update;
>> +} else {
>> +omap_control_usb_set_mode(glue->control_otghs, mode);
>> +}
>> +
>> +return;
>> +
>> +err_regmap_update:
>> +dev_err(glue->dev, "Failed to set mode to %d\n", mode);
>> +}
>> +
>>  static void omap_musb_set_mailbox(struct omap2430_glue *glue)
>>  {
>>  struct musb *musb = glue_to_musb(glue);
>> @@ -270,8 +322,7 @@ static void omap_musb_set_mailbox(struct omap2430_glue 
>> *glue)
>>  musb->xceiv->last_event = USB_EVENT_ID;
>>  if (musb->gadget_driver) {
>>  pm_runtime_get_sync(dev);
>> -omap_control_usb_set_mode(glue->control_otghs,
>> -USB_MODE_HOST);
>> +omap2430_musb_set_usbmode(glue, USB_MODE_HOST);
>>  omap2430_musb_set_vbus(musb, 1);
>>  }
>>  break;
>> @@ -284,7 +335,7 @@ static void omap_musb_set_mailbox(struct omap2430_glue 
>> *glue)
>>  musb->xceiv->last_event = USB_EVENT_VBUS;
>>  if (musb->gadget_driver)
>>  pm_runtime_get_sync(dev);
>> -omap_control_usb_set_mode(gl

Re: [PATCH 07/17] usb: musb: omap2430: use *syscon* framework to write to mailbox register

2015-06-24 Thread Kishon Vijay Abraham I
Hi Tony,

On Wednesday 24 June 2015 05:19 PM, Tony Lindgren wrote:
> * Kishon Vijay Abraham I  [150623 05:02]:
>> Deprecate using phy-omap-control driver to write to the mailbox register
>> and start using *syscon* framework to do the same.
> 
> All this stuff needs to go to some generic syscon USB phy
> driver. Let's not start adding phy specific stuff to a USB
> driver.

Mailbox register is actually part of OMAP USB glue that should be written in
order to inform the usbmode to the MUSB core.

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 07/17] usb: musb: omap2430: use *syscon* framework to write to mailbox register

2015-06-24 Thread Tony Lindgren
* Kishon Vijay Abraham I  [150623 05:02]:
> Deprecate using phy-omap-control driver to write to the mailbox register
> and start using *syscon* framework to do the same.

All this stuff needs to go to some generic syscon USB phy
driver. Let's not start adding phy specific stuff to a USB
driver.

Regards,

Tony
--
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 07/17] usb: musb: omap2430: use *syscon* framework to write to mailbox register

2015-06-24 Thread Roger Quadros
On Tue, 23 Jun 2015 17:28:52 +0530
Kishon Vijay Abraham I  wrote:

> Deprecate using phy-omap-control driver to write to the mailbox register
> and start using *syscon* framework to do the same.
> 
> Signed-off-by: Kishon Vijay Abraham I 
> ---
>  Documentation/devicetree/bindings/usb/omap-usb.txt |7 +-
>  drivers/usb/musb/omap2430.c|  118 
> 
>  2 files changed, 102 insertions(+), 23 deletions(-)
> 
> diff --git a/Documentation/devicetree/bindings/usb/omap-usb.txt 
> b/Documentation/devicetree/bindings/usb/omap-usb.txt
> index 38d9bb8..c001306 100644
> --- a/Documentation/devicetree/bindings/usb/omap-usb.txt
> +++ b/Documentation/devicetree/bindings/usb/omap-usb.txt
> @@ -20,10 +20,15 @@ OMAP MUSB GLUE
>   - phy-names : the names of the PHY corresponding to the PHYs present in the
> *phy* phandle.
>  
> -Optional properties:
> +Optional Properties:
> +Deprecated properties:
>   - ctrl-module : phandle of the control module this glue uses to write to
> mailbox
>  
> +Recommended properies:
> + - syscon-otghs : phandle/offset pair. Phandle to the system control module 
> and the
> +   register offset of the mailbox.
> +
>  SOC specific device node entry
>  usb_otg_hs: usb_otg_hs@4a0ab000 {
>   compatible = "ti,omap4-musb";
> diff --git a/drivers/usb/musb/omap2430.c b/drivers/usb/musb/omap2430.c
> index cc752d8..bcd6d1e 100644
> --- a/drivers/usb/musb/omap2430.c
> +++ b/drivers/usb/musb/omap2430.c
> @@ -39,16 +39,27 @@
>  #include 
>  #include 
>  #include 
> +#include 
> +#include 
>  
>  #include "musb_core.h"
>  #include "omap2430.h"
>  
> +#define OMAP2430_MUSB_MODE_MASK  0x1f
> +#define OMAP2430_MUSB_AVALID (0x1 << 0)
> +#define OMAP2430_MUSB_BVALID (0x1 << 1)
> +#define OMAP2430_MUSB_VBUSVALID  (0x1 << 2)
> +#define OMAP2430_MUSB_SESSEND(0x1 << 3)
> +#define OMAP2430_MUSB_IDDIG  (0x1 << 4)
> +
>  struct omap2430_glue {
>   struct device   *dev;
>   struct platform_device  *musb;
>   enum omap_musb_vbus_id_status status;
>   struct work_struct  omap_musb_mailbox_work;
>   struct device   *control_otghs;
> + struct regmap   *syscon_otghs; /* ctrl. reg. acces */
> + unsigned intotghs_reg; /* otghs reg. index within syscon */
>  };
>  #define glue_to_musb(g)  platform_get_drvdata(g->musb)
>  
> @@ -253,6 +264,47 @@ void omap_musb_mailbox(enum omap_musb_vbus_id_status 
> status)
>  }
>  EXPORT_SYMBOL_GPL(omap_musb_mailbox);
>  
> +static void omap2430_musb_set_usbmode(struct omap2430_glue *glue,
> +   enum omap_control_usb_mode mode)
> +{
> + u32 val;
> + int ret;
> +
> + if (glue->syscon_otghs) {
> + switch (mode) {
> + case USB_MODE_HOST:
> + val = OMAP2430_MUSB_AVALID | OMAP2430_MUSB_VBUSVALID;
> + break;
> +
> + case USB_MODE_DEVICE:
> + val = OMAP2430_MUSB_IDDIG | OMAP2430_MUSB_AVALID |
> + OMAP2430_MUSB_VBUSVALID;
> + break;
> +
> + case USB_MODE_DISCONNECT:
> + val = OMAP2430_MUSB_IDDIG | OMAP2430_MUSB_SESSEND;
> + break;
> +
> + default:
> + dev_dbg(glue->dev, "Invalid mode\n");
> + goto err_regmap_update;
> + }
> +
> + ret = regmap_update_bits(glue->syscon_otghs,
> +  glue->otghs_reg,
> +  OMAP2430_MUSB_MODE_MASK, val);
> + if (ret < 0)
> + goto err_regmap_update;
> + } else {
> + omap_control_usb_set_mode(glue->control_otghs, mode);
> + }
> +
> + return;
> +
> +err_regmap_update:
> + dev_err(glue->dev, "Failed to set mode to %d\n", mode);
> +}
> +
>  static void omap_musb_set_mailbox(struct omap2430_glue *glue)
>  {
>   struct musb *musb = glue_to_musb(glue);
> @@ -270,8 +322,7 @@ static void omap_musb_set_mailbox(struct omap2430_glue 
> *glue)
>   musb->xceiv->last_event = USB_EVENT_ID;
>   if (musb->gadget_driver) {
>   pm_runtime_get_sync(dev);
> - omap_control_usb_set_mode(glue->control_otghs,
> - USB_MODE_HOST);
> + omap2430_musb_set_usbmode(glue, USB_MODE_HOST);
>   omap2430_musb_set_vbus(musb, 1);
>   }
>   break;
> @@ -284,7 +335,7 @@ static void omap_musb_set_mailbox(struct omap2430_glue 
> *glue)
>   musb->xceiv->last_event = USB_EVENT_VBUS;
>   if (musb->gadget_driver)
>   pm_runtime_get_sync(dev);
> - omap_control_usb_set_mode(glue->control_otghs, USB_MODE_DEVICE);
> + omap2430_musb_set_usbmode(glue, USB_MODE_DEVICE);
>   break;
>  
>   case OMAP_MUSB_ID

[PATCH 07/17] usb: musb: omap2430: use *syscon* framework to write to mailbox register

2015-06-23 Thread Kishon Vijay Abraham I
Deprecate using phy-omap-control driver to write to the mailbox register
and start using *syscon* framework to do the same.

Signed-off-by: Kishon Vijay Abraham I 
---
 Documentation/devicetree/bindings/usb/omap-usb.txt |7 +-
 drivers/usb/musb/omap2430.c|  118 
 2 files changed, 102 insertions(+), 23 deletions(-)

diff --git a/Documentation/devicetree/bindings/usb/omap-usb.txt 
b/Documentation/devicetree/bindings/usb/omap-usb.txt
index 38d9bb8..c001306 100644
--- a/Documentation/devicetree/bindings/usb/omap-usb.txt
+++ b/Documentation/devicetree/bindings/usb/omap-usb.txt
@@ -20,10 +20,15 @@ OMAP MUSB GLUE
  - phy-names : the names of the PHY corresponding to the PHYs present in the
*phy* phandle.
 
-Optional properties:
+Optional Properties:
+Deprecated properties:
  - ctrl-module : phandle of the control module this glue uses to write to
mailbox
 
+Recommended properies:
+ - syscon-otghs : phandle/offset pair. Phandle to the system control module 
and the
+   register offset of the mailbox.
+
 SOC specific device node entry
 usb_otg_hs: usb_otg_hs@4a0ab000 {
compatible = "ti,omap4-musb";
diff --git a/drivers/usb/musb/omap2430.c b/drivers/usb/musb/omap2430.c
index cc752d8..bcd6d1e 100644
--- a/drivers/usb/musb/omap2430.c
+++ b/drivers/usb/musb/omap2430.c
@@ -39,16 +39,27 @@
 #include 
 #include 
 #include 
+#include 
+#include 
 
 #include "musb_core.h"
 #include "omap2430.h"
 
+#define OMAP2430_MUSB_MODE_MASK0x1f
+#define OMAP2430_MUSB_AVALID   (0x1 << 0)
+#define OMAP2430_MUSB_BVALID   (0x1 << 1)
+#define OMAP2430_MUSB_VBUSVALID(0x1 << 2)
+#define OMAP2430_MUSB_SESSEND  (0x1 << 3)
+#define OMAP2430_MUSB_IDDIG(0x1 << 4)
+
 struct omap2430_glue {
struct device   *dev;
struct platform_device  *musb;
enum omap_musb_vbus_id_status status;
struct work_struct  omap_musb_mailbox_work;
struct device   *control_otghs;
+   struct regmap   *syscon_otghs; /* ctrl. reg. acces */
+   unsigned intotghs_reg; /* otghs reg. index within syscon */
 };
 #define glue_to_musb(g)platform_get_drvdata(g->musb)
 
@@ -253,6 +264,47 @@ void omap_musb_mailbox(enum omap_musb_vbus_id_status 
status)
 }
 EXPORT_SYMBOL_GPL(omap_musb_mailbox);
 
+static void omap2430_musb_set_usbmode(struct omap2430_glue *glue,
+ enum omap_control_usb_mode mode)
+{
+   u32 val;
+   int ret;
+
+   if (glue->syscon_otghs) {
+   switch (mode) {
+   case USB_MODE_HOST:
+   val = OMAP2430_MUSB_AVALID | OMAP2430_MUSB_VBUSVALID;
+   break;
+
+   case USB_MODE_DEVICE:
+   val = OMAP2430_MUSB_IDDIG | OMAP2430_MUSB_AVALID |
+   OMAP2430_MUSB_VBUSVALID;
+   break;
+
+   case USB_MODE_DISCONNECT:
+   val = OMAP2430_MUSB_IDDIG | OMAP2430_MUSB_SESSEND;
+   break;
+
+   default:
+   dev_dbg(glue->dev, "Invalid mode\n");
+   goto err_regmap_update;
+   }
+
+   ret = regmap_update_bits(glue->syscon_otghs,
+glue->otghs_reg,
+OMAP2430_MUSB_MODE_MASK, val);
+   if (ret < 0)
+   goto err_regmap_update;
+   } else {
+   omap_control_usb_set_mode(glue->control_otghs, mode);
+   }
+
+   return;
+
+err_regmap_update:
+   dev_err(glue->dev, "Failed to set mode to %d\n", mode);
+}
+
 static void omap_musb_set_mailbox(struct omap2430_glue *glue)
 {
struct musb *musb = glue_to_musb(glue);
@@ -270,8 +322,7 @@ static void omap_musb_set_mailbox(struct omap2430_glue 
*glue)
musb->xceiv->last_event = USB_EVENT_ID;
if (musb->gadget_driver) {
pm_runtime_get_sync(dev);
-   omap_control_usb_set_mode(glue->control_otghs,
-   USB_MODE_HOST);
+   omap2430_musb_set_usbmode(glue, USB_MODE_HOST);
omap2430_musb_set_vbus(musb, 1);
}
break;
@@ -284,7 +335,7 @@ static void omap_musb_set_mailbox(struct omap2430_glue 
*glue)
musb->xceiv->last_event = USB_EVENT_VBUS;
if (musb->gadget_driver)
pm_runtime_get_sync(dev);
-   omap_control_usb_set_mode(glue->control_otghs, USB_MODE_DEVICE);
+   omap2430_musb_set_usbmode(glue, USB_MODE_DEVICE);
break;
 
case OMAP_MUSB_ID_FLOAT:
@@ -301,8 +352,7 @@ static void omap_musb_set_mailbox(struct omap2430_glue 
*glue)
if (data->interface_type == MUSB_INTERFACE_UTMI)
otg_set_vbus(musb->xceiv->otg, 0);
 
-