* [PATCH 1/2] usb: renesas_usbhs: add R-Car Gen. 2 init and power control
@ 2014-07-08 14:59 Ulrich Hecht
2014-07-08 14:59 ` [PATCH 2/2] ARM: shmobile: lager: remove USBHS callbacks Ulrich Hecht
2014-07-09 0:08 ` [PATCH 1/2] usb: renesas_usbhs: add R-Car Gen. 2 init and power control Kuninori Morimoto
0 siblings, 2 replies; 4+ messages in thread
From: Ulrich Hecht @ 2014-07-08 14:59 UTC (permalink / raw)
To: linux-arm-kernel
In preparation for DT conversion to reduce reliance on platform device
callbacks.
Signed-off-by: Ulrich Hecht <ulrich.hecht+renesas@gmail.com>
---
drivers/usb/renesas_usbhs/Makefile | 2 +-
drivers/usb/renesas_usbhs/common.c | 39 ++++++++++++++++---
drivers/usb/renesas_usbhs/rcar2.c | 76 ++++++++++++++++++++++++++++++++++++++
drivers/usb/renesas_usbhs/rcar2.h | 4 ++
include/linux/usb/renesas_usbhs.h | 8 ++++
5 files changed, 123 insertions(+), 6 deletions(-)
create mode 100644 drivers/usb/renesas_usbhs/rcar2.c
create mode 100644 drivers/usb/renesas_usbhs/rcar2.h
diff --git a/drivers/usb/renesas_usbhs/Makefile b/drivers/usb/renesas_usbhs/Makefile
index bc8aef4..9e47f47 100644
--- a/drivers/usb/renesas_usbhs/Makefile
+++ b/drivers/usb/renesas_usbhs/Makefile
@@ -4,7 +4,7 @@
obj-$(CONFIG_USB_RENESAS_USBHS) += renesas_usbhs.o
-renesas_usbhs-y := common.o mod.o pipe.o fifo.o
+renesas_usbhs-y := common.o mod.o pipe.o fifo.o rcar2.o
ifneq ($(CONFIG_USB_RENESAS_USBHS_HCD),)
renesas_usbhs-y += mod_host.o
diff --git a/drivers/usb/renesas_usbhs/common.c b/drivers/usb/renesas_usbhs/common.c
index 17267b0..619a3bb 100644
--- a/drivers/usb/renesas_usbhs/common.c
+++ b/drivers/usb/renesas_usbhs/common.c
@@ -15,12 +15,14 @@
*
*/
#include <linux/err.h>
+#include <linux/gpio.h>
#include <linux/io.h>
#include <linux/module.h>
#include <linux/pm_runtime.h>
#include <linux/slab.h>
#include <linux/sysfs.h>
#include "common.h"
+#include "rcar2.h"
/*
* image of renesas_usbhs
@@ -423,8 +425,7 @@ static int usbhs_probe(struct platform_device *pdev)
int ret;
/* check platform information */
- if (!info ||
- !info->platform_callback.get_id) {
+ if (!info) {
dev_err(&pdev->dev, "no platform information\n");
return -EINVAL;
}
@@ -451,13 +452,27 @@ static int usbhs_probe(struct platform_device *pdev)
/*
* care platform info
*/
- memcpy(&priv->pfunc,
- &info->platform_callback,
- sizeof(struct renesas_usbhs_platform_callback));
+
memcpy(&priv->dparam,
&info->driver_param,
sizeof(struct renesas_usbhs_driver_param));
+ switch (priv->dparam.type) {
+ case USBHS_TYPE_R8A7790:
+ case USBHS_TYPE_R8A7791:
+ priv->pfunc = usbhs_rcar2_ops;
+ break;
+ default:
+ if (!info->platform_callback.get_id) {
+ dev_err(&pdev->dev, "no platform callbacks");
+ return -EINVAL;
+ }
+ memcpy(&priv->pfunc,
+ &info->platform_callback,
+ sizeof(struct renesas_usbhs_platform_callback));
+ break;
+ }
+
/* set driver callback functions for platform */
dfunc = &info->driver_callback;
dfunc->notify_hotplug = usbhsc_drvcllbck_notify_hotplug;
@@ -507,6 +522,20 @@ static int usbhs_probe(struct platform_device *pdev)
*/
usbhs_sys_clock_ctrl(priv, 0);
+ /* check GPIO determining if USB function should be enabled */
+ if (priv->dparam.enable_gpio) {
+ gpio_request_one(priv->dparam.enable_gpio, GPIOF_IN, NULL);
+ ret = !gpio_get_value(priv->dparam.enable_gpio);
+ gpio_free(priv->dparam.enable_gpio);
+ if (ret) {
+ dev_warn(&pdev->dev,
+ "USB function not selected (GPIO %d)\n",
+ priv->dparam.enable_gpio);
+ ret = -ENOTSUPP;
+ goto probe_end_mod_exit;
+ }
+ }
+
/*
* platform call
*
diff --git a/drivers/usb/renesas_usbhs/rcar2.c b/drivers/usb/renesas_usbhs/rcar2.c
new file mode 100644
index 0000000..069704c
--- /dev/null
+++ b/drivers/usb/renesas_usbhs/rcar2.c
@@ -0,0 +1,76 @@
+/*
+ * Renesas USB driver R-Car Gen. 2 initialization and power control
+ *
+ * Copyright (C) 2014 Ulrich Hecht
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ */
+
+#include <linux/gpio.h>
+#include <linux/of_gpio.h>
+#include <linux/platform_data/gpio-rcar.h>
+#include <linux/usb/phy.h>
+#include "common.h"
+
+static int usbhs_rcar2_hardware_init(struct platform_device *pdev)
+{
+ struct renesas_usbhs_platform_info *info = dev_get_platdata(&pdev->dev);
+ struct usb_phy *phy;
+
+ phy = usb_get_phy_dev(&pdev->dev, 0);
+ if (IS_ERR(phy))
+ return PTR_ERR(phy);
+
+ info->phy = phy;
+ return 0;
+}
+
+static int usbhs_rcar2_hardware_exit(struct platform_device *pdev)
+{
+ struct renesas_usbhs_platform_info *info = dev_get_platdata(&pdev->dev);
+
+ if (!info->phy)
+ return 0;
+
+ usb_put_phy(info->phy);
+ info->phy = NULL;
+
+ return 0;
+}
+
+static int usbhs_rcar2_power_ctrl(struct platform_device *pdev,
+ void __iomem *base, int enable)
+{
+ struct renesas_usbhs_platform_info *info = dev_get_platdata(&pdev->dev);
+
+ if (!info->phy)
+ return -ENODEV;
+
+ if (enable) {
+ int retval = usb_phy_init(info->phy);
+
+ if (!retval)
+ retval = usb_phy_set_suspend(info->phy, 0);
+ return retval;
+ }
+
+ usb_phy_set_suspend(info->phy, 1);
+ usb_phy_shutdown(info->phy);
+ return 0;
+}
+
+static int usbhs_rcar2_get_id(struct platform_device *pdev)
+{
+ return USBHS_GADGET;
+}
+
+const struct renesas_usbhs_platform_callback usbhs_rcar2_ops = {
+ .hardware_init = usbhs_rcar2_hardware_init,
+ .hardware_exit = usbhs_rcar2_hardware_exit,
+ .power_ctrl = usbhs_rcar2_power_ctrl,
+ .get_id = usbhs_rcar2_get_id,
+};
diff --git a/drivers/usb/renesas_usbhs/rcar2.h b/drivers/usb/renesas_usbhs/rcar2.h
new file mode 100644
index 0000000..f07f10d
--- /dev/null
+++ b/drivers/usb/renesas_usbhs/rcar2.h
@@ -0,0 +1,4 @@
+#include "common.h"
+
+extern const struct renesas_usbhs_platform_callback
+ usbhs_rcar2_ops;
diff --git a/include/linux/usb/renesas_usbhs.h b/include/linux/usb/renesas_usbhs.h
index e452ba6..750f0cd 100644
--- a/include/linux/usb/renesas_usbhs.h
+++ b/include/linux/usb/renesas_usbhs.h
@@ -153,6 +153,9 @@ struct renesas_usbhs_driver_param {
*/
int pio_dma_border; /* default is 64byte */
+ u32 type;
+ u32 enable_gpio;
+
/*
* option:
*/
@@ -160,6 +163,9 @@ struct renesas_usbhs_driver_param {
u32 has_sudmac:1; /* for SUDMAC */
};
+#define USBHS_TYPE_R8A7790 1
+#define USBHS_TYPE_R8A7791 2
+
/*
* option:
*
@@ -186,6 +192,8 @@ struct renesas_usbhs_platform_info {
* driver use these param for some register
*/
struct renesas_usbhs_driver_param driver_param;
+
+ struct usb_phy *phy;
};
/*
--
1.8.4.5
^ permalink raw reply related [flat|nested] 4+ messages in thread* [PATCH 2/2] ARM: shmobile: lager: remove USBHS callbacks
2014-07-08 14:59 [PATCH 1/2] usb: renesas_usbhs: add R-Car Gen. 2 init and power control Ulrich Hecht
@ 2014-07-08 14:59 ` Ulrich Hecht
2014-07-09 0:08 ` [PATCH 1/2] usb: renesas_usbhs: add R-Car Gen. 2 init and power control Kuninori Morimoto
1 sibling, 0 replies; 4+ messages in thread
From: Ulrich Hecht @ 2014-07-08 14:59 UTC (permalink / raw)
To: linux-arm-kernel
Let the driver handle initialization and power control.
Signed-off-by: Ulrich Hecht <ulrich.hecht+renesas@gmail.com>
---
arch/arm/mach-shmobile/board-lager.c | 109 +++++------------------------------
1 file changed, 15 insertions(+), 94 deletions(-)
diff --git a/arch/arm/mach-shmobile/board-lager.c b/arch/arm/mach-shmobile/board-lager.c
index b8b2b44..0138bc5 100644
--- a/arch/arm/mach-shmobile/board-lager.c
+++ b/arch/arm/mach-shmobile/board-lager.c
@@ -420,84 +420,6 @@ static const struct resource usbhs_resources[] __initconst = {
DEFINE_RES_IRQ(gic_spi(107)),
};
-struct usbhs_private {
- struct renesas_usbhs_platform_info info;
- struct usb_phy *phy;
-};
-
-#define usbhs_get_priv(pdev) \
- container_of(renesas_usbhs_get_info(pdev), struct usbhs_private, info)
-
-static int usbhs_power_ctrl(struct platform_device *pdev,
- void __iomem *base, int enable)
-{
- struct usbhs_private *priv = usbhs_get_priv(pdev);
-
- if (!priv->phy)
- return -ENODEV;
-
- if (enable) {
- int retval = usb_phy_init(priv->phy);
-
- if (!retval)
- retval = usb_phy_set_suspend(priv->phy, 0);
- return retval;
- }
-
- usb_phy_set_suspend(priv->phy, 1);
- usb_phy_shutdown(priv->phy);
- return 0;
-}
-
-static int usbhs_hardware_init(struct platform_device *pdev)
-{
- struct usbhs_private *priv = usbhs_get_priv(pdev);
- struct usb_phy *phy;
- int ret;
-
- /* USB0 Function - use PWEN as GPIO input to detect DIP Switch SW5
- * setting to avoid VBUS short circuit due to wrong cable.
- * PWEN should be pulled up high if USB Function is selected by SW5
- */
- gpio_request_one(RCAR_GP_PIN(5, 18), GPIOF_IN, NULL); /* USB0_PWEN */
- if (!gpio_get_value(RCAR_GP_PIN(5, 18))) {
- pr_warn("Error: USB Function not selected - check SW5 + SW6\n");
- ret = -ENOTSUPP;
- goto error;
- }
-
- phy = usb_get_phy_dev(&pdev->dev, 0);
- if (IS_ERR(phy)) {
- ret = PTR_ERR(phy);
- goto error;
- }
-
- priv->phy = phy;
- return 0;
- error:
- gpio_free(RCAR_GP_PIN(5, 18));
- return ret;
-}
-
-static int usbhs_hardware_exit(struct platform_device *pdev)
-{
- struct usbhs_private *priv = usbhs_get_priv(pdev);
-
- if (!priv->phy)
- return 0;
-
- usb_put_phy(priv->phy);
- priv->phy = NULL;
-
- gpio_free(RCAR_GP_PIN(5, 18));
- return 0;
-}
-
-static int usbhs_get_id(struct platform_device *pdev)
-{
- return USBHS_GADGET;
-}
-
static u32 lager_usbhs_pipe_type[] = {
USB_ENDPOINT_XFER_CONTROL,
USB_ENDPOINT_XFER_ISOC,
@@ -517,20 +439,19 @@ static u32 lager_usbhs_pipe_type[] = {
USB_ENDPOINT_XFER_BULK,
};
-static struct usbhs_private usbhs_priv __initdata = {
- .info = {
- .platform_callback = {
- .power_ctrl = usbhs_power_ctrl,
- .hardware_init = usbhs_hardware_init,
- .hardware_exit = usbhs_hardware_exit,
- .get_id = usbhs_get_id,
- },
- .driver_param = {
- .buswait_bwait = 4,
- .pipe_type = lager_usbhs_pipe_type,
- .pipe_size = ARRAY_SIZE(lager_usbhs_pipe_type),
- },
- }
+static struct renesas_usbhs_platform_info usbhs_info __initdata = {
+ .driver_param = {
+ .buswait_bwait = 4,
+ .type = USBHS_TYPE_R8A7790,
+ .pipe_type = lager_usbhs_pipe_type,
+ .pipe_size = ARRAY_SIZE(lager_usbhs_pipe_type),
+ /* USB0 Function - use PWEN as GPIO input to detect DIP
+ * Switch SW5 setting to avoid VBUS short circuit due to
+ * wrong cable. PWEN should be pulled up high if USB
+ * Function is selected by SW5.
+ */
+ .enable_gpio = RCAR_GP_PIN(5, 18),
+ },
};
static void __init lager_register_usbhs(void)
@@ -540,8 +461,8 @@ static void __init lager_register_usbhs(void)
"renesas_usbhs", -1,
usbhs_resources,
ARRAY_SIZE(usbhs_resources),
- &usbhs_priv.info,
- sizeof(usbhs_priv.info));
+ &usbhs_info,
+ sizeof(usbhs_info));
}
/* USBHS PHY */
--
1.8.4.5
^ permalink raw reply related [flat|nested] 4+ messages in thread* [PATCH 1/2] usb: renesas_usbhs: add R-Car Gen. 2 init and power control
2014-07-08 14:59 [PATCH 1/2] usb: renesas_usbhs: add R-Car Gen. 2 init and power control Ulrich Hecht
2014-07-08 14:59 ` [PATCH 2/2] ARM: shmobile: lager: remove USBHS callbacks Ulrich Hecht
@ 2014-07-09 0:08 ` Kuninori Morimoto
2014-07-09 10:11 ` Ulrich Hecht
1 sibling, 1 reply; 4+ messages in thread
From: Kuninori Morimoto @ 2014-07-09 0:08 UTC (permalink / raw)
To: linux-arm-kernel
Hi Ulrich
Thank you for your patch
> In preparation for DT conversion to reduce reliance on platform device
> callbacks.
>
> Signed-off-by: Ulrich Hecht <ulrich.hecht+renesas@gmail.com>
> ---
(snip)
> @@ -186,6 +192,8 @@ struct renesas_usbhs_platform_info {
> * driver use these param for some register
> */
> struct renesas_usbhs_driver_param driver_param;
> +
> + struct usb_phy *phy;
> };
Using renesas_usbhs_platform_info for *phy is not good idea from my point of view.
Because its memory is located on platform side.
(this is the reason why usbhs_probe() using memcpy() for getting info->xxx)
I guess struct usbhs_priv is good place,
and you can use usbhs_pdev_to_priv() for this purpose ?
Best regards
---
Kuninori Morimoto
^ permalink raw reply [flat|nested] 4+ messages in thread* [PATCH 1/2] usb: renesas_usbhs: add R-Car Gen. 2 init and power control
2014-07-09 0:08 ` [PATCH 1/2] usb: renesas_usbhs: add R-Car Gen. 2 init and power control Kuninori Morimoto
@ 2014-07-09 10:11 ` Ulrich Hecht
0 siblings, 0 replies; 4+ messages in thread
From: Ulrich Hecht @ 2014-07-09 10:11 UTC (permalink / raw)
To: linux-arm-kernel
On Wed, Jul 9, 2014 at 2:08 AM, Kuninori Morimoto
<kuninori.morimoto.gx@gmail.com> wrote:
>
> Hi Ulrich
>
> Thank you for your patch
Thank you for your review.
>> @@ -186,6 +192,8 @@ struct renesas_usbhs_platform_info {
>> * driver use these param for some register
>> */
>> struct renesas_usbhs_driver_param driver_param;
>> +
>> + struct usb_phy *phy;
>> };
>
> Using renesas_usbhs_platform_info for *phy is not good idea from my point of view.
> Because its memory is located on platform side.
> (this is the reason why usbhs_probe() using memcpy() for getting info->xxx)
>
> I guess struct usbhs_priv is good place,
> and you can use usbhs_pdev_to_priv() for this purpose ?
Yes, that seems more natural anyway.
CU
Uli
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2014-07-09 10:11 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-07-08 14:59 [PATCH 1/2] usb: renesas_usbhs: add R-Car Gen. 2 init and power control Ulrich Hecht
2014-07-08 14:59 ` [PATCH 2/2] ARM: shmobile: lager: remove USBHS callbacks Ulrich Hecht
2014-07-09 0:08 ` [PATCH 1/2] usb: renesas_usbhs: add R-Car Gen. 2 init and power control Kuninori Morimoto
2014-07-09 10:11 ` Ulrich Hecht
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).