diff options
author | Mark Brown <broonie@linaro.org> | 2013-08-09 11:41:53 +0100 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2013-08-12 12:20:26 -0700 |
commit | 2487e3ee33dd6c4fa3dabbe11bc988883be81f1e (patch) | |
tree | a051a4555160990f81bb6f184853d62d01f69492 /drivers/usb/misc/usb3503.c | |
parent | 68b14134be55eca7340b9a8b3ec4cb8f79622a3c (diff) | |
download | op-kernel-dev-2487e3ee33dd6c4fa3dabbe11bc988883be81f1e.zip op-kernel-dev-2487e3ee33dd6c4fa3dabbe11bc988883be81f1e.tar.gz |
usb: misc: usb3503: Factor out I2C probe
In preparation for supporting operation without an I2C control interface
factor out the I2C-specific parts of the probe routine from those that
don't do any register I/O.
Signed-off-by: Mark Brown <broonie@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/usb/misc/usb3503.c')
-rw-r--r-- | drivers/usb/misc/usb3503.c | 77 |
1 files changed, 43 insertions, 34 deletions
diff --git a/drivers/usb/misc/usb3503.c b/drivers/usb/misc/usb3503.c index f2c0356..ca0f789 100644 --- a/drivers/usb/misc/usb3503.c +++ b/drivers/usb/misc/usb3503.c @@ -156,31 +156,16 @@ static const struct regmap_config usb3503_regmap_config = { .max_register = USB3503_RESET, }; -static int usb3503_probe(struct i2c_client *i2c, const struct i2c_device_id *id) +static int usb3503_probe(struct usb3503 *hub) { - struct usb3503_platform_data *pdata = dev_get_platdata(&i2c->dev); - struct device_node *np = i2c->dev.of_node; - struct usb3503 *hub; - int err = -ENOMEM; + struct device *dev = hub->dev; + struct usb3503_platform_data *pdata = dev_get_platdata(dev); + struct device_node *np = dev->of_node; + int err; u32 mode = USB3503_MODE_UNKNOWN; const u32 *property; int len; - hub = devm_kzalloc(&i2c->dev, sizeof(struct usb3503), GFP_KERNEL); - if (!hub) { - dev_err(&i2c->dev, "private data alloc fail\n"); - return err; - } - - i2c_set_clientdata(i2c, hub); - hub->regmap = devm_regmap_init_i2c(i2c, &usb3503_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; - if (pdata) { hub->port_off_mask = pdata->port_off_mask; hub->gpio_intn = pdata->gpio_intn; @@ -214,46 +199,70 @@ static int usb3503_probe(struct i2c_client *i2c, const struct i2c_device_id *id) } if (gpio_is_valid(hub->gpio_intn)) { - err = devm_gpio_request_one(&i2c->dev, hub->gpio_intn, + err = devm_gpio_request_one(dev, hub->gpio_intn, GPIOF_OUT_INIT_HIGH, "usb3503 intn"); if (err) { - dev_err(&i2c->dev, - "unable to request GPIO %d as connect pin (%d)\n", - hub->gpio_intn, err); + dev_err(dev, + "unable to request GPIO %d as connect pin (%d)\n", + hub->gpio_intn, err); return err; } } if (gpio_is_valid(hub->gpio_connect)) { - err = devm_gpio_request_one(&i2c->dev, hub->gpio_connect, + err = devm_gpio_request_one(dev, hub->gpio_connect, GPIOF_OUT_INIT_LOW, "usb3503 connect"); if (err) { - dev_err(&i2c->dev, - "unable to request GPIO %d as connect pin (%d)\n", - hub->gpio_connect, 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(&i2c->dev, hub->gpio_reset, + err = devm_gpio_request_one(dev, hub->gpio_reset, GPIOF_OUT_INIT_LOW, "usb3503 reset"); if (err) { - dev_err(&i2c->dev, - "unable to request GPIO %d as reset pin (%d)\n", - hub->gpio_reset, err); + dev_err(dev, + "unable to request GPIO %d as reset pin (%d)\n", + hub->gpio_reset, err); return err; } } usb3503_switch_mode(hub, hub->mode); - dev_info(&i2c->dev, "%s: probed on %s mode\n", __func__, + dev_info(dev, "%s: probed on %s mode\n", __func__, (hub->mode == USB3503_MODE_HUB) ? "hub" : "standby"); return 0; } +static int usb3503_i2c_probe(struct i2c_client *i2c, + const struct i2c_device_id *id) +{ + struct usb3503 *hub; + int err; + + hub = devm_kzalloc(&i2c->dev, sizeof(struct usb3503), GFP_KERNEL); + if (!hub) { + dev_err(&i2c->dev, "private data alloc fail\n"); + return -ENOMEM; + } + + i2c_set_clientdata(i2c, hub); + hub->regmap = devm_regmap_init_i2c(i2c, &usb3503_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 usb3503_probe(hub); +} + static const struct i2c_device_id usb3503_id[] = { { USB3503_I2C_NAME, 0 }, { } @@ -273,7 +282,7 @@ static struct i2c_driver usb3503_driver = { .name = USB3503_I2C_NAME, .of_match_table = of_match_ptr(usb3503_of_match), }, - .probe = usb3503_probe, + .probe = usb3503_i2c_probe, .id_table = usb3503_id, }; |