tiny4412 驱动 (3)网卡驱动移植

网卡驱动是后面驱动的基础

 

型号 DM9621

USB_HOST_ETHNET_DP1+ USB4604

USB_HOST_ETHNET_DP1- USB4604

其中USB4604有四路USB

一路接网卡DM9621, 一路引出标号USBH3, 另外两路USBH1heUSBH2,都是usb-typeA

对于USB4604

复位信号 : GPM2_4_USBRST , 接B35

XuhostDATA1 B59

XuhostSTROBE1 B57

相关驱动

drivers/usb/misc/usb4604.c

enum usb4604_mode {
        USB4604_MODE_UNKNOWN,
        USB4604_MODE_HUB,
        USB4604_MODE_STANDBY,
};

#ifdef CONFIG_OF
static const struct of_device_id usb4604_of_match[] = {
        { .compatible = "smsc,usb4604" },
        {}
};
MODULE_DEVICE_TABLE(of, usb4604_of_match);
#endif

static struct i2c_driver usb4604_i2c_driver = {
        .driver = {
                .name = "usb4604",
                .pm = &usb4604_i2c_pm_ops,
                .of_match_table = of_match_ptr(usb4604_of_match),
        },
        .probe          = usb4604_i2c_probe,
        .id_table       = usb4604_id,
};
module_i2c_driver(usb4604_i2c_driver);

注意这里没有使用module_init等来加载驱动,而是使用module_i2c_driver, 说明还需要IIC

根据网上资料把相同目录的drivers/usb/misc/usb3503.c移植过来就可以了

此外还有include/linux/platform_data/usb3503.h

cp include/linux/platform_data/usb3503.h include/linux/platform_data/usb4604.h
cp drivers/usb/misc/usb3503.c drivers/usb/misc/usb4604.c

vim include/linux/platform_data/usb4604.h

/* SPDX-License-Identifier: GPL-2.0 */
#ifndef __USB4604_H__
#define __USB4604_H__

#define USB4604_I2C_NAME        "usb4604"

#define USB4604_OFF_PORT1       (1 << 1)
#define USB4604_OFF_PORT2       (1 << 2)
#define USB6604_OFF_PORT3       (1 << 3)

enum usb4604_mode {
        USB4604_MODE_UNKNOWN,
        USB4604_MODE_HUB,
        USB4604_MODE_STANDBY,
};

struct usb4604_platform_data {
        enum usb4604_mode       initial_mode;
        u8      port_off_mask;
        int     gpio_intn;
        int     gpio_connect;
        int     gpio_reset;
};

#endif

vim drivers/usb/misc/usb4604.c

// SPDX-License-Identifier: GPL-2.0+
/*
 * Driver for SMSC USB4604 USB 2.0 hub controller driver
 *
 * Copyright (c) 2012-2013 Dongjin Kim ([email protected])
 */

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 

#define USB4604_VIDL		0x00
#define USB4604_VIDM		0x01
#define USB4604_PIDL		0x02
#define USB4604_PIDM		0x03
#define USB4604_DIDL		0x04
#define USB4604_DIDM		0x05

#define USB4604_CFG1		0x06
#define USB4604_SELF_BUS_PWR	(1 << 7)

#define USB4604_CFG2		0x07
#define USB4604_CFG3		0x08
#define USB4604_NRD		0x09

#define USB4604_PDS		0x0a

#define USB4604_SP_ILOCK	0xe7
#define USB4604_SPILOCK_CONNECT	(1 << 1)
#define USB4604_SPILOCK_CONFIG	(1 << 0)

#define USB4604_CFGP		0xee
#define USB4604_CLKSUSP		(1 << 7)

#define USB4604_RESET		0xff

struct usb4604 {
	enum usb4604_mode	mode;
	struct regmap		*regmap;
	struct device		*dev;
	struct clk		*clk;
	u8	port_off_mask;
	int	gpio_intn;
	int	gpio_reset;
	int	gpio_connect;
	bool	secondary_ref_clk;
};

static int usb4604_reset(struct usb4604 *hub, int state)
{
	if (!state && gpio_is_valid(hub->gpio_connect))
		gpio_set_value_cansleep(hub->gpio_connect, 0);

	if (gpio_is_valid(hub->gpio_reset))
		gpio_set_value_cansleep(hub->gpio_reset, state);

	/* Wait T_HUBINIT == 4ms for hub logic to stabilize */
	if (state)
		usleep_range(4000, 10000);

	return 0;
}

