Kernel->usbdev: add class node to enable/disable otg usb
This commit is contained in:
@ -973,10 +973,52 @@ static const struct of_device_id rk_usb_control_id_table[] = {
|
||||
|
||||
#endif
|
||||
|
||||
static ssize_t firefly_otg_read_ctl_status(struct class *cls, struct class_attribute *attr, char *_buf)
|
||||
{
|
||||
return sprintf(_buf, "%d\n", gpio_get_value(control_usb->otg_gpios->gpio));
|
||||
}
|
||||
|
||||
static ssize_t firefly_otg_write_ctl_status(struct class *cls, struct class_attribute *attr, const char *_buf, size_t _count)
|
||||
{
|
||||
if('0' == _buf[0])
|
||||
{
|
||||
gpio_direction_output(control_usb->otg_gpios->gpio, 0);
|
||||
}
|
||||
else if(_buf[0]>'0')
|
||||
{
|
||||
gpio_direction_output(control_usb->otg_gpios->gpio, 1);
|
||||
}
|
||||
return _count;
|
||||
}
|
||||
|
||||
static ssize_t firefly_host_read_ctl_status(struct class *cls, struct class_attribute *attr, char *_buf)
|
||||
{
|
||||
return sprintf(_buf, "%d\n", gpio_get_value(control_usb->host_gpios->gpio));
|
||||
}
|
||||
|
||||
static ssize_t firefly_host_write_ctl_status(struct class *cls, struct class_attribute *attr, const char *_buf, size_t _count)
|
||||
{
|
||||
if('0' == _buf[0])
|
||||
{
|
||||
gpio_direction_output(control_usb->host_gpios->gpio, 0);
|
||||
}
|
||||
else if(_buf[0]>'0')
|
||||
{
|
||||
gpio_direction_output(control_usb->host_gpios->gpio, 1);
|
||||
}
|
||||
return _count;
|
||||
}
|
||||
|
||||
|
||||
static CLASS_ATTR(otg_hw_ctl, 0666, firefly_otg_read_ctl_status, firefly_otg_write_ctl_status);
|
||||
static CLASS_ATTR(host_hw_ctl, 0666, firefly_host_read_ctl_status, firefly_host_write_ctl_status);
|
||||
|
||||
static int rk_usb_control_probe(struct platform_device *pdev)
|
||||
{
|
||||
int gpio, err;
|
||||
struct device_node *np = pdev->dev.of_node;
|
||||
struct class *otg_drv_class;
|
||||
struct class *host_drv_class;
|
||||
int ret = 0;
|
||||
|
||||
control_usb =
|
||||
@ -1047,6 +1089,23 @@ static int rk_usb_control_probe(struct platform_device *pdev)
|
||||
gpio_direction_output(control_usb->otg_gpios->gpio, 0);
|
||||
}
|
||||
|
||||
host_drv_class = class_create(THIS_MODULE, "host_hw_ctl");
|
||||
if(IS_ERR(host_drv_class))
|
||||
printk("create host class failed \r\n");
|
||||
else
|
||||
{
|
||||
ret = class_create_file(host_drv_class, &class_attr_host_hw_ctl);
|
||||
}
|
||||
|
||||
|
||||
otg_drv_class = class_create(THIS_MODULE, "otg_hw_ctl");
|
||||
if(IS_ERR(otg_drv_class))
|
||||
printk("create otg class failed \r\n");
|
||||
else
|
||||
{
|
||||
ret = class_create_file(otg_drv_class, &class_attr_otg_hw_ctl);
|
||||
}
|
||||
|
||||
out:
|
||||
return ret;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user