usb: musb: add driver for control module
Subsystems (8)
cover usb: musb: add driver for control module
Added a new driver for the usb part of control module. This has an API to power on the USB2 phy and an API to write to the mailbox depending on whether MUSB has to act in host mode or in device mode.
Writing to control module registers for doing the above task which was previously done in omap glue and in omap-usb2 phy is removed.
Changes from RFC:
* Used "#if IS_ENABLED(CONFIG_OMAP_CONTROL_USB)" instead of "#if (defined(CONFIG_OMAP_CONTROL_USB) || \
defined(CONFIG_OMAP_CONTROL_USB_MODULE))"
* return "-EADDRNOTAVAIL" if devm_request_and_ioremap fails.
* Removed the dt data from this patch series (I'll send that as a separate series).
* added "ctrl_module" binding to usb otg glue and usb phy in the Documentaion. This binding is not planned to be used until an actual requirement for it arises.
This series was developed ongit://git.kernel.org/pub/scm/linux/kernel/git/balbi/usb.git xceiv
Did basic enumeration testing in omap4 panda, omap4 sdp and omap3 beagle.
Kishon Vijay Abraham I (4):
drivers: usb: phy: add a new driver for usb part of control module
ARM: OMAP: devices: create device for usb part of control module
ARM: OMAP2: MUSB: Specify omap4 has mailbox
drivers: usb: start using the control module driver
Documentation/devicetree/bindings/usb/omap-usb.txt | 30 ++- Documentation/devicetree/bindings/usb/usb-phy.txt | 12 +- arch/arm/mach-omap2/devices.c | 48 +++++ arch/arm/mach-omap2/omap_hwmod_44xx_data.c | 13 -- arch/arm/mach-omap2/usb-musb.c | 3 + drivers/usb/musb/Kconfig | 1 + drivers/usb/musb/omap2430.c | 64 +++--- drivers/usb/musb/omap2430.h | 9 - drivers/usb/phy/Kconfig | 10 + drivers/usb/phy/Makefile | 1 + drivers/usb/phy/omap-control-usb.c | 204 ++++++++++++++++++++ drivers/usb/phy/omap-usb2.c | 38 +--- include/linux/usb/musb.h | 2 + include/linux/usb/omap_control_usb.h | 72 +++++++ include/linux/usb/omap_usb.h | 4 +- 15 files changed, 411 insertions(+), 100 deletions(-) create mode 100644 drivers/usb/phy/omap-control-usb.c create mode 100644 include/linux/usb/omap_control_usb.h
Signature · 1 line
1.7.9.5
PATCH 1/4 drivers: usb: phy: add a new driver for usb part of control module
Added a new driver for the usb part of control module. This has an API to power on the USB2 phy and an API to write to the mailbox depending on whether MUSB has to act in host mode or in device mode.
Writing to control module registers for doing the above task which was previously done in omap glue and in omap-usb2 phy will be removed.
--- Documentation/devicetree/bindings/usb/omap-usb.txt | 26 ++- Documentation/devicetree/bindings/usb/usb-phy.txt | 5 + drivers/usb/phy/Kconfig | 9 + drivers/usb/phy/Makefile | 1 + drivers/usb/phy/omap-control-usb.c | 204 ++++++++++++++++++++ include/linux/usb/omap_control_usb.h | 72 +++++++ 6 files changed, 316 insertions(+), 1 deletion(-) create mode 100644 drivers/usb/phy/omap-control-usb.c create mode 100644 include/linux/usb/omap_control_usb.h
Documentation/devicetree/bindings/usb/omap-usb.txt +25 -1
@@ -1,4 +1,4 @@ -OMAP GLUE +OMAP GLUE AND OTHER OMAP SPECIFIC COMPONENTS OMAP MUSB GLUE - compatible : Should be "ti,omap4-musb" or "ti,omap3-musb"
@@ -16,6 +16,10 @@ OMAP MUSB GLUE - power : Should be "50". This signifies the controller can supply upto 100mA when operating in host mode. +Optional properties: + - ctrl_module : phandle of the control module this glue uses to write to + mailbox + SOC specific device node entry usb_otg_hs: usb_otg_hs at 4a0ab000 { compatible = "ti,omap4-musb";
@@ -23,6 +27,7 @@ usb_otg_hs: usb_otg_hs at 4a0ab000 { multipoint = <1>; num_eps = <16>; ram_bits = <12>; + ctrl_module = <&omap_control_usb>; }; Board specific device node entry
@@ -31,3 +36,22 @@ Board specific device node entry mode = <3>; power = <50>; }; + +OMAP CONTROL USB + +Required properties: + - compatible: Should be "ti,omap-control-usb" + - reg : Address and length of the register set for the device. It contains + the address of "control_dev_conf" and "otghs_control". + - reg-names: The names of the register addresses corresponding to the registers + filled in "reg". + - ti,has_mailbox: This is used to specify if the platform has mailbox in + control module. + +omap_control_usb: omap-control-usb at 4a002300 { + compatible = "ti,omap-control-usb"; + reg = <0x4a002300 0x4>, + <0x4a00233c 0x4>; + reg-names = "control_dev_conf", "otghs_control"; + ti,has_mailbox; +};
Documentation/devicetree/bindings/usb/usb-phy.txt +5 -0
@@ -8,10 +8,15 @@ Required properties: add the address of control module dev conf register until a driver for control module is added +Optional properties: + - ctrl_module : phandle of the control module used by PHY driver to power on + the PHY. + This is usually a subnode of ocp2scp to which it is connected. usb2phy at 4a0ad080 { compatible = "ti,omap-usb2"; reg = <0x4a0ad080 0x58>, <0x4a002300 0x4>; + ctrl_module = <&omap_control_usb>; };
drivers/usb/phy/Kconfig +9 -0
@@ -14,6 +14,15 @@ config OMAP_USB2 The USB OTG controller communicates with the comparator using this driver. +config OMAP_CONTROL_USB + tristate "OMAP CONTROL USB Driver" + depends on ARCH_OMAP2PLUS + help + Enable this to add support for the USB part present in the control + module. This driver has API to power on the PHY and to write to the + mailbox. The mailbox is present only in omap4 and the register to + power on the PHY is present in omap4 and omap5. + config USB_ISP1301 tristate "NXP ISP1301 USB transceiver support" depends on USB || USB_GADGET
drivers/usb/phy/Makefile +1 -0
@@ -5,6 +5,7 @@ ccflags-$(CONFIG_USB_DEBUG) := -DDEBUG obj-$(CONFIG_OMAP_USB2) += omap-usb2.o +obj-$(CONFIG_OMAP_CONTROL_USB) += omap-control-usb.o obj-$(CONFIG_USB_ISP1301) += isp1301.o obj-$(CONFIG_MV_U3D_PHY) += mv_u3d_phy.o obj-$(CONFIG_USB_EHCI_TEGRA) += tegra_usb_phy.o
drivers/usb/phy/omap-control-usb.c new file +204 -0
204 lines not on this page · raw message
include/linux/usb/omap_control_usb.h new file +72 -0
72 lines not on this page · raw message
Signature · 1 line
1.7.9.5
Re: [PATCH 1/4] drivers: usb: phy: add a new driver for usb part of control module
Hi,
Quoted 157 lines · Kishon Vijay Abraham I
Added a new driver for the usb part of control module. This has an API to power on the USB2 phy and an API to write to the mailbox depending on whether MUSB has to act in host mode or in device mode.
Writing to control module registers for doing the above task which was previously done in omap glue and in omap-usb2 phy will be removed.
Signed-off-by Kishon Vijay Abraham I <[email protected]>--- Documentation/devicetree/bindings/usb/omap-usb.txt | 26 ++- Documentation/devicetree/bindings/usb/usb-phy.txt | 5 + drivers/usb/phy/Kconfig | 9 + drivers/usb/phy/Makefile | 1 + drivers/usb/phy/omap-control-usb.c | 204 ++++++++++++++++++++ include/linux/usb/omap_control_usb.h | 72 +++++++ 6 files changed, 316 insertions(+), 1 deletion(-) create mode 100644 drivers/usb/phy/omap-control-usb.c create mode 100644 include/linux/usb/omap_control_usb.hDocumentation/devicetree/bindings/usb/omap-usb.txt +25
-1@@ -1,4 +1,4 @@ -OMAP GLUE +OMAP GLUE AND OTHER OMAP SPECIFIC COMPONENTS OMAP MUSB GLUE - compatible : Should be "ti,omap4-musb" or "ti,omap3-musb"@@ -16,6 +16,10 @@ OMAP MUSB GLUE - power : Should be "50". This signifies the controller can supply upto 100mA when operating in host mode. +Optional properties: + - ctrl_module : phandle of the control module this glue uses to write to + mailbox + SOC specific device node entry usb_otg_hs: usb_otg_hs at 4a0ab000 { compatible = "ti,omap4-musb";@@ -23,6 +27,7 @@ usb_otg_hs: usb_otg_hs at 4a0ab000 { multipoint = <1>; num_eps = <16>; ram_bits = <12>; + ctrl_module = <&omap_control_usb>; }; Board specific device node entry@@ -31,3 +36,22 @@ Board specific device node entry mode = <3>; power = <50>; }; + +OMAP CONTROL USB + +Required properties: + - compatible: Should be "ti,omap-control-usb" + - reg : Address and length of the register set for the device. It contains + the address of "control_dev_conf" and "otghs_control". + - reg-names: The names of the register addresses corresponding to the registers + filled in "reg". + - ti,has_mailbox: This is used to specify if the platform has mailbox in + control module. + +omap_control_usb: omap-control-usb at 4a002300 { + compatible = "ti,omap-control-usb"; + reg = <0x4a002300 0x4>, + <0x4a00233c 0x4>; + reg-names = "control_dev_conf", "otghs_control"; + ti,has_mailbox; +};Documentation/devicetree/bindings/usb/usb-phy.txt +5
-0@@ -8,10 +8,15 @@ Required properties: add the address of control module dev conf register until a driver for control module is added +Optional properties: + - ctrl_module : phandle of the control module used by PHY driver to power on + the PHY. + This is usually a subnode of ocp2scp to which it is connected. usb2phy at 4a0ad080 { compatible = "ti,omap-usb2"; reg = <0x4a0ad080 0x58>, <0x4a002300 0x4>; + ctrl_module = <&omap_control_usb>; };drivers/usb/phy/Kconfig +9
-0@@ -14,6 +14,15 @@ config OMAP_USB2 The USB OTG controller communicates with the comparator using this driver. +config OMAP_CONTROL_USB + tristate "OMAP CONTROL USB Driver" + depends on ARCH_OMAP2PLUS + help + Enable this to add support for the USB part present in the control + module. This driver has API to power on the PHY and to write to the + mailbox. The mailbox is present only in omap4 and the register to + power on the PHY is present in omap4 and omap5. + config USB_ISP1301 tristate "NXP ISP1301 USB transceiver support" depends on USB || USB_GADGETdrivers/usb/phy/Makefile +1
-0@@ -5,6 +5,7 @@ ccflags-$(CONFIG_USB_DEBUG) := -DDEBUG obj-$(CONFIG_OMAP_USB2) += omap-usb2.o +obj-$(CONFIG_OMAP_CONTROL_USB) += omap-control-usb.o obj-$(CONFIG_USB_ISP1301) += isp1301.o obj-$(CONFIG_MV_U3D_PHY) += mv_u3d_phy.o obj-$(CONFIG_USB_EHCI_TEGRA) += tegra_usb_phy.odrivers/usb/phy/omap-control-usb.c new file +28
-0@@ -0,0 +1,204 @@ +/* +* omap-control-usb.c - The USB part of control module. +* +* Copyright (C) 2013 Texas Instruments Incorporated - http://www.ti.com +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* Author: Kishon Vijay Abraham I <[email protected]> +* +* 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/module.h> +#include <linux/platform_device.h> +#include <linux/slab.h> +#include <linux/of.h> +#include <linux/err.h> +#include <linux/io.h> +#include <linux/usb/omap_control_usb.h> + +static struct omap_control_usb *control_usb; +
drivers/usb/phy/omap-control-usb.c line 38
Quoted 10 lines
drivers/usb/phy/omap-control-usb.c new file +10
-0+/** +* get_omap_control_dev - returns the device pointer for this control device +* +* This API should be called to get the device pointer for this control +* module device. This device pointer should be passed to all other API's +* in this driver. +* +* To be used by PHY driver and glue driver +*/ +struct device *get_omap_control_dev (void )
let's do a small rename here and call it:
omap_get_control_dev(), just to keep consistency with rest of the file.
Quoted 15 lines
drivers/usb/phy/omap-control-usb.c new file +15
-0+{ +if (!control_usb) +return ERR_PTR (-ENODEV ); + +return control_usb->dev; +} +EXPORT_SYMBOL_GPL (get_omap_control_dev); + +/** +* omap_control_usb_phy_power - power on/off the phy using control module reg +* @dev: the control module device +* @on: 0 or 1, based on powering on or off the PHY +*/ +void omap_control_usb_phy_power (struct device *dev,int on) +{
drivers/usb/phy/omap-control-usb.c line 63
Quoted 10 lines
drivers/usb/phy/omap-control-usb.c new file +10
-0+u32 val; +struct omap_control_usb *control_usb =dev_get_drvdata (dev); + +if (on) { + val =readl (control_usb->dev_conf); +if (val &PHY_PD ) +writel (~PHY_PD , control_usb->dev_conf); + }else { +writel (PHY_PD , control_usb->dev_conf); + }
this can be better. I would rather have this:
struct omap_control_usb *ctrl = dev_get_drvdata(dev); u32 val;
val = readl(ctrl->dev_conf);
if (on)
val &= ~OMAP_CTRL_DEV_PHY_PD; else val |= OMAP_CTRL_DEV_PHY_PD;
writel(val, ctrl->dev_conf);
Quoted 8 lines
drivers/usb/phy/omap-control-usb.c new file +8
-0+} +EXPORT_SYMBOL_GPL (omap_control_usb_phy_power); + +/** +* omap_control_usb_host_mode - set AVALID, VBUSVALID and ID pin in grounded +* @dev: struct device * +* +* This is an API to write to the mailbox register to notify the usb core that
drivers/usb/phy/omap-control-usb.c line 81
Quoted 10 lines
drivers/usb/phy/omap-control-usb.c new file +10
-0+* a usb device has been connected. +*/ +void omap_control_usb_host_mode (struct device *dev) +{ +u32 val; +struct omap_control_usb *control_usb =dev_get_drvdata (dev); + + val =AVALID |VBUSVALID ; + +writel (val, control_usb->otghs_control);
I would like to make this future proof too:
val = readl(ctrl->otghs_control);
val |= OMAP_CTRL_DEV_AVALID | OMAP_CTRL_DEV_VBUSVALID; writel(val, ctrl->otghs_control);
drivers/usb/phy/omap-control-usb.c line 98
Quoted 6 lines
drivers/usb/phy/omap-control-usb.c new file +6
-0+void omap_control_usb_device_mode (struct device *dev) +{ +u32 val; +struct omap_control_usb *control_usb =dev_get_drvdata (dev); + + val =IDDIG |AVALID |VBUSVALID ;
ditto. Read it before changing it. (the idea is that in future the other bits might be used for something else, so you risk breaking future functionality).
Quoted 9 lines
drivers/usb/phy/omap-control-usb.c new file +9
-0+ +writel (val, control_usb->otghs_control); +} +EXPORT_SYMBOL_GPL (omap_control_usb_device_mode); + +/** +* omap_control_usb_set_sessionend - Enable SESSIONEND and IDIG to high +* impedance +* @dev: struct device *
drivers/usb/phy/omap-control-usb.c line 117
Quoted 10 lines
drivers/usb/phy/omap-control-usb.c new file +10
-0+* +* This is an API to write to the mailbox register to notify the usb core +* it's now in disconnected state. +*/ +void omap_control_usb_set_sessionend (struct device *dev) +{ +u32 val; +struct omap_control_usb *control_usb =dev_get_drvdata (dev); + + val =SESSEND |IDDIG ;
ditto
drivers/usb/phy/omap-control-usb.c line 130
Quoted 13 lines
drivers/usb/phy/omap-control-usb.c new file +13
-0+ +writel (val, control_usb->otghs_control); +} +EXPORT_SYMBOL_GPL (omap_control_usb_set_sessionend); + +static int omap_control_usb_probe (struct platform_device *pdev) +{ +struct resource *res; +struct device_node *np = pdev->dev.of_node; +struct omap_control_usb_platform_data *pdata = pdev->dev.platform_data; + + control_usb =devm_kzalloc (&pdev->dev,sizeof (*control_usb), +GFP_KERNEL );
you're using space indentation here.
drivers/usb/phy/omap-control-usb.c line 143
Quoted 13 lines
drivers/usb/phy/omap-control-usb.c new file +13
-0+if (!control_usb) { +dev_err (&pdev->dev,"unable to alloc memory for control usb\n" ); +return -ENOMEM ; + } + +if (np) { + control_usb->has_mailbox =of_property_read_bool (np, +"ti,has_mailbox" ); + }else if (pdata) { + control_usb->has_mailbox = pdata->has_mailbox; + }else { +dev_err (&pdev->dev,"no pdata present\n" ); +return -EINVAL ;
does it make sense to default to has_mailbox as true ? I mean, seems like this is how it's going to be in future devices looking at the current trend.
Another idea is to try to get the extra resource below, if it fails you try to continue without it ;-)
drivers/usb/phy/omap-control-usb.c line 149
Quoted 6 lines
drivers/usb/phy/omap-control-usb.c new file +6
-0+ } + + control_usb->dev = &pdev->dev; + + res =platform_get_resource_byname (pdev,IORESOURCE_MEM , +"control_dev_conf" );
using space indentation here again.
Quoted 25 lines
drivers/usb/phy/omap-control-usb.c new file +25
-0+ control_usb->dev_conf =devm_request_and_ioremap (&pdev->dev, res); +if (control_usb->dev_conf ==NULL ) { +dev_err (&pdev->dev,"Failed to obtain io memory\n" ); +return -EADDRNOTAVAIL ; + } + +if (control_usb->has_mailbox) { + res =platform_get_resource_byname (pdev,IORESOURCE_MEM , +"otghs_control" ); + control_usb->otghs_control =devm_request_and_ioremap ( + &pdev->dev, res); +if (control_usb->otghs_control ==NULL ) { +dev_err (&pdev->dev,"Failed to obtain io memory\n" ); +return -EADDRNOTAVAIL ; + } + } + +dev_set_drvdata (control_usb->dev, control_usb); + +return 0 ; +} + +#ifdef CONFIG_OF +static const struct of_device_id omap_control_usb_id_table[] = { + { .compatible = "ti,omap-control-usb" },
drivers/usb/phy/omap-control-usb.c line 184
Quoted 10 lines
drivers/usb/phy/omap-control-usb.c new file +10
-0+ {} +}; +MODULE_DEVICE_TABLE (of, omap_control_usb_id_table); +#endif + +static struct platform_driver omap_control_usb_driver = { + .probe = omap_control_usb_probe, + .driver = { + .name ="omap-control-usb" , + .owner =THIS_MODULE ,
no need to set owner here. When you register the platform_driver, it will be set for you.
Quoted 9 lines
drivers/usb/phy/omap-control-usb.c new file +9
-0+ .of_match_table = of_match_ptr(omap_control_usb_id_table), + }, +}; + +static int __init omap_control_usb_init (void ) +{ +return platform_driver_register (&omap_control_usb_driver); +} +subsys_initcall (omap_control_usb_init);
drivers/usb/phy/omap-control-usb.c line 203
Quoted 10 lines
drivers/usb/phy/omap-control-usb.c new file +10
-0+ +static void __exit omap_control_usb_exit(void) +{ +platform_driver_unregister (&omap_control_usb_driver); +} +module_exit (omap_control_usb_exit); + +MODULE_ALIAS ("platform: omap_control_usb" ); +MODULE_AUTHOR ("Texas Instruments Inc." ); +MODULE_DESCRIPTION ("OMAP CONTROL USB DRIVER" );
don't scream to your users like that ;-)
MODULE_DESCRIPTION("OMAP Control Module USB Driver");
Quoted 38 lines
drivers/usb/phy/omap-control-usb.c new file +1
-0+MODULE_LICENSE ("GPL v2" );include/linux/usb/omap_control_usb.h new file +31
-0@@ -0,0 +1,72 @@ +/* +* omap_control_usb.h - Header file for the USB part of control module. +* +* Copyright (C) 2013 Texas Instruments Incorporated - http://www.ti.com +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* Author: Kishon Vijay Abraham I <[email protected]> +* +* 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. +* +*/ + +#ifndef __OMAP_CONTROL_USB_H__ +#define __OMAP_CONTROL_USB_H__ + +struct omap_control_usb { +struct device *dev; + +u32 __iomem *dev_conf; +u32 __iomem *otghs_control; + +u8 has_mailbox:1 ; +}; + +struct omap_control_usb_platform_data {
include/linux/usb/omap_control_usb.h line 41
Quoted 10 lines
include/linux/usb/omap_control_usb.h new file +10
-0+ u8 has_mailbox:1; +}; + +#define PHY_PD BIT(0) + +#define AVALID BIT(0) +#define BVALID BIT(1) +#define VBUSVALID BIT(2) +#define SESSEND BIT(3) +#define IDDIG BIT(4)
please prepend with OMAP_CTRL_ or something similar.
Signature · 8 lines
balbi -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 836 bytes Desc: Digital signature URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20130118/591f58b0/attachment-0001.sig>
Re: [PATCH 1/4] drivers: usb: phy: add a new driver for usb part of control module
Hi,
Quoted 173 lines · Felipe Balbi
Hi,
Quoted 157 lines · Kishon Vijay Abraham I
Added a new driver for the usb part of control module. This has an API to power on the USB2 phy and an API to write to the mailbox depending on whether MUSB has to act in host mode or in device mode.
Writing to control module registers for doing the above task which was previously done in omap glue and in omap-usb2 phy will be removed.
Signed-off-by Kishon Vijay Abraham I <[email protected]>--- Documentation/devicetree/bindings/usb/omap-usb.txt | 26 ++- Documentation/devicetree/bindings/usb/usb-phy.txt | 5 + drivers/usb/phy/Kconfig | 9 + drivers/usb/phy/Makefile | 1 + drivers/usb/phy/omap-control-usb.c | 204 ++++++++++++++++++++ include/linux/usb/omap_control_usb.h | 72 +++++++ 6 files changed, 316 insertions(+), 1 deletion(-)create mode 100644
drivers/usb/phy/omap-control-usb.ccreate mode 100644include/linux/usb/omap_control_usb.hDocumentation/devicetree/bindings/usb/omap-usb.txt +25
-1@@ -1,4 +1,4 @@ -OMAP GLUE +OMAP GLUE AND OTHER OMAP SPECIFIC COMPONENTS OMAP MUSB GLUE - compatible : Should be "ti,omap4-musb" or "ti,omap3-musb"@@ -16,6 +16,10 @@ OMAP MUSB GLUE - power : Should be "50". This signifies the controller can supply upto 100mA when operating in host mode. +Optional properties: + - ctrl_module : phandle of the control module this glue uses to write to + mailbox + SOC specific device node entry usb_otg_hs: usb_otg_hs at 4a0ab000 { compatible = "ti,omap4-musb";@@ -23,6 +27,7 @@ usb_otg_hs: usb_otg_hs at 4a0ab000 { multipoint = <1>; num_eps = <16>; ram_bits = <12>; + ctrl_module = <&omap_control_usb>; }; Board specific device node entry@@ -31,3 +36,22 @@ Board specific device node entry mode = <3>; power = <50>; }; + +OMAP CONTROL USB + +Required properties: + - compatible: Should be "ti,omap-control-usb" + - reg : Address and length of the register set for the device. It contains + the address of "control_dev_conf" and "otghs_control". + - reg-names: The names of the register addresses corresponding to the registers + filled in "reg". + - ti,has_mailbox: This is used to specify if the platform has mailbox in + control module. + +omap_control_usb: omap-control-usb at 4a002300 { + compatible = "ti,omap-control-usb"; + reg = <0x4a002300 0x4>, + <0x4a00233c 0x4>; + reg-names = "control_dev_conf", "otghs_control"; + ti,has_mailbox; +};Documentation/devicetree/bindings/usb/usb-phy.txt +5
-0@@ -8,10 +8,15 @@ Required properties: add the address of control module dev conf register until a driver for control module is added +Optional properties: + - ctrl_module : phandle of the control module used by PHY driver to power on + the PHY. + This is usually a subnode of ocp2scp to which it is connected. usb2phy at 4a0ad080 { compatible = "ti,omap-usb2"; reg = <0x4a0ad080 0x58>, <0x4a002300 0x4>; + ctrl_module = <&omap_control_usb>; };drivers/usb/phy/Kconfig +9
-0@@ -14,6 +14,15 @@ config OMAP_USB2 The USB OTG controller communicates with the comparator using this driver. +config OMAP_CONTROL_USB + tristate "OMAP CONTROL USB Driver" + depends on ARCH_OMAP2PLUS + help + Enable this to add support for the USB part present in the control + module. This driver has API to power on the PHY and to write to the + mailbox. The mailbox is present only in omap4 and the register to + power on the PHY is present in omap4 and omap5. + config USB_ISP1301 tristate "NXP ISP1301 USB transceiver support" depends on USB || USB_GADGETdrivers/usb/phy/Makefile +1
-0@@ -5,6 +5,7 @@ ccflags-$(CONFIG_USB_DEBUG) := -DDEBUG obj-$(CONFIG_OMAP_USB2) += omap-usb2.o +obj-$(CONFIG_OMAP_CONTROL_USB) += omap-control-usb.o obj-$(CONFIG_USB_ISP1301) += isp1301.o obj-$(CONFIG_MV_U3D_PHY) += mv_u3d_phy.o obj-$(CONFIG_USB_EHCI_TEGRA) += tegra_usb_phy.odrivers/usb/phy/omap-control-usb.c new file +28
-0@@ -0,0 +1,204 @@ +/* +* omap-control-usb.c - The USB part of control module. +* +* Copyright (C) 2013 Texas Instruments Incorporated - http://www.ti.com +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* Author: Kishon Vijay Abraham I <[email protected]> +* +* 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/module.h> +#include <linux/platform_device.h> +#include <linux/slab.h> +#include <linux/of.h> +#include <linux/err.h> +#include <linux/io.h> +#include <linux/usb/omap_control_usb.h> + +static struct omap_control_usb *control_usb; +drivers/usb/phy/omap-control-usb.c line 38
Quoted 10 lines
drivers/usb/phy/omap-control-usb.c new file +10
-0+/** +* get_omap_control_dev - returns the device pointer for this control device +* +* This API should be called to get the device pointer for this control +* module device. This device pointer should be passed to all other API's +* in this driver. +* +* To be used by PHY driver and glue driver +*/ +struct device *get_omap_control_dev (void )let's do a small rename here and call it:
Quoted 1 line
omap_get_control_dev(), just to keep consistency with rest of the file.
Ok.
Quoted 64 lines
Quoted 16 lines
drivers/usb/phy/omap-control-usb.c new file +15
-0+{ +if (!control_usb) +return ERR_PTR (-ENODEV ); + +return control_usb->dev; +} +EXPORT_SYMBOL_GPL (get_omap_control_dev); + +/** +* omap_control_usb_phy_power - power on/off the phy using control module reg +* @dev: the control module device +* @on: 0 or 1, based on powering on or off the PHY +*/ +void omap_control_usb_phy_power (struct device *dev,int on) +{drivers/usb/phy/omap-control-usb.c line 63
Quoted 10 lines
drivers/usb/phy/omap-control-usb.c new file +10
-0+u32 val; +struct omap_control_usb *control_usb =dev_get_drvdata (dev); + +if (on) { + val =readl (control_usb->dev_conf); +if (val &PHY_PD ) +writel (~PHY_PD , control_usb->dev_conf); + }else { +writel (PHY_PD , control_usb->dev_conf); + }this can be better. I would rather have this:
struct
omap_control_usb*ctrl =dev_get_drvdata(dev); u32 val;val =
readl(ctrl->dev_conf);if (on)
val &= ~OMAP_CTRL_DEV_PHY_PD; else val |= OMAP_CTRL_DEV_PHY_PD;
writel(val, ctrl->dev_conf);Quoted 8 lines
drivers/usb/phy/omap-control-usb.c new file +8
-0+} +EXPORT_SYMBOL_GPL (omap_control_usb_phy_power); + +/** +* omap_control_usb_host_mode - set AVALID, VBUSVALID and ID pin in grounded +* @dev: struct device * +* +* This is an API to write to the mailbox register to notify the usb core that drivers/usb/phy/omap-control-usb.c line 81
Quoted 10 lines
drivers/usb/phy/omap-control-usb.c new file +10
-0+* a usb device has been connected. +*/ +void omap_control_usb_host_mode (struct device *dev) +{ +u32 val; +struct omap_control_usb *control_usb =dev_get_drvdata (dev); + + val =AVALID |VBUSVALID ; + +writel (val, control_usb->otghs_control);I would like to make this future proof too:
Quoted 3 lines
val =
readl(ctrl->otghs_control);
val |=OMAP_CTRL_DEV_AVALID|OMAP_CTRL_DEV_VBUSVALID;writel(val, ctrl->otghs_control);
I think we might then have to add
val &= ~(IDDIG | SESSEND) right?
Similar things should be done for below API's also so that we don't inadvertently carry forward the settings.
Quoted 59 lines
drivers/usb/phy/omap-control-usb.c line 98
Quoted 7 lines
drivers/usb/phy/omap-control-usb.c new file +6
-0+void omap_control_usb_device_mode (struct device *dev) +{ +u32 val; +struct omap_control_usb *control_usb =dev_get_drvdata (dev); + + val =IDDIG |AVALID |VBUSVALID ;ditto. Read it before changing it. (the idea is that in future the other bits might be used for something else, so you risk breaking future functionality).
Quoted 9 lines
drivers/usb/phy/omap-control-usb.c new file +9
-0+ +writel (val, control_usb->otghs_control); +} +EXPORT_SYMBOL_GPL (omap_control_usb_device_mode); + +/** +* omap_control_usb_set_sessionend - Enable SESSIONEND and IDIG to high +* impedance +* @dev: struct device * drivers/usb/phy/omap-control-usb.c line 117
Quoted 10 lines
drivers/usb/phy/omap-control-usb.c new file +10
-0+* +* This is an API to write to the mailbox register to notify the usb core +* it's now in disconnected state. +*/ +void omap_control_usb_set_sessionend (struct device *dev) +{ +u32 val; +struct omap_control_usb *control_usb =dev_get_drvdata (dev); + + val =SESSEND |IDDIG ;ditto
drivers/usb/phy/omap-control-usb.c line 130
Quoted 13 lines
drivers/usb/phy/omap-control-usb.c new file +13
-0+ +writel (val, control_usb->otghs_control); +} +EXPORT_SYMBOL_GPL (omap_control_usb_set_sessionend); + +static int omap_control_usb_probe (struct platform_device *pdev) +{ +struct resource *res; +struct device_node *np = pdev->dev.of_node; +struct omap_control_usb_platform_data *pdata = pdev->dev.platform_data; + + control_usb =devm_kzalloc (&pdev->dev,sizeof (*control_usb), +GFP_KERNEL );you're using space indentation here.
Quoted 9 lines
drivers/usb/phy/omap-control-usb.c new file +9
-0+if (!control_usb) { +dev_err (&pdev->dev,"unable to alloc memory for control usb\n" ); +return -ENOMEM ; + } + +if (np) { + control_usb->has_mailbox =of_property_read_bool (np, +"ti,has_mailbox" ); + }else if (pdata) {
Quoted 8 lines
drivers/usb/phy/omap-control-usb.c line 143
Quoted 4 lines
drivers/usb/phy/omap-control-usb.c new file +4
-0+ control_usb->has_mailbox = pdata->has_mailbox; + }else { +dev_err (&pdev->dev,"no pdata present\n" ); +return -EINVAL ;does it make sense to default to
has_mailboxas true ? I mean, seems like this is how it's going to be in future devices looking at the current trend.
No actually. omap5 doesn't have mailbox in control module ;-)
Quoted 3 lines
Another idea is to try to get the extra resource below, if it fails you try to continue without it ;-)
I prefer the way it is now because mailbox is needed for MUSB to be functional in OMAP4 and we should fail if we don't have it. No?
Quoted 40 lines
drivers/usb/phy/omap-control-usb.c line 149
Quoted 7 lines
drivers/usb/phy/omap-control-usb.c new file +6
-0+ } + + control_usb->dev = &pdev->dev; + + res =platform_get_resource_byname (pdev,IORESOURCE_MEM , +"control_dev_conf" );using space indentation here again.
Quoted 30 lines
drivers/usb/phy/omap-control-usb.c new file +30
-0+ control_usb->dev_conf =devm_request_and_ioremap (&pdev->dev, res); +if (control_usb->dev_conf ==NULL ) { +dev_err (&pdev->dev,"Failed to obtain io memory\n" ); +return -EADDRNOTAVAIL ; + } + +if (control_usb->has_mailbox) { + res =platform_get_resource_byname (pdev,IORESOURCE_MEM , +"otghs_control" ); + control_usb->otghs_control =devm_request_and_ioremap ( + &pdev->dev, res); +if (control_usb->otghs_control ==NULL ) { +dev_err (&pdev->dev,"Failed to obtain io memory\n" ); +return -EADDRNOTAVAIL ; + } + } + +dev_set_drvdata (control_usb->dev, control_usb); + +return 0 ; +} + +#ifdef CONFIG_OF +static const struct of_device_id omap_control_usb_id_table[] = { + { .compatible ="ti,omap-control-usb" }, + {} +}; +MODULE_DEVICE_TABLE (of, omap_control_usb_id_table); +#endif +
Quoted 8 lines
drivers/usb/phy/omap-control-usb.c line 184
Quoted 5 lines
drivers/usb/phy/omap-control-usb.c new file +5
-0+static struct platform_driver omap_control_usb_driver = { + .probe = omap_control_usb_probe, + .driver = { + .name ="omap-control-usb" , + .owner =THIS_MODULE ,no need to set owner here. When you register the
platform_driver, it will be set for you.
Ok.
Quoted 23 lines
Quoted 10 lines
drivers/usb/phy/omap-control-usb.c new file +9
-0+ .of_match_table = of_match_ptr(omap_control_usb_id_table), + }, +}; + +static int __init omap_control_usb_init (void ) +{ +return platform_driver_register (&omap_control_usb_driver); +} +subsys_initcall (omap_control_usb_init);drivers/usb/phy/omap-control-usb.c line 203
Quoted 10 lines
drivers/usb/phy/omap-control-usb.c new file +10
-0+ +static void __exit omap_control_usb_exit(void) +{ +platform_driver_unregister (&omap_control_usb_driver); +} +module_exit (omap_control_usb_exit); + +MODULE_ALIAS ("platform: omap_control_usb" ); +MODULE_AUTHOR ("Texas Instruments Inc." ); +MODULE_DESCRIPTION ("OMAP CONTROL USB DRIVER" );don't scream to your users like that ;-)
Quoted 1 line
MODULE_DESCRIPTION("OMAP Control Module USB Driver");
Ok.
Quoted 43 lines
Quoted 43 lines
drivers/usb/phy/omap-control-usb.c new file +1
-0+MODULE_LICENSE ("GPL v2" );include/linux/usb/omap_control_usb.h new file +35
-0@@ -0,0 +1,72 @@ +/* +* omap_control_usb.h - Header file for the USB part of control module. +* +* Copyright (C) 2013 Texas Instruments Incorporated - http://www.ti.com +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* Author: Kishon Vijay Abraham I <[email protected]> +* +* 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. +* +*/ + +#ifndef __OMAP_CONTROL_USB_H__ +#define __OMAP_CONTROL_USB_H__ + +struct omap_control_usb { +struct device *dev; + +u32 __iomem *dev_conf; +u32 __iomem *otghs_control; + +u8 has_mailbox:1 ; +}; + +struct omap_control_usb_platform_data { +u8 has_mailbox:1 ; +}; + +#define PHY_PD BIT(0)
Quoted 8 lines
include/linux/usb/omap_control_usb.h line 41
Quoted 6 lines
include/linux/usb/omap_control_usb.h new file +6
-0+ +#define AVALID BIT(0) +#define BVALID BIT(1) +#define VBUSVALID BIT(2) +#define SESSEND BIT(3) +#define IDDIG BIT(4)please prepend with
OMAP_CTRL_or something similar.
Sure.
Thanks
Kishon
Re: [PATCH 1/4] drivers: usb: phy: add a new driver for usb part of control module
Hi,
Quoted 11 lines · kishon
Quoted 11 lines
drivers/usb/phy/omap-control-usb.c line 81
Quoted 8 lines
drivers/usb/phy/omap-control-usb.c new file +8
-0+void omap_control_usb_host_mode (struct device *dev) +{ +u32 val; +struct omap_control_usb *control_usb =dev_get_drvdata (dev); + + val =AVALID |VBUSVALID ; + +writel (val, control_usb->otghs_control);I would like to make this future proof too:
Quoted 6 lines
Quoted 3 lines
val =
readl(ctrl->otghs_control);
val |=OMAP_CTRL_DEV_AVALID|OMAP_CTRL_DEV_VBUSVALID;writel(val, ctrl->otghs_control);I think we might then have to add
val &= ~(IDDIG | SESSEND) right?
right, my bad ;-)
Quoted 5 lines
Quoted 2 lines
Another idea is to try to get the extra resource below, if it fails you try to continue without it ;-)
I prefer the way it is now because mailbox is needed for MUSB to be functional in OMAP4 and we should fail if we don't have it. No?
could be, that would mean an error on DT data though.
Signature · 8 lines
balbi -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 836 bytes Desc: Digital signature URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20130118/4795ddc0/attachment.sig>
PATCH 2/4 ARM: OMAP: devices: create device for usb part of control module
In reply to Kishon Vijay Abraham IA seperate driver has been added to handle the usb part of control module. A device for the above driver is created here, using the register address information to be used by the driver for powering on the PHY and for writing to the mailbox.
--- arch/arm/mach-omap2/devices.c | 48 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+)
arch/arm/mach-omap2/devices.c +48 -0
@@ -20,6 +20,7 @@#include <linux/pinctrl/machine.h> #include <linux/platform_data/omap4-keypad.h> #include <linux/platform_data/omap_ocp2scp.h> +#include <linux/usb/omap_control_usb.h> #include <asm/mach-types.h> #include <asm/mach/map.h>
@@ -254,6 +255,52 @@ static inline void omap_init_camera(void)#endif } +#if IS_ENABLED (CONFIG_OMAP_CONTROL_USB ) +static struct omap_control_usb_platform_data omap4_control_usb_pdata = { + .has_mailbox = true, +}; + +struct resource omap4_control_usb_res[] = { + { + .name ="control_dev_conf" , + .start =0x4a002300 , + .end =0x4a002303 , + .flags =IORESOURCE_MEM , + }, + { + .name ="otghs_control" , + .start =0x4a00233c , + .end =0x4a00233f , + .flags =IORESOURCE_MEM , + }, +}; + +static struct platform_device omap4_control_usb = { + .name ="omap-control-usb" , + .id =-1 , + .dev = { + .platform_data = &omap4_control_usb_pdata, + }, + .num_resources =2 , + .resource = omap4_control_usb_res, +}; + +static inline void __init omap_init_control_usb (void ) +{ +int ret =0 ; + +if (cpu_is_omap44xx ()) { + ret =platform_device_register (&omap4_control_usb); +if (ret) +pr_err ("Error registering omap_control_usb device:%d\n" , + ret); + } +} + +#else +static inline void omap_init_control_usb (void ) { } +#endif /* CONFIG_OMAP_CONTROL_USB */ +int __init omap4_keyboard_init (struct omap4_keypad_platform_data *sdp4430_keypad_data,struct omap_board_data *bdata) {
@@ -721,6 +768,7 @@ static int __init omap2_init_devices(void)omap_init_mbox ();/* If dtb is there, the devices will be created dynamically */ if (!of_have_populated_dt ()) { +omap_init_control_usb ();omap_init_dmic ();omap_init_mcpdm ();omap_init_mcspi ();
Signature · 1 line
1.7.9.5
Re: [PATCH 2/4] ARM: OMAP: devices: create device for usb part of control module
Quoted 56 lines · Kishon Vijay Abraham I
A seperate driver has been added to handle the usb part of control module. A device for the above driver is created here, using the register address information to be used by the driver for powering on the PHY and for writing to the mailbox.
Signed-off-by Kishon Vijay Abraham I <[email protected]>--- arch/arm/mach-omap2/devices.c | 48 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+)arch/arm/mach-omap2/devices.c +31
-0@@ -20,6 +20,7 @@#include <linux/pinctrl/machine.h> #include <linux/platform_data/omap4-keypad.h> #include <linux/platform_data/omap_ocp2scp.h> +#include <linux/usb/omap_control_usb.h> #include <asm/mach-types.h> #include <asm/mach/map.h> @@ -254,6 +255,52 @@ static inline void omap_init_camera(void)#endif } +#if IS_ENABLED (CONFIG_OMAP_CONTROL_USB ) +static struct omap_control_usb_platform_data omap4_control_usb_pdata = { + .has_mailbox = true, +}; + +struct resource omap4_control_usb_res[] = { + { + .name ="control_dev_conf" , + .start =0x4a002300 , + .end =0x4a002303 , + .flags =IORESOURCE_MEM , + }, + { + .name ="otghs_control" , + .start =0x4a00233c , + .end =0x4a00233f , + .flags =IORESOURCE_MEM , + }, +}; + +static struct platform_device omap4_control_usb = { + .name ="omap-control-usb" , + .id =-1 , + .dev = { + .platform_data = &omap4_control_usb_pdata, + }, + .num_resources =2 , + .resource = omap4_control_usb_res, +}; +
arch/arm/mach-omap2/devices.c static inline void omap_init_camera(void) · line 297
Quoted 10 lines
arch/arm/mach-omap2/devices.c +10
-0+static inline void __init omap_init_control_usb (void ) +{ +int ret =0 ; + +if (cpu_is_omap44xx ()) { + ret =platform_device_register (&omap4_control_usb); +if (ret) +pr_err ("Error registering omap_control_usb device:%d\n" , + ret); + }
you can decrease indentation if you invert the check:
if (!cpu_is_omap44xx())
return;
if (platform_device_register(.....)
Signature · 8 lines
balbi -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 836 bytes Desc: Digital signature URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20130118/5be607ef/attachment.sig>
PATCH 3/4 ARM: OMAP2: MUSB: Specify omap4 has mailbox
In reply to Kishon Vijay Abraham IAdded has_mailbox to the musb platform data to specify that omap uses an external mailbox (in control module) to communicate with the musb core during device connect and disconnect.
--- arch/arm/mach-omap2/usb-musb.c | 3 +++ include/linux/usb/musb.h | 2 ++ 2 files changed, 5 insertions(+)
arch/arm/mach-omap2/usb-musb.c +3 -0
@@ -85,6 +85,9 @@ void __init usb_musb_init(struct omap_musb_board_data *musb_board_data) musb_plat.mode = board_data->mode; musb_plat.extvbus = board_data->extvbus; +if (cpu_is_omap44xx ()) + musb_plat.has_mailbox = true; +if (soc_is_am35xx ()) { oh_name ="am35x_otg_hs" ; name ="musb-am35x" ;
include/linux/usb/musb.h +2 -0
@@ -99,6 +99,8 @@ struct musb_hdrc_platform_data {/* MUSB_HOST, MUSB_PERIPHERAL, or MUSB_OTG */ u8 mode; + u8 has_mailbox:1; +/* for clk_get() */ const char *clock;
Signature · 1 line
1.7.9.5
PATCH 4/4 drivers: usb: start using the control module driver
In reply to Kishon Vijay Abraham IStart using the control module driver for powering on the PHY and for writing to the mailbox instead of writing to the control module registers on their own.
--- Documentation/devicetree/bindings/usb/omap-usb.txt | 4 ++ Documentation/devicetree/bindings/usb/usb-phy.txt | 7 +-- arch/arm/mach-omap2/omap_hwmod_44xx_data.c | 13 ---- drivers/usb/musb/Kconfig | 1 + drivers/usb/musb/omap2430.c | 64 ++++++++------------ drivers/usb/musb/omap2430.h | 9 --- drivers/usb/phy/Kconfig | 1 + drivers/usb/phy/omap-usb2.c | 38 +++--------- include/linux/usb/omap_usb.h | 4 +- 9 files changed, 42 insertions(+), 99 deletions(-)
Documentation/devicetree/bindings/usb/omap-usb.txt +4 -0
@@ -3,6 +3,9 @@ OMAP GLUE AND OTHER OMAP SPECIFIC COMPONENTS OMAP MUSB GLUE - compatible : Should be "ti,omap4-musb" or "ti,omap3-musb" - ti,hwmods : must be "usb_otg_hs" + - ti,has_mailbox : to specify that omap uses an external mailbox + (in control module) to communicate with the musb core during device connect + and disconnect. - multipoint : Should be "1" indicating the musb controller supports multipoint. This is a MUSB configuration-specific setting. - num_eps : Specifies the number of endpoints. This is also a
@@ -24,6 +27,7 @@ SOC specific device node entry usb_otg_hs: usb_otg_hs at 4a0ab000 { compatible = "ti,omap4-musb"; ti,hwmods = "usb_otg_hs"; + ti,has_mailbox; multipoint = <1>; num_eps = <16>; ram_bits = <12>;
Documentation/devicetree/bindings/usb/usb-phy.txt +2 -5
@@ -4,9 +4,7 @@ OMAP USB2 PHY Required properties: - compatible: Should be "ti,omap-usb2" - - reg : Address and length of the register set for the device. Also -add the address of control module dev conf register until a driver for -control module is added + - reg : Address and length of the register set for the device. Optional properties: - ctrl_module : phandle of the control module used by PHY driver to power on
@@ -16,7 +14,6 @@ This is usually a subnode of ocp2scp to which it is connected. usb2phy at 4a0ad080 { compatible = "ti,omap-usb2"; - reg = <0x4a0ad080 0x58>, - <0x4a002300 0x4>; + reg = <0x4a0ad080 0x58>; ctrl_module = <&omap_control_usb>; };
arch/arm/mach-omap2/omap_hwmod_44xx_data.c +0 -13
@@ -2698,13 +2698,6 @@ static struct resource omap44xx_usb_phy_and_pll_addrs[] = { .end = 0x4a0ae000, .flags = IORESOURCE_MEM, }, - { -/* XXX: Remove this once control module driver is in place */ - .name = "ctrl_dev", - .start = 0x4a002300, - .end = 0x4a002303, - .flags = IORESOURCE_MEM, - }, { } };
@@ -6152,12 +6145,6 @@ static struct omap_hwmod_addr_space omap44xx_usb_otg_hs_addrs[] = { .pa_end = 0x4a0ab7ff, .flags = ADDR_TYPE_RT }, - { -/* XXX: Remove this once control module driver is in place */ - .pa_start = 0x4a00233c, - .pa_end = 0x4a00233f, - .flags = ADDR_TYPE_RT - }, { } };
drivers/usb/musb/Kconfig +1 -0
@@ -11,6 +11,7 @@ config USB_MUSB_HDRC select NOP_USB_XCEIV if (SOC_TI81XX || SOC_AM33XX) select TWL4030_USB if MACH_OMAP_3430SDP select TWL6030_USB if MACH_OMAP_4430SDP || MACH_OMAP4_PANDA + select OMAP_CONTROL_USB if MACH_OMAP_4430SDP || MACH_OMAP4_PANDA select USB_OTG_UTILS help Say Y here if your system has a dual role high speed USB
drivers/usb/musb/omap2430.c +25 -39
151 lines not on this page · raw message
drivers/usb/musb/omap2430.h +0 -9
@@ -49,13 +49,4 @@#define OTG_FORCESTDBY 0x414# define ENABLEFORCE (1 << 0) -/* -* Control Module bit definitions -* XXX: Will be removed once we have a driver for control module. -*/ -#define AVALID BIT(0) -#define BVALID BIT(1) -#define VBUSVALID BIT(2) -#define SESSEND BIT(3) -#define IDDIG BIT(4)#endif /* __MUSB_OMAP243X_H__ */
drivers/usb/phy/Kconfig +1 -0
@@ -8,6 +8,7 @@ config OMAP_USB2 tristate "OMAP USB2 PHY Driver" depends on ARCH_OMAP2PLUS select USB_OTG_UTILS + select OMAP_CONTROL_USB help Enable this to support the transceiver that is part of SOC. This driver takes care of all the PHY functionality apart from comparator.
drivers/usb/phy/omap-usb2.c +8 -30
@@ -27,6 +27,7 @@#include <linux/err.h> #include <linux/pm_runtime.h> #include <linux/delay.h> +#include <linux/usb/omap_control_usb.h> /** * omap_usb2_set_comparator - links the comparator present in the sytem with
@@ -52,29 +53,6 @@ int omap_usb2_set_comparator(struct phy_companion *comparator) }EXPORT_SYMBOL_GPL (omap_usb2_set_comparator); -/** -* omap_usb_phy_power - power on/off the phy using control module reg -* @phy: struct omap_usb * -* @on: 0 or 1, based on powering on or off the PHY -* -* XXX: Remove this function once control module driver gets merged -*/ -static void omap_usb_phy_power (struct omap_usb *phy,int on) -{ -u32 val; - -if (on) { - val =readl (phy->control_dev); -if (val &PHY_PD ) { -writel (~PHY_PD , phy->control_dev); -/* XXX: add proper documentation for this delay */ -mdelay (200 ); - } - }else { -writel (PHY_PD , phy->control_dev); - } -} -static int omap_usb_set_vbus (struct usb_otg *otg,bool enabled) {struct omap_usb *phy =phy_to_omapusb (otg->phy);
@@ -124,7 +102,7 @@ static int omap_usb2_suspend(struct usb_phy *x, int suspend)struct omap_usb *phy =phy_to_omapusb (x);if (suspend && !phy->is_suspended) { -omap_usb_phy_power (phy,0 ); +omap_control_usb_phy_power (phy->control_dev,0 );pm_runtime_put_sync (phy->dev); phy->is_suspended =1 ; }else if (!suspend && phy->is_suspended) {
@@ -134,7 +112,7 @@ static int omap_usb2_suspend(struct usb_phy *x, int suspend) ret);return ret; } -omap_usb_phy_power (phy,1 ); +omap_control_usb_phy_power (phy->control_dev,1 ); phy->is_suspended =0 ; }
@@ -168,14 +146,14 @@ static int omap_usb2_probe(struct platform_device *pdev) res =platform_get_resource (pdev,IORESOURCE_MEM ,1 ); - phy->control_dev =devm_request_and_ioremap (&pdev->dev, res); -if (phy->control_dev ==NULL ) { -dev_err (&pdev->dev,"Failed to obtain io memory\n" ); -return -ENXIO ; + phy->control_dev =get_omap_control_dev (); +if (IS_ERR (phy->control_dev)) { +dev_dbg (&pdev->dev,"Failed to get control device\n" ); +return -ENODEV ; } phy->is_suspended =1 ; -omap_usb_phy_power (phy,0 ); +omap_control_usb_phy_power (phy->control_dev,0 ); otg->set_host = omap_usb_set_host; otg->set_peripheral = omap_usb_set_peripheral;
include/linux/usb/omap_usb.h +1 -3
@@ -25,13 +25,11 @@ struct omap_usb {struct usb_phy phy;struct phy_companion *comparator;struct device *dev; -u32 __iomem *control_dev; +struct device *control_dev;struct clk *wkupclk; u8 is_suspended:1; }; -#define PHY_PD 0x1 -#define phy_to_omapusb (x) container_of((x), struct omap_usb, phy)#if defined(CONFIG_OMAP_USB2 ) || defined(CONFIG_OMAP_USB2_MODULE )
Signature · 1 line
1.7.9.5
Re: [PATCH 4/4] drivers: usb: start using the control module driver
Hi,
Quoted 163 lines · Kishon Vijay Abraham I
Start using the control module driver for powering on the PHY and for writing to the mailbox instead of writing to the control module registers on their own.
Signed-off-by Kishon Vijay Abraham I <[email protected]>--- Documentation/devicetree/bindings/usb/omap-usb.txt | 4 ++ Documentation/devicetree/bindings/usb/usb-phy.txt | 7 +-- arch/arm/mach-omap2/omap_hwmod_44xx_data.c | 13 ---- drivers/usb/musb/Kconfig | 1 + drivers/usb/musb/omap2430.c | 64 ++++++++------------ drivers/usb/musb/omap2430.h | 9 --- drivers/usb/phy/Kconfig | 1 + drivers/usb/phy/omap-usb2.c | 38 +++--------- include/linux/usb/omap_usb.h | 4 +- 9 files changed, 42 insertions(+), 99 deletions(-)Documentation/devicetree/bindings/usb/omap-usb.txt +4
-0@@ -3,6 +3,9 @@ OMAP GLUE AND OTHER OMAP SPECIFIC COMPONENTS OMAP MUSB GLUE - compatible : Should be "ti,omap4-musb" or "ti,omap3-musb" - ti,hwmods : must be "usb_otg_hs" + - ti,has_mailbox : to specify that omap uses an external mailbox + (in control module) to communicate with the musb core during device connect + and disconnect. - multipoint : Should be "1" indicating the musb controller supports multipoint. This is a MUSB configuration-specific setting. - num_eps : Specifies the number of endpoints. This is also a@@ -24,6 +27,7 @@ SOC specific device node entry usb_otg_hs: usb_otg_hs at 4a0ab000 { compatible = "ti,omap4-musb"; ti,hwmods = "usb_otg_hs"; + ti,has_mailbox; multipoint = <1>; num_eps = <16>; ram_bits = <12>;Documentation/devicetree/bindings/usb/usb-phy.txt +2
-5@@ -4,9 +4,7 @@ OMAP USB2 PHY Required properties: - compatible: Should be "ti,omap-usb2" - - reg : Address and length of the register set for the device. Also -add the address of control module dev conf register until a driver for -control module is added + - reg : Address and length of the register set for the device. Optional properties: - ctrl_module : phandle of the control module used by PHY driver to power on@@ -16,7 +14,6 @@ This is usually a subnode of ocp2scp to which it is connected. usb2phy at 4a0ad080 { compatible = "ti,omap-usb2"; - reg = <0x4a0ad080 0x58>, - <0x4a002300 0x4>; + reg = <0x4a0ad080 0x58>; ctrl_module = <&omap_control_usb>; };arch/arm/mach-omap2/omap_hwmod_44xx_data.c +0
-13@@ -2698,13 +2698,6 @@ static struct resource omap44xx_usb_phy_and_pll_addrs[] = { .end = 0x4a0ae000, .flags = IORESOURCE_MEM, }, - { -/* XXX: Remove this once control module driver is in place */ - .name = "ctrl_dev", - .start = 0x4a002300, - .end = 0x4a002303, - .flags = IORESOURCE_MEM, - }, { } };@@ -6152,12 +6145,6 @@ static struct omap_hwmod_addr_space omap44xx_usb_otg_hs_addrs[] = { .pa_end = 0x4a0ab7ff, .flags = ADDR_TYPE_RT }, - { -/* XXX: Remove this once control module driver is in place */ - .pa_start = 0x4a00233c, - .pa_end = 0x4a00233f, - .flags = ADDR_TYPE_RT - }, { } };drivers/usb/musb/Kconfig +1
-0@@ -11,6 +11,7 @@ config USB_MUSB_HDRC select NOP_USB_XCEIV if (SOC_TI81XX || SOC_AM33XX) select TWL4030_USB if MACH_OMAP_3430SDP select TWL6030_USB if MACH_OMAP_4430SDP || MACH_OMAP4_PANDA + select OMAP_CONTROL_USB if MACH_OMAP_4430SDP || MACH_OMAP4_PANDA select USB_OTG_UTILS help Say Y here if your system has a dual role high speed USBdrivers/usb/musb/omap2430.c +2
-22@@ -37,6 +37,7 @@#include <linux/err.h> #include <linux/delay.h> #include <linux/usb/musb-omap.h> +#include <linux/usb/omap_control_usb.h> #include "musb_core.h" #include "omap2430.h" @@ -46,7 +47,7 @@ struct omap2430_glue {struct platform_device *musb;enum omap_musb_vbus_id_status status;struct work_struct omap_musb_mailbox_work; -u32 __iomem *control_otghs; +struct device *control_otghs; };#define glue_to_musb (g) platform_get_drvdata(g->musb)@@ -54,26 +55,6 @@ struct omap2430_glue *_glue;static struct timer_list musb_idle_timer; -/** -* omap4_usb_phy_mailbox - write to usb otg mailbox -* @glue: struct omap2430_glue * -* @val: the value to be written to the mailbox -* -* On detection of a device (ID pin is grounded), this API should be called -* to set AVALID, VBUSVALID and ID pin is grounded. -* -* When OMAP is connected to a host (OMAP in device mode), this API -* is called to set AVALID, VBUSVALID and ID pin in high impedance. -* -* XXX: This function will be removed once we have a seperate driver for -* control module -*/ -static void omap4_usb_phy_mailbox (struct omap2430_glue *glue,u32 val) -{ -if (glue->control_otghs) -writel (val, glue->control_otghs); -} -static void musb_do_idle (unsigned long _musb) {struct musb *musb = (void *)_musb;@@ -269,7 +250,6 @@ EXPORT_SYMBOL_GPL(omap_musb_mailbox);static void omap_musb_set_mailbox (struct omap2430_glue *glue) { -u32 val;struct musb *musb =glue_to_musb (glue);struct device *dev = musb->controller;struct musb_hdrc_platform_data *pdata = dev->platform_data;
drivers/usb/musb/omap2430.c static void omap_musb_set_mailbox(struct omap2430_glue *glue) · line 269
Quoted 7 lines
drivers/usb/musb/omap2430.c +2
-2@@ -285,8 +265,8 @@ 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); - val =AVALID |VBUSVALID ; -omap4_usb_phy_mailbox (glue, val); +if (!IS_ERR (glue->control_otghs)) +omap_control_usb_host_mode (glue->control_otghs);
you could introduce a helper to do the checks for you. something like:
static inline void omap_control_set_mode(*ctrl, int mode)
{
if (IS_ERR(glue->control_otghs))
return;
switch (mode) {
case HOST:
omap_control_usb_host_mode(ctrl);
break;
case DEVICE:
omap_control_usb_device(ctrl)
break;
default:
meh();
}
}likewise for power() method
Signature · 8 lines
balbi -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 836 bytes Desc: Digital signature URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20130118/18b3d6d3/attachment.sig>
Re: [PATCH 4/4] drivers: usb: start using the control module driver
Quoted 193 lines · Felipe Balbi
Hi,
Quoted 163 lines · Kishon Vijay Abraham I
Start using the control module driver for powering on the PHY and for writing to the mailbox instead of writing to the control module registers on their own.
Signed-off-by Kishon Vijay Abraham I <[email protected]>--- Documentation/devicetree/bindings/usb/omap-usb.txt | 4 ++ Documentation/devicetree/bindings/usb/usb-phy.txt | 7 +-- arch/arm/mach-omap2/omap_hwmod_44xx_data.c | 13 ---- drivers/usb/musb/Kconfig | 1 + drivers/usb/musb/omap2430.c | 64 ++++++++------------ drivers/usb/musb/omap2430.h | 9 --- drivers/usb/phy/Kconfig | 1 + drivers/usb/phy/omap-usb2.c | 38 +++--------- include/linux/usb/omap_usb.h | 4 +- 9 files changed, 42 insertions(+), 99 deletions(-)Documentation/devicetree/bindings/usb/omap-usb.txt +4
-0@@ -3,6 +3,9 @@ OMAP GLUE AND OTHER OMAP SPECIFIC COMPONENTS OMAP MUSB GLUE - compatible : Should be "ti,omap4-musb" or "ti,omap3-musb" - ti,hwmods : must be "usb_otg_hs" + - ti,has_mailbox : to specify that omap uses an external mailbox + (in control module) to communicate with the musb core during device connect + and disconnect. - multipoint : Should be "1" indicating the musb controller supports multipoint. This is a MUSB configuration-specific setting. - num_eps : Specifies the number of endpoints. This is also a@@ -24,6 +27,7 @@ SOC specific device node entry usb_otg_hs: usb_otg_hs at 4a0ab000 { compatible = "ti,omap4-musb"; ti,hwmods = "usb_otg_hs"; + ti,has_mailbox; multipoint = <1>; num_eps = <16>; ram_bits = <12>;Documentation/devicetree/bindings/usb/usb-phy.txt +2
-5@@ -4,9 +4,7 @@ OMAP USB2 PHY Required properties: - compatible: Should be "ti,omap-usb2" - - reg : Address and length of the register set for the device. Also -add the address of control module dev conf register until a driver for -control module is added + - reg : Address and length of the register set for the device. Optional properties: - ctrl_module : phandle of the control module used by PHY driver to power on@@ -16,7 +14,6 @@ This is usually a subnode of ocp2scp to which it is connected. usb2phy at 4a0ad080 { compatible = "ti,omap-usb2"; - reg = <0x4a0ad080 0x58>, - <0x4a002300 0x4>; + reg = <0x4a0ad080 0x58>; ctrl_module = <&omap_control_usb>; };arch/arm/mach-omap2/omap_hwmod_44xx_data.c +0
-13@@ -2698,13 +2698,6 @@ static struct resource omap44xx_usb_phy_and_pll_addrs[] = { .end = 0x4a0ae000, .flags = IORESOURCE_MEM, }, - { -/* XXX: Remove this once control module driver is in place */ - .name = "ctrl_dev", - .start = 0x4a002300, - .end = 0x4a002303, - .flags = IORESOURCE_MEM, - }, { } };@@ -6152,12 +6145,6 @@ static struct omap_hwmod_addr_space omap44xx_usb_otg_hs_addrs[] = { .pa_end = 0x4a0ab7ff, .flags = ADDR_TYPE_RT }, - { -/* XXX: Remove this once control module driver is in place */ - .pa_start = 0x4a00233c, - .pa_end = 0x4a00233f, - .flags = ADDR_TYPE_RT - }, { } };drivers/usb/musb/Kconfig +1
-0@@ -11,6 +11,7 @@ config USB_MUSB_HDRC select NOP_USB_XCEIV if (SOC_TI81XX || SOC_AM33XX) select TWL4030_USB if MACH_OMAP_3430SDP select TWL6030_USB if MACH_OMAP_4430SDP || MACH_OMAP4_PANDA + select OMAP_CONTROL_USB if MACH_OMAP_4430SDP || MACH_OMAP4_PANDA select USB_OTG_UTILS help Say Y here if your system has a dual role high speed USBdrivers/usb/musb/omap2430.c +2
-22@@ -37,6 +37,7 @@#include <linux/err.h> #include <linux/delay.h> #include <linux/usb/musb-omap.h> +#include <linux/usb/omap_control_usb.h> #include "musb_core.h" #include "omap2430.h" @@ -46,7 +47,7 @@ struct omap2430_glue {struct platform_device *musb;enum omap_musb_vbus_id_status status;struct work_struct omap_musb_mailbox_work; -u32 __iomem *control_otghs; +struct device *control_otghs; };#define glue_to_musb (g) platform_get_drvdata(g->musb)@@ -54,26 +55,6 @@ struct omap2430_glue *_glue;static struct timer_list musb_idle_timer; -/** -* omap4_usb_phy_mailbox - write to usb otg mailbox -* @glue: struct omap2430_glue * -* @val: the value to be written to the mailbox -* -* On detection of a device (ID pin is grounded), this API should be called -* to set AVALID, VBUSVALID and ID pin is grounded. -* -* When OMAP is connected to a host (OMAP in device mode), this API -* is called to set AVALID, VBUSVALID and ID pin in high impedance. -* -* XXX: This function will be removed once we have a seperate driver for -* control module -*/ -static void omap4_usb_phy_mailbox (struct omap2430_glue *glue,u32 val) -{ -if (glue->control_otghs) -writel (val, glue->control_otghs); -} -static void musb_do_idle (unsigned long _musb) {struct musb *musb = (void *)_musb;@@ -269,7 +250,6 @@ EXPORT_SYMBOL_GPL(omap_musb_mailbox);static void omap_musb_set_mailbox (struct omap2430_glue *glue) { -u32 val;struct musb *musb =glue_to_musb (glue);struct device *dev = musb->controller;struct musb_hdrc_platform_data *pdata = dev->platform_data;drivers/usb/musb/omap2430.c static void omap_musb_set_mailbox(struct omap2430_glue *glue) · line 269
Quoted 7 lines
drivers/usb/musb/omap2430.c +2
-2@@ -285,8 +265,8 @@ 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); - val =AVALID |VBUSVALID ; -omap4_usb_phy_mailbox (glue, val); +if (!IS_ERR (glue->control_otghs)) +omap_control_usb_host_mode (glue->control_otghs);you could introduce a helper to do the checks for you. something like:
static inline void
omap_control_set_mode(*ctrl, int mode){ if (IS_ERR(glue->control_otghs)) return; switch (mode) { case HOST: omap_control_usb_host_mode(ctrl); break; case DEVICE: omap_control_usb_device(ctrl) break; default: meh(); } }
Quoted 1 line
likewise for
power()method
Ok.
Thanks
Kishon