static int usb4604_connect(struct usb4604 *hub)
{
	struct device *dev = hub->dev;
	int err;

	usb4604_reset(hub, 1);

	if (hub->regmap) {
		/* SP_ILOCK: set connect_n, config_n for config */
		err = regmap_write(hub->regmap, USB4604_SP_ILOCK,
			   (USB4604_SPILOCK_CONNECT
				 | USB4604_SPILOCK_CONFIG));
		if (err < 0) {
			dev_err(dev, "SP_ILOCK failed (%d)\n", err);
			return err;
		}

		/* PDS : Set the ports which are disabled in self-powered mode. */
		if (hub->port_off_mask) {
			err = regmap_update_bits(hub->regmap, USB4604_PDS,
					hub->port_off_mask,
					hub->port_off_mask);
			if (err < 0) {
				dev_err(dev, "PDS failed (%d)\n", err);
				return err;
			}
		}

		/* CFG1 : Set SELF_BUS_PWR, this enables self-powered operation. */
		err = regmap_update_bits(hub->regmap, USB4604_CFG1,
					 USB4604_SELF_BUS_PWR,
					 USB4604_SELF_BUS_PWR);
		if (err < 0) {
			dev_err(dev, "CFG1 failed (%d)\n", err);
			return err;
		}

		/* SP_LOCK: clear connect_n, config_n for hub connect */
		err = regmap_update_bits(hub->regmap, USB4604_SP_ILOCK,
					 (USB4604_SPILOCK_CONNECT
					  | USB4604_SPILOCK_CONFIG), 0);
		if (err < 0) {
			dev_err(dev, "SP_ILOCK failed (%d)\n", err);
			return err;
		}
	}

	if (gpio_is_valid(hub->gpio_connect))
		gpio_set_value_cansleep(hub->gpio_connect, 1);

	hub->mode = USB4604_MODE_HUB;
	dev_info(dev, "switched to HUB mode\n");

	return 0;
}

static int usb4604_switch_mode(struct usb4604 *hub, enum usb4604_mode mode)
{
	struct device *dev = hub->dev;
	int err = 0;

	switch (mode) {
	case USB4604_MODE_HUB:
		err = usb4604_connect(hub);
		break;

	case USB4604_MODE_STANDBY:
		usb4604_reset(hub, 0);
		dev_info(dev, "switched to STANDBY mode\n");
		break;

	default:
		dev_err(dev, "unknown mode is requested\n");
		err = -EINVAL;
		break;
	}

	return err;
}

static const struct regmap_config usb4604_regmap_config = {
	.reg_bits = 8,
	.val_bits = 8,

	.max_register = USB4604_RESET,
};

