[PATCH] introduce-usb-host-power-control.patch

Felipe Balbi me at felipebalbi.com
Wed Mar 12 02:09:01 CET 2008


On Tue, Mar 11, 2008 at 09:25:41PM +0000, Andy Green wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
> 
> Hm... I didn't find any support for this in the kernel... I didn't see
> it in U-Boot...  either I missed the point badly or we don't seem to
> have tested this?  It seems to work fine anyway.

Actually this should be done automatically, again based on id_pin
status.

I'm inlining your patch below for commenting on it.

BTW, try using git send-email for that.
The patch becomes a lot better for handling with git later ;-)
also easier to review as it come inlined in the mail ;-)

> introduce-usb-host-power-control.patch
> 
> From: Andy Green <andy at openmoko.com>
> 
> Unless I really really missed the point, there is no support for enabling
> USB Host power for USB host mode.  This patch adds a /sys node for GTA02
> that allows control of the charge pump for 5V out on the USB mini connector
> It doesn't change any logical mode in the CPU, just enables (1) and disables
> (0) USB host power.
> 
> # cat /sys/devices/platform/neo1973-pm-host.0/hostmode
> 0
> # echo 1 > /sys/devices/platform/neo1973-pm-host.0/hostmode

this should really be under ohci-s3c....

> 
> Signed-off-by: Andy Green <andy at openmoko.com>
> ---
> 
>  arch/arm/mach-s3c2440/mach-gta02.c      |    6 ++
>  arch/arm/plat-s3c24xx/Makefile          |    2 -
>  arch/arm/plat-s3c24xx/neo1973_pm_host.c |  101 +++++++++++++++++++++++++++++++
>  3 files changed, 108 insertions(+), 1 deletions(-)
>  create mode 100644 arch/arm/plat-s3c24xx/neo1973_pm_host.c
> 
> 
> diff --git a/arch/arm/mach-s3c2440/mach-gta02.c b/arch/arm/mach-s3c2440/mach-gta02.c
> index 0fd4853..fd6df94 100644
> --- a/arch/arm/mach-s3c2440/mach-gta02.c
> +++ b/arch/arm/mach-s3c2440/mach-gta02.c
> @@ -1020,6 +1020,11 @@ static struct platform_device gta01_pm_gsm_dev = {
>  	.name		= "neo1973-pm-gsm",
>  };
>  
> +static struct platform_device gta02_pm_usbhost_dev = {
> +	.name		= "neo1973-pm-host",
> +};
> +

I don't really like this approach. You should just have something
sampling id pin and when it goes grounded then you switch charge pump
on.

