diff options
| author | Mark Brown <broonie@linaro.org> | 2013-08-09 06:41:53 -0400 |
|---|---|---|
| committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2013-08-12 15:20:26 -0400 |
| commit | 2487e3ee33dd6c4fa3dabbe11bc988883be81f1e (patch) | |
| tree | a051a4555160990f81bb6f184853d62d01f69492 /drivers/usb/misc | |
| parent | 68b14134be55eca7340b9a8b3ec4cb8f79622a3c (diff) | |
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')
| -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 f2c0356b7148..ca0f789d78a3 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 = { | |||
| 156 | .max_register = USB3503_RESET, | 156 | .max_register = USB3503_RESET, |
| 157 | }; | 157 | }; |
| 158 | 158 | ||
| 159 | static int usb3503_probe(struct i2c_client *i2c, const struct i2c_device_id *id) | 159 | static int usb3503_probe(struct usb3503 *hub) |
| 160 | { | 160 | { |
| 161 | struct usb3503_platform_data *pdata = dev_get_platdata(&i2c->dev); | 161 | struct device *dev = hub->dev; |
| 162 | struct device_node *np = i2c->dev.of_node; | 162 | struct usb3503_platform_data *pdata = dev_get_platdata(dev); |
| 163 | struct usb3503 *hub; | 163 | struct device_node *np = dev->of_node; |
| 164 | int err = -ENOMEM; | 164 | int err; |
| 165 | u32 mode = USB3503_MODE_UNKNOWN; | 165 | u32 mode = USB3503_MODE_UNKNOWN; |
| 166 | const u32 *property; | 166 | const u32 *property; |
| 167 | int len; | 167 | int len; |
| 168 | 168 | ||
| 169 | hub = devm_kzalloc(&i2c->dev, sizeof(struct usb3503), GFP_KERNEL); | ||
| 170 | if (!hub) { | ||
| 171 | dev_err(&i2c->dev, "private data alloc fail\n"); | ||
| 172 | return err; | ||
| 173 | } | ||
| 174 | |||
| 175 | i2c_set_clientdata(i2c, hub); | ||
| 176 | hub->regmap = devm_regmap_init_i2c(i2c, &usb3503_regmap_config); | ||
| 177 | if (IS_ERR(hub->regmap)) { | ||
| 178 | err = PTR_ERR(hub->regmap); | ||
| 179 | dev_err(&i2c->dev, "Failed to initialise regmap: %d\n", err); | ||
| 180 | return err; | ||
| 181 | } | ||
| 182 | hub->dev = &i2c->dev; | ||
| 183 | |||
| 184 | if (pdata) { | 169 | if (pdata) { |
| 185 | hub->port_off_mask = pdata->port_off_mask; | 170 | hub->port_off_mask = pdata->port_off_mask; |
| 186 | hub->gpio_intn = pdata->gpio_intn; | 171 | hub->gpio_intn = pdata->gpio_intn; |
| @@ -214,46 +199,70 @@ static int usb3503_probe(struct i2c_client *i2c, const struct i2c_device_id *id) | |||
| 214 | } | 199 | } |
| 215 | 200 | ||
| 216 | if (gpio_is_valid(hub->gpio_intn)) { | 201 | if (gpio_is_valid(hub->gpio_intn)) { |
| 217 | err = devm_gpio_request_one(&i2c->dev, hub->gpio_intn, | 202 | err = devm_gpio_request_one(dev, hub->gpio_intn, |
| 218 | GPIOF_OUT_INIT_HIGH, "usb3503 intn"); | 203 | GPIOF_OUT_INIT_HIGH, "usb3503 intn"); |
| 219 | if (err) { | 204 | if (err) { |
| 220 | dev_err(&i2c->dev, | 205 | dev_err(dev, |
| 221 | "unable to request GPIO %d as connect pin (%d)\n", | 206 | "unable to request GPIO %d as connect pin (%d)\n", |
| 222 | hub->gpio_intn, err); | 207 | hub->gpio_intn, err); |
| 223 | return err; | 208 | return err; |
| 224 | } | 209 | } |
| 225 | } | 210 | } |
| 226 | 211 | ||
| 227 | if (gpio_is_valid(hub->gpio_connect)) { | 212 | if (gpio_is_valid(hub->gpio_connect)) { |
| 228 | err = devm_gpio_request_one(&i2c->dev, hub->gpio_connect, | 213 | err = devm_gpio_request_one(dev, hub->gpio_connect, |
| 229 | GPIOF_OUT_INIT_LOW, "usb3503 connect"); | 214 | GPIOF_OUT_INIT_LOW, "usb3503 connect"); |
| 230 | if (err) { | 215 | if (err) { |
| 231 | dev_err(&i2c->dev, | 216 | dev_err(dev, |
| 232 | "unable to request GPIO %d as connect pin (%d)\n", | 217 | "unable to request GPIO %d as connect pin (%d)\n", |
| 233 | hub->gpio_connect, err); | 218 | hub->gpio_connect, err); |
| 234 | return err; | 219 | return err; |
| 235 | } | 220 | } |
| 236 | } | 221 | } |
| 237 | 222 | ||
| 238 | if (gpio_is_valid(hub->gpio_reset)) { | 223 | if (gpio_is_valid(hub->gpio_reset)) { |
| 239 | err = devm_gpio_request_one(&i2c->dev, hub->gpio_reset, | 224 | err = devm_gpio_request_one(dev, hub->gpio_reset, |
| 240 | GPIOF_OUT_INIT_LOW, "usb3503 reset"); | 225 | GPIOF_OUT_INIT_LOW, "usb3503 reset"); |
| 241 | if (err) { | 226 | if (err) { |
| 242 | dev_err(&i2c->dev, | 227 | dev_err(dev, |
| 243 | "unable to request GPIO %d as reset pin (%d)\n", | 228 | "unable to request GPIO %d as reset pin (%d)\n", |
| 244 | hub->gpio_reset, err); | 229 | hub->gpio_reset, err); |
| 245 | return err; | 230 | return err; |
| 246 | } | 231 | } |
| 247 | } | 232 | } |
| 248 | 233 | ||
| 249 | usb3503_switch_mode(hub, hub->mode); | 234 | usb3503_switch_mode(hub, hub->mode); |
| 250 | 235 | ||
| 251 | dev_info(&i2c->dev, "%s: probed on %s mode\n", __func__, | 236 | dev_info(dev, "%s: probed on %s mode\n", __func__, |
| 252 | (hub->mode == USB3503_MODE_HUB) ? "hub" : "standby"); | 237 | (hub->mode == USB3503_MODE_HUB) ? "hub" : "standby"); |
| 253 | 238 | ||
| 254 | return 0; | 239 | return 0; |
| 255 | } | 240 | } |
| 256 | 241 | ||
| 242 | static int usb3503_i2c_probe(struct i2c_client *i2c, | ||
| 243 | const struct i2c_device_id *id) | ||
| 244 | { | ||
| 245 | struct usb3503 *hub; | ||
| 246 | int err; | ||
| 247 | |||
| 248 | hub = devm_kzalloc(&i2c->dev, sizeof(struct usb3503), GFP_KERNEL); | ||
| 249 | if (!hub) { | ||
| 250 | dev_err(&i2c->dev, "private data alloc fail\n"); | ||
| 251 | return -ENOMEM; | ||
| 252 | } | ||
| 253 | |||
| 254 | i2c_set_clientdata(i2c, hub); | ||
| 255 | hub->regmap = devm_regmap_init_i2c(i2c, &usb3503_regmap_config); | ||
| 256 | if (IS_ERR(hub->regmap)) { | ||
| 257 | err = PTR_ERR(hub->regmap); | ||
| 258 | dev_err(&i2c->dev, "Failed to initialise regmap: %d\n", err); | ||
| 259 | return err; | ||
| 260 | } | ||
| 261 | hub->dev = &i2c->dev; | ||
| 262 | |||
| 263 | return usb3503_probe(hub); | ||
| 264 | } | ||
| 265 | |||
| 257 | static const struct i2c_device_id usb3503_id[] = { | 266 | static const struct i2c_device_id usb3503_id[] = { |
| 258 | { USB3503_I2C_NAME, 0 }, | 267 | { USB3503_I2C_NAME, 0 }, |
| 259 | { } | 268 | { } |
| @@ -273,7 +282,7 @@ static struct i2c_driver usb3503_driver = { | |||
| 273 | .name = USB3503_I2C_NAME, | 282 | .name = USB3503_I2C_NAME, |
| 274 | .of_match_table = of_match_ptr(usb3503_of_match), | 283 | .of_match_table = of_match_ptr(usb3503_of_match), |
| 275 | }, | 284 | }, |
| 276 | .probe = usb3503_probe, | 285 | .probe = usb3503_i2c_probe, |
| 277 | .id_table = usb3503_id, | 286 | .id_table = usb3503_id, |
| 278 | }; | 287 | }; |
| 279 | 288 | ||
