Search
SailfishOS Open Build Service
>
Projects
>
home:dcthang:branches:nemo:devel:hw:ti:omap3:n900
>
kernel-adaptation-n900
> linux-2.6-usb-musb-add-mA-and-charger-sysfs-entries.patch
Log In
Username
Password
Cancel
Overview
Repositories
Revisions
Requests
Users
Advanced
Attributes
Meta
File linux-2.6-usb-musb-add-mA-and-charger-sysfs-entries.patch of Package kernel-adaptation-n900
From 05c35d6d71c6baae4e94b92e1ff209c20f72ad80 Mon Sep 17 00:00:00 2001 From: Felipe Balbi <felipe.balbi@nokia.com> Date: Mon, 4 Jan 2010 15:05:37 +0200 Subject: [PATCH 01/42] usb: musb: add mA and charger sysfs entries This is the same mA entry and charger entry used in Fremantle program. We are adding it as __deprecated because it will change and this is done just for us to be able to test USB charging funtionality. One difference from Fremantle is that we now issue sysfs_notify() when that value changes. Signed-off-by: Felipe Balbi <felipe.balbi@nokia.com> Signed-off-by: Ameya Palande <ameya.palande@nokia.com> --- drivers/usb/musb/musb_core.c | 29 +++++++++++++++++++++++++++++ drivers/usb/musb/musb_core.h | 2 ++ drivers/usb/musb/musb_gadget.c | 9 +++++++++ 3 files changed, 40 insertions(+), 0 deletions(-) diff --git a/drivers/usb/musb/musb_core.c b/drivers/usb/musb/musb_core.c index 99beebc..6ee2ba1 100644 --- a/drivers/usb/musb/musb_core.c +++ b/drivers/usb/musb/musb_core.c @@ -1801,6 +1801,27 @@ musb_vbus_show(struct device *dev, struct device_attribute *attr, char *buf) } static DEVICE_ATTR(vbus, 0644, musb_vbus_show, musb_vbus_store); +static ssize_t +musb_ma_show(struct device *dev, struct device_attribute *attr, char *buf) +{ + struct musb *musb = dev_to_musb(dev); + + return snprintf(buf, PAGE_SIZE, "%d\n", musb->power_draw); +} +static DEVICE_ATTR(mA, 0444, musb_ma_show, NULL); + +static ssize_t +musb_charger_show(struct device *dev, struct device_attribute *attr, char *buf) +{ + struct musb *musb = dev_to_musb(dev); + int charger; + + charger = otg_detect_charger(musb->xceiv); + + return snprintf(buf, PAGE_SIZE, "%d\n", charger); +} +static DEVICE_ATTR(charger, 0444, musb_charger_show, NULL); + #ifdef CONFIG_USB_GADGET_MUSB_HDRC /* Gadget drivers can't know that a host is connected so they might want @@ -1831,6 +1852,8 @@ static DEVICE_ATTR(srp, 0644, NULL, musb_srp_store); static struct attribute *musb_attributes[] = { &dev_attr_mode.attr, &dev_attr_vbus.attr, + &dev_attr_mA.attr, + &dev_attr_charger.attr, #ifdef CONFIG_USB_GADGET_MUSB_HDRC &dev_attr_srp.attr, #endif @@ -1848,11 +1871,17 @@ static void musb_irq_work(struct work_struct *data) { struct musb *musb = container_of(data, struct musb, irq_work); static int old_state; + static int old_power_draw; if (musb->xceiv->state != old_state) { old_state = musb->xceiv->state; sysfs_notify(&musb->controller->kobj, NULL, "mode"); } + + if (musb->power_draw != old_power_draw) { + old_power_draw = musb->power_draw; + sysfs_notify(&musb->controller->kobj, NULL, "mA"); + } } /* -------------------------------------------------------------------------- diff --git a/drivers/usb/musb/musb_core.h b/drivers/usb/musb/musb_core.h index febaabc..16061a9 100644 --- a/drivers/usb/musb/musb_core.h +++ b/drivers/usb/musb/musb_core.h @@ -402,6 +402,8 @@ struct musb { u8 min_power; /* vbus for periph, in mA/2 */ + unsigned power_draw __deprecated; /* current power drawn, gadget only */ + bool is_host; int a_wait_bcon; /* VBUS timeout in msecs */ diff --git a/drivers/usb/musb/musb_gadget.c b/drivers/usb/musb/musb_gadget.c index 9d6ade8..927a420 100644 --- a/drivers/usb/musb/musb_gadget.c +++ b/drivers/usb/musb/musb_gadget.c @@ -1588,8 +1588,17 @@ static int musb_gadget_vbus_draw(struct usb_gadget *gadget, unsigned mA) { struct musb *musb = gadget_to_musb(gadget); + /* REVISIT we shouldn't need to be passing + * this kind of value to userland. We have + * now the blocking notifier for transceivers + * which could very well handle this + */ + musb->power_draw = mA; + schedule_work(&musb->irq_work); + if (!musb->xceiv->set_power) return -EOPNOTSUPP; + return otg_set_power(musb->xceiv, mA); } -- 1.7.0.4