usb hub模块调试

1.usb hub设备树:
	hsic-usb-hub{
        compatible = "hub_reset";
        reset,pin =<&gpio7 GPIO_A6 GPIO_ACTIVE_HIGH>;   // hub reset pin
        status = "disabled";
    };



2.对应的代码:	
	#include <dt-bindings/gpio/gpio.h>
	#include <linux/gpio.h>
	#include <linux/of_gpio.h>
	#include <linux/module.h>
	#include <linux/kernel.h>
	#include <linux/init.h>
	#include <linux/platform_device.h>
	#include <linux/fb.h>
	#include <linux/backlight.h>
	#include <linux/err.h>
	#include <linux/pwm.h>
	#include <linux/pwm_backlight.h>
	#include <linux/slab.h>
	#include <linux/delay.h>

	static struct of_device_id hub_reset_of_match[] = {
		{ .compatible = "hub_reset" },
		{ }
	};
	MODULE_DEVICE_TABLE(of, hub_reset_of_match);


	static int hub_reset_probe(struct platform_device *pdev)
	{
		struct device_node *node = pdev->dev.of_node;
		enum of_gpio_flags flags;  //gpio标志  高低电平 自我认为 不对请指正
		int gpio, ret,en_value;

		if (!node)
			return -ENODEV;
		//获取gpio序号及有效标志,实际上是通过gpios属性获取  
		gpio = of_get_named_gpio_flags(node, "reset,pin", 0, &flags);
		en_value = (flags == GPIO_ACTIVE_HIGH)? 1:0;
		//gpio =  of_get_named_gpio(node, "gpios", 0);
		//检验gpio是否有效
		if(!gpio_is_valid(gpio)){
			dev_err(&pdev->dev, "invalid hub rst gpio%d\n", gpio);
		}
		//	申请gpio
		ret = devm_gpio_request(&pdev->dev, gpio, "hub_rst_gpio");
		if (ret) {
			dev_err(&pdev->dev, "failed to request GPIO%d for ohub_rst_drv\n", gpio);
			return -EINVAL;
		}
		gpio_direction_output(gpio, 1);
		// msleep(10);
		// gpio_direction_output(gpio, 0);
		// msleep(10);
		// gpio_direction_output(gpio, 1);
		// msleep(1);
		return 0;
	}

	static int hub_reset_remove(struct platform_device *pdev)
	{
		//printk("func: %s\n", __func__); 
		return 0;
	}

	#ifdef CONFIG_PM_SLEEP
	static int hub_reset_suspend(struct device *dev)
	{
		//printk("func: %s\n", __func__); 
		return 0;
	}

	static int hub_reset_resume(struct device *dev)
	{
		//printk("func: %s\n", __func__); 
		return 0;
	}
	#endif
	//电源管理
	static const struct dev_pm_ops hub_reset_pm_ops = {
	#ifdef CONFIG_PM_SLEEP
		.suspend	= hub_reset_suspend,
		.resume		= hub_reset_resume,
		.poweroff	= hub_reset_suspend,
		.restore	= hub_reset_resume,
	#endif
	};

	static struct platform_driver hub_reset_driver = {
		.driver		= {
			.name		= "_hsic_hub_reset",
			.owner		= THIS_MODULE,
			.pm			= &hub_reset_pm_ops,
			.of_match_table	= of_match_ptr(hub_reset_of_match),
		},
		.probe		= hub_reset_probe,
		.remove		= hub_reset_remove,
	};

	module_platform_driver(hub_reset_driver);
	MODULE_DESCRIPTION("hsic usb hub reset");
	MODULE_LICENSE("GPL");
	MODULE_ALIAS("platform: hsic usb hub");	


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值