static int usb4604_probe(struct usb4604 *hub)
{
	struct device *dev = hub->dev;
	struct usb4604_platform_data *pdata = dev_get_platdata(dev);
	struct device_node *np = dev->of_node;
	int err;
	u32 mode = USB4604_MODE_HUB;
	const u32 *property;
	int len;

	if (pdata) {
		hub->port_off_mask	= pdata->port_off_mask;
		hub->gpio_intn		= pdata->gpio_intn;
		hub->gpio_connect	= pdata->gpio_connect;
		hub->gpio_reset		= pdata->gpio_reset;
		hub->mode		= pdata->initial_mode;
	} else if (np) {
		struct clk *clk;
		u32 rate = 0;
		hub->port_off_mask = 0;

		if (!of_property_read_u32(np, "refclk-frequency", &rate)) {
			switch (rate) {
			case 38400000:
			case 26000000:
			case 19200000:
			case 12000000:
				hub->secondary_ref_clk = 0;
				break;
			case 24000000:
			case 27000000:
			case 25000000:
			case 50000000:
				hub->secondary_ref_clk = 1;
				break;
			default:
				dev_err(dev,
					"unsupported reference clock rate (%d)\n",
					(int) rate);
				return -EINVAL;
			}
		}

		clk = devm_clk_get(dev, "refclk");
		if (IS_ERR(clk) && PTR_ERR(clk) != -ENOENT) {
			dev_err(dev, "unable to request refclk (%ld)\n",
					PTR_ERR(clk));
			return PTR_ERR(clk);
		}

		if (!IS_ERR(clk)) {
			hub->clk = clk;

			if (rate != 0) {
				err = clk_set_rate(hub->clk, rate);
				if (err) {
					dev_err(dev,
						"unable to set reference clock rate to %d\n",
						(int) rate);
					return err;
				}
			}

			err = clk_prepare_enable(hub->clk);
			if (err) {
				dev_err(dev,
					"unable to enable reference clock\n");
				return err;
			}
		}

		property = of_get_property(np, "disabled-ports", &len);
		if (property && (len / sizeof(u32)) > 0) {
			int i;
			for (i = 0; i < len / sizeof(u32); i++) {
				u32 port = be32_to_cpu(property[i]);
				if ((1 <= port) && (port <= 3))
					hub->port_off_mask |= (1 << port);
			}
		}

		hub->gpio_intn	= of_get_named_gpio(np, "intn-gpios", 0);
		if (hub->gpio_intn == -EPROBE_DEFER)
			return -EPROBE_DEFER;
		hub->gpio_connect = of_get_named_gpio(np, "connect-gpios", 0);
		if (hub->gpio_connect == -EPROBE_DEFER)
			return -EPROBE_DEFER;
		hub->gpio_reset = of_get_named_gpio(np, "reset-gpios", 0);
		if (hub->gpio_reset == -EPROBE_DEFER)
			return -EPROBE_DEFER;
		of_property_read_u32(np, "initial-mode", &mode);
		hub->mode = mode;
	}

	if (hub->port_off_mask && !hub->regmap)
		dev_err(dev, "Ports disabled with no control interface\n");

	if (gpio_is_valid(hub->gpio_intn)) {
		int val = hub->secondary_ref_clk ? GPIOF_OUT_INIT_LOW :
						   GPIOF_OUT_INIT_HIGH;
		err = devm_gpio_request_one(dev, hub->gpio_intn, val,
					    "usb4604 intn");
		if (err) {
			dev_err(dev,
				"unable to request GPIO %d as interrupt pin (%d)\n",
				hub->gpio_intn, err);
			return err;
		}
	}

	if (gpio_is_valid(hub->gpio_connect)) {
		err = devm_gpio_request_one(dev, hub->gpio_connect,
				GPIOF_OUT_INIT_LOW, "usb4604 connect");
		if (err) {
			dev_err(dev,
				"unable to request GPIO %d as connect pin (%d)\n",
				hub->gpio_connect, err);
			return err;
		}
	}

	if (gpio_is_valid(hub->gpio_reset)) {
		err = devm_gpio_request_one(dev, hub->gpio_reset,
				GPIOF_OUT_INIT_LOW, "usb4604 reset");
		/* Datasheet defines a hardware reset to be at least 100us */
		usleep_range(100, 10000);
		if (err) {
			dev_err(dev,
				"unable to request GPIO %d as reset pin (%d)\n",
				hub->gpio_reset, err);
			return err;
		}
	}

	usb4604_switch_mode(hub, hub->mode);

	dev_info(dev, "%s: probed in %s mode\n", __func__,
			(hub->mode == USB4604_MODE_HUB) ? "hub" : "standby");

	return 0;
}

static int usb4604_i2c_probe(struct i2c_client *i2c,
			     const struct i2c_device_id *id)
{
	struct usb4604 *hub;
	int err;

	hub = devm_kzalloc(&i2c->dev, sizeof(struct usb4604), GFP_KERNEL);
	if (!hub)
		return -ENOMEM;

	i2c_set_clientdata(i2c, hub);
	hub->regmap = devm_regmap_init_i2c(i2c, &usb4604_regmap_config);
	if (IS_ERR(hub->regmap)) {
		err = PTR_ERR(hub->regmap);
		dev_err(&i2c->dev, "Failed to initialise regmap: %d\n", err);
		return err;
	}
	hub->dev = &i2c->dev;

	return usb4604_probe(hub);
}

static int usb4604_i2c_remove(struct i2c_client *i2c)
{
	struct usb4604 *hub;

	hub = i2c_get_clientdata(i2c);
	if (hub->clk)
		clk_disable_unprepare(hub->clk);

	return 0;
}

static int usb4604_platform_probe(struct platform_device *pdev)
{
	struct usb4604 *hub;

	hub = devm_kzalloc(&pdev->dev, sizeof(struct usb4604), GFP_KERNEL);
	if (!hub)
		return -ENOMEM;
	hub->dev = &pdev->dev;
	platform_set_drvdata(pdev, hub);

	return usb4604_probe(hub);
}

