Message ID | 1351438946-5331-1-git-send-email-anarsoul@gmail.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
On Sun, Oct 28, 2012 at 4:42 PM, Vasily Khoruzhick <anarsoul@gmail.com> wrote: > This driver controls mode of USB port #2 pins - device or host. > > Signed-off-by: Vasily Khoruzhick <anarsoul@gmail.com> > --- > arch/arm/mach-pxa/Kconfig | 7 +++ > arch/arm/mach-pxa/Makefile | 1 + > arch/arm/mach-pxa/z2-usb-switch.c | 100 ++++++++++++++++++++++++++++++++++++++ > 3 files changed, 108 insertions(+) > create mode 100644 arch/arm/mach-pxa/z2-usb-switch.c > > diff --git a/arch/arm/mach-pxa/Kconfig b/arch/arm/mach-pxa/Kconfig > index 11aa739..5fffc4b 100644 > --- a/arch/arm/mach-pxa/Kconfig > +++ b/arch/arm/mach-pxa/Kconfig > @@ -630,6 +630,13 @@ config MACH_ZIPIT2 > bool "Zipit Z2 Handheld" > select HAVE_PWM > select PXA27x > + > +config Z2_USB_SWITCH > + tristate "Control the state of USB port on Zipit Z2" > + depends on MACH_ZIPIT2 > + help > + This is a simple driver that is able to control > + usb mode of Zipit Z2 > endif > endmenu > > diff --git a/arch/arm/mach-pxa/Makefile b/arch/arm/mach-pxa/Makefile > index ee88d6e..86a032f 100644 > --- a/arch/arm/mach-pxa/Makefile > +++ b/arch/arm/mach-pxa/Makefile > @@ -99,3 +99,4 @@ obj-$(CONFIG_MACH_RAUMFELD_SPEAKER) += raumfeld.o > obj-$(CONFIG_MACH_ZIPIT2) += z2.o > > obj-$(CONFIG_TOSA_BT) += tosa-bt.o > +obj-$(CONFIG_Z2_USB_SWITCH) += z2-usb-switch.o > diff --git a/arch/arm/mach-pxa/z2-usb-switch.c b/arch/arm/mach-pxa/z2-usb-switch.c > new file mode 100644 > index 0000000..9583092 > --- /dev/null > +++ b/arch/arm/mach-pxa/z2-usb-switch.c > @@ -0,0 +1,100 @@ > +/* > + * USB mode switcher for Z2 > + * > + * Copyright (c) 2011 Vasily Khoruzhick > + * > + * This program is free software; you can redistribute it and/or modify > + * it under the terms of the GNU General Public License version 2 as > + * published by the Free Software Foundation. > + * > + */ > + > +#include <linux/kernel.h> > +#include <linux/module.h> > +#include <linux/platform_device.h> > +#include <linux/delay.h> > + > +#include <mach/pxa27x.h> > +#include <mach/pxa27x-udc.h> > + > +#include <asm/io.h> > + > +#define MIN(a, b) ((a) < (b) ? (a) : (b)) > + > +static ssize_t usb_mode_show(struct device *dev, struct device_attribute *attr, > + char *buf) > +{ > + if (UP2OCR & UP2OCR_HXS) > + return sprintf(buf, "host\n"); > + else > + return sprintf(buf, "device\n"); > +} > + > +static ssize_t usb_mode_set(struct device *dev, struct device_attribute *attr, > + const char *buf, size_t count) > +{ > + if (strncmp(buf, "host", MIN(count, 4)) == 0) { > + UP2OCR = UP2OCR_HXS | UP2OCR_HXOE | UP2OCR_DPPDE | UP2OCR_DMPDE; > + return count; > + } else if (strncmp(buf, "device", MIN(count, 6)) == 0) { > + UP2OCR = UP2OCR_HXOE | UP2OCR_DPPUE; > + return count; > + } > + return -EINVAL; > +} > + > +static DEVICE_ATTR(usb_mode, 0644, usb_mode_show, usb_mode_set); > + > +static const struct attribute *attrs[] = { > + &dev_attr_usb_mode.attr, > + NULL, > +}; > + > +static const struct attribute_group attr_group = { > + .attrs = (struct attribute **)attrs, > +}; > + > +static int z2_usb_switch_probe(struct platform_device *dev) > +{ > + int res; > + > + res = sysfs_create_group(&dev->dev.kobj, &attr_group); > + if (res) > + return res; > + > + UP2OCR = UP2OCR_HXOE | UP2OCR_DPPUE; > + > + return 0; > +} > + > +static int __devexit z2_usb_switch_remove(struct platform_device *dev) > +{ > + UP2OCR = UP2OCR_HXOE; > + sysfs_remove_group(&dev->dev.kobj, &attr_group); > + > + return 0; > +} > + > +static struct platform_driver z2_usb_switch_driver = { > + .probe = z2_usb_switch_probe, > + .remove = __devexit_p(z2_usb_switch_remove), > + > + .driver = { > + .name = "z2-usb-switch", > + .owner = THIS_MODULE, > + }, > +}; > + > + > +static int __init z2_usb_switch_init(void) > +{ > + return platform_driver_register(&z2_usb_switch_driver); > +} > + > +static void __exit z2_usb_switch_exit(void) > +{ > + platform_driver_unregister(&z2_usb_switch_driver); > +} > + > +module_init(z2_usb_switch_init); > +module_exit(z2_usb_switch_exit); > -- > 1.7.12.4 > > > _______________________________________________ > linux-arm-kernel mailing list > linux-arm-kernel@lists.infradead.org > http://lists.infradead.org/mailman/listinfo/linux-arm-kernel A more fitting name might be something like "pxa270-usb-switch", since this isn't really z2 specific. Other pxa270 based devices could use it aswell.
On Sun, Oct 28, 2012 at 8:03 PM, Marko Kati? <dromede@gmail.com> wrote: > > A more fitting name might be something like "pxa270-usb-switch", since > this isn't really z2 specific. Other pxa270 based devices could use it > aswell. Sure. I'll wait for few more comments before sending v3 with fixed name. Regards Vasily
Dear Vasily Khoruzhick, > This driver controls mode of USB port #2 pins - device or host. Please supply proper commit message. This short message describes nothing. [...] > @@ -0,0 +1,100 @@ > +/* > + * USB mode switcher for Z2 > + * > + * Copyright (c) 2011 Vasily Khoruzhick 2012 > + * This program is free software; you can redistribute it and/or modify > + * it under the terms of the GNU General Public License version 2 as > + * published by the Free Software Foundation. > + * > + */ > + > +#include <linux/kernel.h> > +#include <linux/module.h> > +#include <linux/platform_device.h> > +#include <linux/delay.h> > + > +#include <mach/pxa27x.h> > +#include <mach/pxa27x-udc.h> > + > +#include <asm/io.h> > + > +#define MIN(a, b) ((a) < (b) ? (a) : (b)) min() is already defined in kernel.h > +static ssize_t usb_mode_show(struct device *dev, struct device_attribute > *attr, + char *buf) > +{ > + if (UP2OCR & UP2OCR_HXS) > + return sprintf(buf, "host\n"); > + else > + return sprintf(buf, "device\n"); > +} > + > +static ssize_t usb_mode_set(struct device *dev, struct device_attribute > *attr, + const char *buf, size_t count) > +{ > + if (strncmp(buf, "host", MIN(count, 4)) == 0) { > + UP2OCR = UP2OCR_HXS | UP2OCR_HXOE | UP2OCR_DPPDE | UP2OCR_DMPDE; > + return count; > + } else if (strncmp(buf, "device", MIN(count, 6)) == 0) { > + UP2OCR = UP2OCR_HXOE | UP2OCR_DPPUE; > + return count; > + } > + return -EINVAL; > +} > + > +static DEVICE_ATTR(usb_mode, 0644, usb_mode_show, usb_mode_set); I wonder if we have no better means to control enforcement of mode. > +static const struct attribute *attrs[] = { > + &dev_attr_usb_mode.attr, > + NULL, > +}; > + > +static const struct attribute_group attr_group = { > + .attrs = (struct attribute **)attrs, > +}; Isn't there some macro to do this assignment? > +static int z2_usb_switch_probe(struct platform_device *dev) Missing __devinit > +{ > + int res; > + > + res = sysfs_create_group(&dev->dev.kobj, &attr_group); > + if (res) > + return res; > + > + UP2OCR = UP2OCR_HXOE | UP2OCR_DPPUE; > + > + return 0; > +} > + > +static int __devexit z2_usb_switch_remove(struct platform_device *dev) > +{ > + UP2OCR = UP2OCR_HXOE; > + sysfs_remove_group(&dev->dev.kobj, &attr_group); > + > + return 0; > +} > + > +static struct platform_driver z2_usb_switch_driver = { > + .probe = z2_usb_switch_probe, > + .remove = __devexit_p(z2_usb_switch_remove), > + > + .driver = { > + .name = "z2-usb-switch", > + .owner = THIS_MODULE, > + }, > +}; > + > + > +static int __init z2_usb_switch_init(void) > +{ > + return platform_driver_register(&z2_usb_switch_driver); > +} > + > +static void __exit z2_usb_switch_exit(void) > +{ > + platform_driver_unregister(&z2_usb_switch_driver); > +} > + > +module_init(z2_usb_switch_init); > +module_exit(z2_usb_switch_exit); module_platform_driver() Best regards, Marek Vasut
On Mon, Oct 29, 2012 at 12:57 AM, Marek Vasut <marex@denx.de> wrote: > Dear Vasily Khoruzhick, Dear Marek Vasut, >> This driver controls mode of USB port #2 pins - device or host. > > Please supply proper commit message. This short message describes nothing. OK, "This driver allows user to choose USB port #2 mode between device and host" - that would be OK? > [...] > >> @@ -0,0 +1,100 @@ >> +/* >> + * USB mode switcher for Z2 >> + * >> + * Copyright (c) 2011 Vasily Khoruzhick > > 2012 Actually, it was implemented early in 2011, so 2011-2012 >> + * This program is free software; you can redistribute it and/or modify >> + * it under the terms of the GNU General Public License version 2 as >> + * published by the Free Software Foundation. >> + * >> + */ >> + >> +#include <linux/kernel.h> >> +#include <linux/module.h> >> +#include <linux/platform_device.h> >> +#include <linux/delay.h> >> + >> +#include <mach/pxa27x.h> >> +#include <mach/pxa27x-udc.h> >> + >> +#include <asm/io.h> >> + >> +#define MIN(a, b) ((a) < (b) ? (a) : (b)) > > min() is already defined in kernel.h OK >> +static ssize_t usb_mode_show(struct device *dev, struct device_attribute >> *attr, + char *buf) >> +{ >> + if (UP2OCR & UP2OCR_HXS) >> + return sprintf(buf, "host\n"); >> + else >> + return sprintf(buf, "device\n"); >> +} >> + >> +static ssize_t usb_mode_set(struct device *dev, struct device_attribute >> *attr, + const char *buf, size_t count) >> +{ >> + if (strncmp(buf, "host", MIN(count, 4)) == 0) { >> + UP2OCR = UP2OCR_HXS | UP2OCR_HXOE | UP2OCR_DPPDE | UP2OCR_DMPDE; >> + return count; >> + } else if (strncmp(buf, "device", MIN(count, 6)) == 0) { >> + UP2OCR = UP2OCR_HXOE | UP2OCR_DPPUE; >> + return count; >> + } >> + return -EINVAL; >> +} >> + >> +static DEVICE_ATTR(usb_mode, 0644, usb_mode_show, usb_mode_set); > > I wonder if we have no better means to control enforcement of mode. Why? sysfs fits nicely. >> +static const struct attribute *attrs[] = { >> + &dev_attr_usb_mode.attr, >> + NULL, >> +}; >> + >> +static const struct attribute_group attr_group = { >> + .attrs = (struct attribute **)attrs, >> +}; > > Isn't there some macro to do this assignment? Will check >> +static int z2_usb_switch_probe(struct platform_device *dev) > > Missing __devinit OK >> +{ >> + int res; >> + >> + res = sysfs_create_group(&dev->dev.kobj, &attr_group); >> + if (res) >> + return res; >> + >> + UP2OCR = UP2OCR_HXOE | UP2OCR_DPPUE; >> + >> + return 0; >> +} >> + >> +static int __devexit z2_usb_switch_remove(struct platform_device *dev) >> +{ >> + UP2OCR = UP2OCR_HXOE; >> + sysfs_remove_group(&dev->dev.kobj, &attr_group); >> + >> + return 0; >> +} >> + >> +static struct platform_driver z2_usb_switch_driver = { >> + .probe = z2_usb_switch_probe, >> + .remove = __devexit_p(z2_usb_switch_remove), >> + >> + .driver = { >> + .name = "z2-usb-switch", >> + .owner = THIS_MODULE, >> + }, >> +}; >> + >> + >> +static int __init z2_usb_switch_init(void) >> +{ >> + return platform_driver_register(&z2_usb_switch_driver); >> +} >> + >> +static void __exit z2_usb_switch_exit(void) >> +{ >> + platform_driver_unregister(&z2_usb_switch_driver); >> +} >> + >> +module_init(z2_usb_switch_init); >> +module_exit(z2_usb_switch_exit); > > module_platform_driver() OK > Best regards, > Marek Vasut Thanks for review! Regards Vasily
Dear Vasily Khoruzhick, > On Mon, Oct 29, 2012 at 12:57 AM, Marek Vasut <marex@denx.de> wrote: > > Dear Vasily Khoruzhick, > > Dear Marek Vasut, > > >> This driver controls mode of USB port #2 pins - device or host. > > > > Please supply proper commit message. This short message describes > > nothing. > > OK, "This driver allows user to choose USB port #2 mode between device > and host" - that would be OK? Please describe why is this needed at all and what it does. [...] > > I wonder if we have no better means to control enforcement of mode. > > Why? sysfs fits nicely. Because if there is already an API to implement this OTG in kernel, you should use that and not reinvent wheel. [...] Best regards, Marek Vasut
On Mon, Oct 29, 2012 at 1:38 AM, Marek Vasut <marex@denx.de> wrote: > Dear Vasily Khoruzhick, > >> On Mon, Oct 29, 2012 at 12:57 AM, Marek Vasut <marex@denx.de> wrote: >> > Dear Vasily Khoruzhick, >> >> Dear Marek Vasut, >> >> >> This driver controls mode of USB port #2 pins - device or host. >> > >> > Please supply proper commit message. This short message describes >> > nothing. >> >> OK, "This driver allows user to choose USB port #2 mode between device >> and host" - that would be OK? > > Please describe why is this needed at all and what it does. Because one might need USB device and USB host functionality provided by USB port #2? It switches pins mode from device to host and backwards. > [...] > >> > I wonder if we have no better means to control enforcement of mode. >> >> Why? sysfs fits nicely. > > Because if there is already an API to implement this OTG in kernel, you should > use that and not reinvent wheel. One needs to select USB mode manually (btw, Z2 can't even power USB device properly, only 3.3v or external 5v). There's no way to determine what type of device (device/host) connected to Z2 at the moment. > [...] > > Best regards, > Marek Vasut Regards Vasily
Dear Vasily Khoruzhick, > On Mon, Oct 29, 2012 at 1:38 AM, Marek Vasut <marex@denx.de> wrote: > > Dear Vasily Khoruzhick, > > > >> On Mon, Oct 29, 2012 at 12:57 AM, Marek Vasut <marex@denx.de> wrote: > >> > Dear Vasily Khoruzhick, > >> > >> Dear Marek Vasut, > >> > >> >> This driver controls mode of USB port #2 pins - device or host. > >> > > >> > Please supply proper commit message. This short message describes > >> > nothing. > >> > >> OK, "This driver allows user to choose USB port #2 mode between device > >> and host" - that would be OK? > > > > Please describe why is this needed at all and what it does. > > Because one might need USB device and USB host functionality provided > by USB port #2? > It switches pins mode from device to host and backwards. Good, now compile it into the commit message for v3 please. > > [...] > > > >> > I wonder if we have no better means to control enforcement of mode. > >> > >> Why? sysfs fits nicely. > > > > Because if there is already an API to implement this OTG in kernel, you > > should use that and not reinvent wheel. > > One needs to select USB mode manually (btw, Z2 can't even power USB > device properly, only 3.3v or external 5v). > There's no way to determine what type of device (device/host) > connected to Z2 at the moment. Good, so your OTG is software controlled. [...] Best regards, Marek Vasut
diff --git a/arch/arm/mach-pxa/Kconfig b/arch/arm/mach-pxa/Kconfig index 11aa739..5fffc4b 100644 --- a/arch/arm/mach-pxa/Kconfig +++ b/arch/arm/mach-pxa/Kconfig @@ -630,6 +630,13 @@ config MACH_ZIPIT2 bool "Zipit Z2 Handheld" select HAVE_PWM select PXA27x + +config Z2_USB_SWITCH + tristate "Control the state of USB port on Zipit Z2" + depends on MACH_ZIPIT2 + help + This is a simple driver that is able to control + usb mode of Zipit Z2 endif endmenu diff --git a/arch/arm/mach-pxa/Makefile b/arch/arm/mach-pxa/Makefile index ee88d6e..86a032f 100644 --- a/arch/arm/mach-pxa/Makefile +++ b/arch/arm/mach-pxa/Makefile @@ -99,3 +99,4 @@ obj-$(CONFIG_MACH_RAUMFELD_SPEAKER) += raumfeld.o obj-$(CONFIG_MACH_ZIPIT2) += z2.o obj-$(CONFIG_TOSA_BT) += tosa-bt.o +obj-$(CONFIG_Z2_USB_SWITCH) += z2-usb-switch.o diff --git a/arch/arm/mach-pxa/z2-usb-switch.c b/arch/arm/mach-pxa/z2-usb-switch.c new file mode 100644 index 0000000..9583092 --- /dev/null +++ b/arch/arm/mach-pxa/z2-usb-switch.c @@ -0,0 +1,100 @@ +/* + * USB mode switcher for Z2 + * + * Copyright (c) 2011 Vasily Khoruzhick + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + */ + +#include <linux/kernel.h> +#include <linux/module.h> +#include <linux/platform_device.h> +#include <linux/delay.h> + +#include <mach/pxa27x.h> +#include <mach/pxa27x-udc.h> + +#include <asm/io.h> + +#define MIN(a, b) ((a) < (b) ? (a) : (b)) + +static ssize_t usb_mode_show(struct device *dev, struct device_attribute *attr, + char *buf) +{ + if (UP2OCR & UP2OCR_HXS) + return sprintf(buf, "host\n"); + else + return sprintf(buf, "device\n"); +} + +static ssize_t usb_mode_set(struct device *dev, struct device_attribute *attr, + const char *buf, size_t count) +{ + if (strncmp(buf, "host", MIN(count, 4)) == 0) { + UP2OCR = UP2OCR_HXS | UP2OCR_HXOE | UP2OCR_DPPDE | UP2OCR_DMPDE; + return count; + } else if (strncmp(buf, "device", MIN(count, 6)) == 0) { + UP2OCR = UP2OCR_HXOE | UP2OCR_DPPUE; + return count; + } + return -EINVAL; +} + +static DEVICE_ATTR(usb_mode, 0644, usb_mode_show, usb_mode_set); + +static const struct attribute *attrs[] = { + &dev_attr_usb_mode.attr, + NULL, +}; + +static const struct attribute_group attr_group = { + .attrs = (struct attribute **)attrs, +}; + +static int z2_usb_switch_probe(struct platform_device *dev) +{ + int res; + + res = sysfs_create_group(&dev->dev.kobj, &attr_group); + if (res) + return res; + + UP2OCR = UP2OCR_HXOE | UP2OCR_DPPUE; + + return 0; +} + +static int __devexit z2_usb_switch_remove(struct platform_device *dev) +{ + UP2OCR = UP2OCR_HXOE; + sysfs_remove_group(&dev->dev.kobj, &attr_group); + + return 0; +} + +static struct platform_driver z2_usb_switch_driver = { + .probe = z2_usb_switch_probe, + .remove = __devexit_p(z2_usb_switch_remove), + + .driver = { + .name = "z2-usb-switch", + .owner = THIS_MODULE, + }, +}; + + +static int __init z2_usb_switch_init(void) +{ + return platform_driver_register(&z2_usb_switch_driver); +} + +static void __exit z2_usb_switch_exit(void) +{ + platform_driver_unregister(&z2_usb_switch_driver); +} + +module_init(z2_usb_switch_init); +module_exit(z2_usb_switch_exit);
This driver controls mode of USB port #2 pins - device or host. Signed-off-by: Vasily Khoruzhick <anarsoul@gmail.com> --- arch/arm/mach-pxa/Kconfig | 7 +++ arch/arm/mach-pxa/Makefile | 1 + arch/arm/mach-pxa/z2-usb-switch.c | 100 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 108 insertions(+) create mode 100644 arch/arm/mach-pxa/z2-usb-switch.c