On Wed, Jan 08, 2014 at 05:06:24PM +0800, Li Jun wrote: > This patch adds sys input to control and show OTG fsm inputs by application, > user can do host and preipheral role switch by change these inputs. > > Signed-off-by: Li Jun <b47624@xxxxxxxxxxxxx> > --- > drivers/usb/chipidea/otg.c | 1 + > drivers/usb/chipidea/otg_fsm.c | 204 ++++++++++++++++++++++++++++++++++++++++ > drivers/usb/chipidea/otg_fsm.h | 6 + > 3 files changed, 211 insertions(+), 0 deletions(-) > > diff --git a/drivers/usb/chipidea/otg.c b/drivers/usb/chipidea/otg.c > index 5914c92..09099e5 100644 > --- a/drivers/usb/chipidea/otg.c > +++ b/drivers/usb/chipidea/otg.c > @@ -129,4 +129,5 @@ void ci_hdrc_otg_destroy(struct ci_hdrc *ci) > } > ci_disable_otg_interrupt(ci, OTGSC_INT_EN_BITS); > ci_clear_otg_interrupt(ci, OTGSC_INT_STATUS_BITS); > + ci_hdrc_otg_fsm_remove(ci); > } > diff --git a/drivers/usb/chipidea/otg_fsm.c b/drivers/usb/chipidea/otg_fsm.c > index 60465ab..8124a64 100644 > --- a/drivers/usb/chipidea/otg_fsm.c > +++ b/drivers/usb/chipidea/otg_fsm.c > @@ -27,6 +27,7 @@ > #include "otg_fsm.h" > > static struct list_head active_timers; > +static struct ci_hdrc *ci_hdrc_p; > > #define HA_DATA_PULSE 1 > > @@ -51,6 +52,195 @@ inline struct ci_otg_fsm_timer *otg_timer_initializer > return timer; > } > > +/* Add for otg: interact with user space app */ > +static ssize_t > +get_a_bus_req(struct device *dev, struct device_attribute *attr, char *buf) > +{ > + char *next; > + unsigned size, t; > + struct ci_hdrc *ci = ci_hdrc_p; > + > + next = buf; > + size = PAGE_SIZE; > + > + if (ci->transceiver && ci->transceiver->otg && ci->fsm) { > + t = scnprintf(next, size, "%d", ci->fsm->a_bus_req); > + size -= t; > + next += t; > + } else > + dev_err(ci->dev, "error: otg setup is not completed!\n"); > + > + return PAGE_SIZE - size; > +} > + > +static ssize_t > +set_a_bus_req(struct device *dev, struct device_attribute *attr, > + const char *buf, size_t count) > +{ > + struct ci_hdrc *ci = ci_hdrc_p; > + > + if (count > 2) > + return -1; > + > + mutex_lock(&ci->fsm->lock); > + if (ci->transceiver && ci->transceiver->otg && ci->fsm) { > + if (buf[0] == '0') { > + ci->fsm->a_bus_req = 0; > + } else if (buf[0] == '1') { > + /* If a_bus_drop is TRUE, a_bus_req can't be set */ > + if (ci->fsm->a_bus_drop) > + goto end; > + ci->fsm->a_bus_req = 1; > + if (ci->transceiver->state == OTG_STATE_A_PERIPHERAL) { > + ci->gadget.host_request_flag = 1; > + goto end; > + } > + } > + > + disable_irq_nosync(ci->irq); > + queue_work(ci->wq, &ci->work); > + } else > + dev_err(ci->dev, "error: otg setup is not completed!\n"); > +end: > + mutex_unlock(&ci->fsm->lock); > + > + return count; > +} > +static DEVICE_ATTR(a_bus_req, S_IRUGO | S_IWUSR, get_a_bus_req, set_a_bus_req); > + > +static ssize_t > +get_a_bus_drop(struct device *dev, struct device_attribute *attr, char *buf) > +{ > + char *next; > + unsigned size, t; > + struct ci_hdrc *ci = ci_hdrc_p; it is ci dev? if it is, you can use ci = dev_get_drvdata(dev); Peter > + > + next = buf; > + size = PAGE_SIZE; > + if (ci->transceiver && ci->transceiver->otg && ci->fsm) { > + t = scnprintf(next, size, "%d", ci->fsm->a_bus_drop); > + size -= t; > + next += t; > + } else > + dev_err(ci->dev, "error: otg setup is not completed!\n"); > + > + return PAGE_SIZE - size; > +} > + > +static ssize_t > +set_a_bus_drop(struct device *dev, struct device_attribute *attr, > + const char *buf, size_t count) > +{ > + struct ci_hdrc *ci = ci_hdrc_p; > + > + if (count > 2) > + return -1; > + > + mutex_lock(&ci->fsm->lock); > + if (ci->transceiver && ci->transceiver->otg && ci->fsm) { > + if (buf[0] == '0') { > + ci->fsm->a_bus_drop = 0; > + } else if (buf[0] == '1') { > + ci->fsm->a_bus_drop = 1; > + ci->fsm->a_bus_req = 0; > + } > + > + disable_irq_nosync(ci->irq); > + queue_work(ci->wq, &ci->work); > + } > + mutex_unlock(&ci->fsm->lock); > + > + return count; > +} > +static DEVICE_ATTR(a_bus_drop, S_IRUGO | S_IWUSR, get_a_bus_drop, > + set_a_bus_drop); > + > +static ssize_t > +get_b_bus_req(struct device *dev, struct device_attribute *attr, char *buf) > +{ > + char *next; > + unsigned size, t; > + struct ci_hdrc *ci = ci_hdrc_p; > + > + next = buf; > + size = PAGE_SIZE; > + > + if (ci->transceiver && ci->transceiver->otg && ci->fsm) { > + t = scnprintf(next, size, "%d", ci->fsm->b_bus_req); > + size -= t; > + next += t; > + } > + > + return PAGE_SIZE - size; > +} > + > +static ssize_t > +set_b_bus_req(struct device *dev, struct device_attribute *attr, > + const char *buf, size_t count) > +{ > + struct ci_hdrc *ci = ci_hdrc_p; > + > + if (count > 2) > + return -1; > + > + mutex_lock(&ci->fsm->lock); > + if (ci->transceiver && ci->transceiver->otg && ci->fsm) { > + if (buf[0] == '0') > + ci->fsm->b_bus_req = 0; > + else if (buf[0] == '1') { > + ci->fsm->b_bus_req = 1; > + if (ci->transceiver->state == OTG_STATE_B_PERIPHERAL) { > + ci->gadget.host_request_flag = 1; > + goto end; > + } > + } > + > + disable_irq_nosync(ci->irq); > + queue_work(ci->wq, &ci->work); > + } > +end: > + mutex_unlock(&ci->fsm->lock); > + > + return count; > +} > +static DEVICE_ATTR(b_bus_req, S_IRUGO | S_IWUSR, get_b_bus_req, set_b_bus_req); > + > +static ssize_t > +set_a_clr_err(struct device *dev, struct device_attribute *attr, > + const char *buf, size_t count) > +{ > + struct ci_hdrc *ci = ci_hdrc_p; > + > + if (count > 2) > + return -1; > + > + mutex_lock(&ci->fsm->lock); > + if (ci->transceiver && ci->transceiver->otg && ci->fsm) { > + if (buf[0] == '1') > + ci->fsm->a_clr_err = 1; > + > + disable_irq_nosync(ci->irq); > + queue_work(ci->wq, &ci->work); > + } > + mutex_unlock(&ci->fsm->lock); > + > + return count; > +} > +static DEVICE_ATTR(a_clr_err, S_IWUSR, NULL, set_a_clr_err); > + > +static struct attribute *inputs_attrs[] = { > + &dev_attr_a_bus_req.attr, > + &dev_attr_a_bus_drop.attr, > + &dev_attr_b_bus_req.attr, > + &dev_attr_a_clr_err.attr, > + NULL, > +}; > + > +static struct attribute_group inputs_attr_group = { > + .name = "inputs", > + .attrs = inputs_attrs, > +}; > + > /* Add timer to timer list */ > void ci_otg_add_timer(struct ci_hdrc *ci, struct ci_otg_fsm_timer *gtimer) > { > @@ -764,6 +954,7 @@ int ci_hdrc_otg_fsm_init(struct ci_hdrc *ci) > { > int retval = 0; > > + ci_hdrc_p = ci; > if (ci->transceiver == NULL) > return -EPROBE_DEFER; > > @@ -803,6 +994,14 @@ int ci_hdrc_otg_fsm_init(struct ci_hdrc *ci) > > setup_timer(&ci->fsm->hnp_polling_timer, hnp_polling_timer_work, > (unsigned long)ci); > + > + retval = sysfs_create_group(&ci->dev->kobj, &inputs_attr_group); > + if (retval < 0) { > + dev_dbg(ci->dev, > + "Can't register sysfs attr group: %d\n", retval); > + return retval; > + } > + > /* enable ID and A vbus valid irq */ > hw_write(ci, OP_OTGSC, OTGSC_INT_EN_BITS | OTGSC_INT_STATUS_BITS, > OTGSC_IDIE | OTGSC_AVVIE); > @@ -816,3 +1015,8 @@ int ci_hdrc_otg_fsm_init(struct ci_hdrc *ci) > > return 0; > } > + > +void ci_hdrc_otg_fsm_remove(struct ci_hdrc *ci) > +{ > + sysfs_remove_group(&ci->dev->kobj, &inputs_attr_group); > +} > diff --git a/drivers/usb/chipidea/otg_fsm.h b/drivers/usb/chipidea/otg_fsm.h > index 812efaa..a4b5792 100644 > --- a/drivers/usb/chipidea/otg_fsm.h > +++ b/drivers/usb/chipidea/otg_fsm.h > @@ -93,6 +93,7 @@ int ci_hdrc_otg_fsm_init(struct ci_hdrc *ci); > int ci_otg_fsm_work(struct ci_hdrc *ci); > irqreturn_t ci_otg_fsm_irq(struct ci_hdrc *ci); > void ci_hdrc_otg_fsm_start(struct ci_hdrc *ci); > +void ci_hdrc_otg_fsm_remove(struct ci_hdrc *ci); > > #else > > @@ -116,6 +117,11 @@ static inline void ci_hdrc_otg_fsm_start(struct ci_hdrc *ci) > > } > > +static inline void ci_hdrc_otg_fsm_remove(struct ci_hdrc *ci) > +{ > + > +} > + > #endif > > #endif /* __DRIVERS_USB_CHIPIDEA_OTG_FSM_H */ > -- > 1.7.8 > > -- Best Regards, Peter Chen -- To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html