static int usb4604_platform_remove(struct platform_device *pdev)
{
	struct usb4604 *hub;

	hub = platform_get_drvdata(pdev);
	if (hub->clk)
		clk_disable_unprepare(hub->clk);

	return 0;
}

#ifdef CONFIG_PM_SLEEP
static int usb4604_i2c_suspend(struct device *dev)
{
	struct i2c_client *client = to_i2c_client(dev);
	struct usb4604 *hub = i2c_get_clientdata(client);

	usb4604_switch_mode(hub, USB4604_MODE_STANDBY);

	if (hub->clk)
		clk_disable_unprepare(hub->clk);

	return 0;
}

static int usb4604_i2c_resume(struct device *dev)
{
	struct i2c_client *client = to_i2c_client(dev);
	struct usb4604 *hub = i2c_get_clientdata(client);

	if (hub->clk)
		clk_prepare_enable(hub->clk);

	usb4604_switch_mode(hub, hub->mode);

	return 0;
}
#endif

static SIMPLE_DEV_PM_OPS(usb4604_i2c_pm_ops, usb4604_i2c_suspend,
		usb4604_i2c_resume);

static const struct i2c_device_id usb4604_id[] = {
	{ USB4604_I2C_NAME, 0 },
	{ }
};
MODULE_DEVICE_TABLE(i2c, usb4604_id);

#ifdef CONFIG_OF
static const struct of_device_id usb4604_of_match[] = {
	{ .compatible = "smsc,usb4604", },
	{ .compatible = "smsc,usb4604a", },
	{},
};
MODULE_DEVICE_TABLE(of, usb4604_of_match);
#endif

static struct i2c_driver usb4604_i2c_driver = {
	.driver = {
		.name = USB4604_I2C_NAME,
		.pm = &usb4604_i2c_pm_ops,
		.of_match_table = of_match_ptr(usb4604_of_match),
	},
	.probe		= usb4604_i2c_probe,
	.remove		= usb4604_i2c_remove,
	.id_table	= usb4604_id,
};

static struct platform_driver usb4604_platform_driver = {
	.driver = {
		.name = USB4604_I2C_NAME,
		.of_match_table = of_match_ptr(usb4604_of_match),
	},
	.probe		= usb4604_platform_probe,
	.remove		= usb4604_platform_remove,
};

static int __init usb4604_init(void)
{
	int err;

	err = i2c_add_driver(&usb4604_i2c_driver);
	if (err != 0)
		pr_err("usb4604: Failed to register I2C driver: %d\n", err);

	err = platform_driver_register(&usb4604_platform_driver);
	if (err != 0)
		pr_err("usb4604: Failed to register platform driver: %d\n",
		       err);

	return 0;
}
module_init(usb4604_init);

static void __exit usb4604_exit(void)
{
	platform_driver_unregister(&usb4604_platform_driver);
	i2c_del_driver(&usb4604_i2c_driver);
}
module_exit(usb4604_exit);

MODULE_AUTHOR("Dongjin Kim ");
MODULE_DESCRIPTION("USB4604 USB HUB driver");
MODULE_LICENSE("GPL");

配置

make menuconfig

 

Device Drivers  --->
	[*] USB support  --->
		<*>   EHCI HCD (USB 2.0) support
			<*>     EHCI support for Samsung S5P/EXYNOS SoC Series
		<*>   USB Mass Storage support
		<*>   USB4604 HSIC to USB20 Driver

设备树

vim arch/arm/boot/dts/exynos4412-tiny4412.dts

    usb-hub {
                    compatible = "smsc,usb4604";
                    reset-gpios = <&gpm2 4 GPIO_ACTIVE_LOW>;
                    initial-mode = <1>;
                    status = "okay";
            };
        
&exynos_usbphy {
        status = "okay";
};

&ehci {
    status = "okay";
    port@0 {
      status = "okay";
    };
    port@1 {
      status = "okay";
    };
    port@2 {
      status = "okay";
    };
};

启动

[    3.066663] dm9601 1-2.4:1.0 eth0: register 'dm9601' at usb-12580000.ehci-2.4, Davicom DM96xx USB 10/100 Ethernet, 00:00:ff:ff:00:00
[    3.173493] usb 1-2.5: new high-speed USB device number 4 using exynos-ehci
[    3.324602] usb 1-2.5: New USB device found, idVendor=0424, idProduct=2530, bcdDevice= 1.16
[    3.324696] usb 1-2.5: New USB device strings: Mfr=0, Product=2, SerialNumber=0
[    3.324774] usb 1-2.5: Product: Bridge device