> +
>  /* USB */
>  static struct s3c2410_hcd_info gta02_usb_info = {
>  	.port[0]	= {
> @@ -1263,6 +1268,7 @@ static void __init gta02_machine_init(void)
>  	platform_device_register(&s3c_device_spi_acc);
>  	platform_device_register(&gta01_button_dev);
>  	platform_device_register(&gta01_pm_gsm_dev);
> +	platform_device_register(&gta02_pm_usbhost_dev);
>  
>  	mangle_pmu_pdata_by_system_rev();
>  	platform_device_register(&gta02_pmu_dev);
> diff --git a/arch/arm/plat-s3c24xx/Makefile b/arch/arm/plat-s3c24xx/Makefile
> index 7192912..e1686a0 100644
> --- a/arch/arm/plat-s3c24xx/Makefile
> +++ b/arch/arm/plat-s3c24xx/Makefile
> @@ -28,4 +28,4 @@ obj-$(CONFIG_PM)		+= pm.o
>  obj-$(CONFIG_PM)		+= sleep.o
>  obj-$(CONFIG_S3C2410_DMA)	+= dma.o
>  obj-$(CONFIG_MACH_SMDK)		+= common-smdk.o
> -obj-$(CONFIG_MACH_NEO1973)	+= neo1973_pm_gsm.o neo1973_pm_gps.o neo1973_pm_bt.o
> +obj-$(CONFIG_MACH_NEO1973)	+= neo1973_pm_host.o neo1973_pm_gsm.o neo1973_pm_gps.o neo1973_pm_bt.o
> diff --git a/arch/arm/plat-s3c24xx/neo1973_pm_host.c b/arch/arm/plat-s3c24xx/neo1973_pm_host.c
> new file mode 100644
> index 0000000..4eae341
> --- /dev/null
> +++ b/arch/arm/plat-s3c24xx/neo1973_pm_host.c
> @@ -0,0 +1,101 @@
> +/*
> + * Bluetooth PM code for the FIC Neo1973 GSM Phone

Err... USB ??

> + *
> + * (C) 2007 by OpenMoko Inc.
> + * Author: Harald Welte <laforge at openmoko.org>
> + * All rights reserved.
> + *
> + * 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/module.h>
> +#include <linux/init.h>
> +#include <linux/kernel.h>
> +#include <linux/platform_device.h>
> +
> +#include <asm/hardware.h>
> +#include <asm/mach-types.h>
> +
> +#ifdef CONFIG_MACH_NEO1973_GTA02
> +#include <asm/arch/gta02.h>
> +#include <linux/pcf50633.h>
> +
> +static ssize_t pm_host_read(struct device *dev, struct device_attribute *attr,
> +			    char *buf)
> +{
> +	return sprintf(buf, "%d\n",
> +		       pcf50633_gpio_get(pcf50633_global, PCF50633_GPO));
> +}
> +
> +static ssize_t pm_host_write(struct device *dev, struct device_attribute *attr,
> +			     const char *buf, size_t count)
> +{
> +	unsigned long on = simple_strtoul(buf, NULL, 10);
> +
> +	pcf50633_gpio_set(pcf50633_global, PCF50633_GPO, on);

ahaa... so it's gpio-based.
How about puting a gpio_request() call in ohci (or maybe board files)
module for this device ?

> +
> +	return count;
> +}
> +
> +static DEVICE_ATTR(hostmode, 0644, pm_host_read, pm_host_write);
> +
> +static struct attribute *neo1973_pm_host_sysfs_entries[] = {
> +	&dev_attr_hostmode.attr,
> +	NULL
> +};
> +
> +static struct attribute_group neo1973_pm_host_attr_group = {
> +	.name	= NULL,
> +	.attrs	= neo1973_pm_host_sysfs_entries,
> +};
> +
> +static int __init neo1973_pm_host_probe(struct platform_device *pdev)
> +{
> +	dev_info(&pdev->dev, "starting\n");

this could be dev_dbg(), this message is only useful on debugging
purposes, also something more explanatory would be cool :-)

something like:

dev_dbg(&pdev->dev, "Neo1973 USB PM\n");

> +
> +	switch (machine_arch_type) {
> +#ifdef CONFIG_MACH_NEO1973_GTA01
> +	case MACH_TYPE_NEO1973_GTA01:
> +		return -EINVAL;
> +#endif /* CONFIG_MACH_NEO1973_GTA01 */
> +	default:
> +		break;
> +	}

how about:
if (machine_is_neo1973_gta01())
	return -EINVAL;

> +
> +	return sysfs_create_group(&pdev->dev.kobj, &neo1973_pm_host_attr_group);
> +}
> +
> +static int neo1973_pm_host_remove(struct platform_device *pdev)
> +{
> +	sysfs_remove_group(&pdev->dev.kobj, &neo1973_pm_host_attr_group);
> +	return 0;
> +}
> +
> +static struct platform_driver neo1973_pm_host_driver = {
> +	.probe		= neo1973_pm_host_probe,
> +	.remove		= neo1973_pm_host_remove,
> +	.driver		= {
> +		.name		= "neo1973-pm-host",
> +	},
> +};
> +
> +static int __devinit neo1973_pm_host_init(void)
> +{
> +	return platform_driver_register(&neo1973_pm_host_driver);
> +}
> +
> +static void neo1973_pm_host_exit(void)
> +{
> +	platform_driver_unregister(&neo1973_pm_host_driver);
> +}
> +
> +module_init(neo1973_pm_host_init);
> +module_exit(neo1973_pm_host_exit);
> +
> +MODULE_LICENSE("GPL");
> +MODULE_AUTHOR("Andy Green <andy at openmoko.com>");
> +MODULE_DESCRIPTION("Neo1973 USB Host Power Management");
> +#endif

If you don't mind, I'd really like to redesign this. Tomorrow I
scheduled to start coding linux-moko-2.6 as off now I just did the
Makefile changes.

I'll start putting together some board-files and the basic support,
after that I'll start fixing up mokopatches to make them acceptable on
mailine :-)

-- 
Best Regards,

Felipe Balbi
me at felipebalbi.com
http://blog.felipebalbi.com




More information about the openmoko-kernel mailing list