// insert U disk
[root@tiny4412 ]# [   20.623748] usb 1-2.2: new high-speed USB device number 5 using exynos-ehci
[   24.789022] usb 1-2.2: New USB device found, idVendor=0930, idProduct=6545, bcdDevice= 1.10
[   24.789244] usb 1-2.2: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[   24.789431] usb 1-2.2: Product: USB FLASH DRIVE
[   24.789576] usb 1-2.2: Manufacturer: TOSHIBA
[   24.791209] usb 1-2.2: SerialNumber: C03FD55EA867E161E00043A9
[   24.804595] usb-storage 1-2.2:1.0: USB Mass Storage device detected
[   24.817381] scsi host0: usb-storage 1-2.2:1.0
[   25.857001] scsi 0:0:0:0: Direct-Access     TOSHIBA  USB FLASH DRIVE  PMAP PQ: 0 ANSI: 6
[   25.873663] sd 0:0:0:0: [sda] 60475392 512-byte logical blocks: (31.0 GB/28.8 GiB)
[   25.874706] sd 0:0:0:0: [sda] Write Protect is off
[   25.875015] sd 0:0:0:0: Attached scsi generic sg0 type 0
[   25.875847] random: fast init done
[   25.876123] sd 0:0:0:0: [sda] Write cache: disabled, read cache: enabled, doesn't support DPO or FUA
[   27.953454]  sda: sda4
[   27.977744] sd 0:0:0:0: [sda] Attached SCSI removable disk

分析

在drivers/usb/misc/usb4604.c里面

#ifdef CONFIG_OF
static const struct of_device_id usb4604_of_match[] = {
        { .compatible = "smsc,usb4604", },
        { .compatible = "smsc,usb4604a", },
        {},
};
MODULE_DEVICE_TABLE(of, usb4604_of_match);
#endif

所以设备树里面hub相关,compatible要匹配

usb-hub {
                compatible = "smsc,usb4604";   # 
                reset-gpios = <&gpm2 4 GPIO_ACTIVE_LOW>;
                initial-mode = <1>;
                status = "okay";
        };

initial-mode = <1>;在代码里面有

enum usb4604_mode {
        USB4604_MODE_UNKNOWN,
        USB4604_MODE_HUB,          // 可知是HUB
        USB4604_MODE_STANDBY,
};

NFS启动

make menuconfig

File systems  ---> 
    [*] Network File Systems  --->
        <*>   NFS client support

配置nfs目录

sudo vim /etc/exports

/home/flinn/tiny4412-SDK/tiny4412/fs/rootfs *(rw,sync,no_root_squash)

/etc/init.d/nfs-kernel-server restart

设置启动参数

setenv ipaddr 192.168.1.123
setenv serverip 192.168.1.101

setenv bootargs noinitrd root=/dev/nfs rw nfsroot=192.168.1.101:/home/flinn/tiny4412-SDK/tiny4412/fs/rootfs ethmac=1C:6F:65:34:51:7E ip=192.168.1.123:192.168.1.101:192.168.1.1:255.255.255.0:TINY4412:eth0:off console=ttySAC0,115200 init=/linuxrc

usb start;tftp 0x40080000 uImage;tftp 0x42000000 exynos4412-tiny4412.dtb;bootm 0x40080000 - 0x42000000

以上驱动有bug !!!

tiny4412 驱动 (3)网卡驱动移植_第1张图片

以上原理图里面没有关于i2c的接口,而驱动usb3503里面有。

会出现什么问题呢?

 

[   14.273539] Waiting up to 110 more seconds for network.
[   24.293529] Waiting up to 100 more seconds for network.

...

经常出现等2分钟还没有启动。一直没有找到原因;后面仔细分析原理图,以及代码,发现设备树也没有给定i2c的地址,那么会不会在扫描到后才能执行后面的usb4604_probe,这样的话可以解释得通;

后面试了一下,直接去掉i2c相关,改成platform_driver,完美解决问题

/*
 * Driver for SMSC USB4604 USB 2.0 hub controller driver
 *
 * Copyright (c) 2012-2013 Dongjin Kim ([email protected])
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */
#include 
#include 
#include 
#include 
#include 
#include 


#define USB4604_NAME	"usb4604"


enum usb4604_mode {
	USB4604_MODE_UNKNOWN,
	USB4604_MODE_HUB,
	USB4604_MODE_STANDBY,
};

struct usb4604_platform_data {
	enum usb4604_mode	initial_mode;
	int	gpio_reset;
};


struct usb4604 {
	enum usb4604_mode	mode;
	struct device		*dev;
	int gpio_reset;
};

static int usb4604_reset(struct usb4604 *hub, int state)
{

	if (gpio_is_valid(hub->gpio_reset))
		gpio_set_value_cansleep(hub->gpio_reset, state);
	dev_info(hub->dev, "%s\n", __func__);
	/* Wait T_HUBINIT == 1ms for hub logic to stabilize */
	usleep_range(1000, 4000);

	return 0;
}

static int usb4604_connect(struct usb4604 *hub)
{
	struct device *dev = hub->dev;
	int err;
	dev_info(hub->dev, "%s\n", __func__);
	usb4604_reset(hub, 1);
	hub->mode = USB4604_MODE_HUB;
	dev_info(dev, "switched to HUB mode\n");

	return 0;
}

static int usb4604_switch_mode(struct usb4604 *hub, enum usb4604_mode mode)
{
	struct device *dev = hub->dev;
	int err = 0;
	dev_info(hub->dev, "%s: mode:%d\n", __func__,mode);

	switch (mode) {
	case USB4604_MODE_HUB:
		/*
		 * 1. reset usb4604 first
		 * 2. switch to HUB mode
		 */
		usb4604_reset(hub, 0);
		err = usb4604_connect(hub);
		break;

	case USB4604_MODE_STANDBY:
		usb4604_reset(hub, 0);
		dev_info(dev, "switched to STANDBY mode\n");
		break;

	default:
		dev_err(dev, "unknown mode is requested\n");
		err = -EINVAL;
		break;
	}

	return err;
}

static int usb4604_probe(struct usb4604 *hub)
{
	struct device *dev = hub->dev;
	struct usb4604_platform_data *pdata = dev_get_platdata(dev);
	struct device_node *np = dev->of_node;
	int err;
	u32 mode = USB4604_MODE_HUB;

	if (pdata) {
		hub->gpio_reset	= pdata->gpio_reset;
		hub->mode = pdata->initial_mode;
	} else if (np) {
		hub->gpio_reset = of_get_named_gpio(np, "reset-gpios", 0);
		if(-EPROBE_DEFER == hub->gpio_reset)
			return -EPROBE_DEFER;
		of_property_read_u32(np, "initial-mode", &mode);
		hub->mode = mode;
	}
	
	if (gpio_is_valid(hub->gpio_reset)) {
		err = devm_gpio_request_one(dev, hub->gpio_reset,
				GPIOF_OUT_INIT_LOW, "usb4604 reset");
		if (err) {
			dev_err(dev,
				"unable to request GPIO %d as reset pin (%d)\n",
				hub->gpio_reset, err);
			return err;
		}
	}

	usb4604_switch_mode(hub, hub->mode);

	dev_info(dev, "%s: probed in %s mode\n", __func__,
			(hub->mode == USB4604_MODE_HUB) ? "hub" : "standby");

	return 0;
}

static int usb4604_platform_probe(struct platform_device *pdev)
{
	struct usb4604 *hub;

	hub = devm_kzalloc(&pdev->dev, sizeof(struct usb4604), GFP_KERNEL);
	if (!hub)
		return -ENOMEM;
	hub->dev = &pdev->dev;

	return usb4604_probe(hub);
}


#ifdef CONFIG_OF
static const struct of_device_id usb4604_of_match[] = {
	{ .compatible = "smsc,usb4604", },
	{},
};
MODULE_DEVICE_TABLE(of, usb4604_of_match);
#endif


static struct platform_driver usb4604_platform_driver = {
	.driver = {
		.name = USB4604_NAME,
		.of_match_table = of_match_ptr(usb4604_of_match),
	},
	.probe		= usb4604_platform_probe,
};

static int __init usb4604_init(void)
{
	int err;


	err = platform_driver_register(&usb4604_platform_driver);
	if (err != 0)
		pr_err("usb4604: Failed to register platform driver: %d\n",
		       err);

	return 0;
}
module_init(usb4604_init);

static void __exit usb4604_exit(void)
{
	platform_driver_unregister(&usb4604_platform_driver);

}
module_exit(usb4604_exit);

MODULE_DESCRIPTION("USB4604 USB HUB driver");
MODULE_LICENSE("GPL");

 

你可能感兴趣的:(tiny4412,tiny4412)