diff options
Diffstat (limited to 'drivers/pinctrl/pinmux.c')
-rw-r--r-- | drivers/pinctrl/pinmux.c | 67 |
1 files changed, 22 insertions, 45 deletions
diff --git a/drivers/pinctrl/pinmux.c b/drivers/pinctrl/pinmux.c index 9301a7a95eff..0ef01ee2835f 100644 --- a/drivers/pinctrl/pinmux.c +++ b/drivers/pinctrl/pinmux.c | |||
@@ -314,14 +314,11 @@ int pinmux_map_to_setting(struct pinctrl_map const *map, | |||
314 | { | 314 | { |
315 | struct pinctrl_dev *pctldev = setting->pctldev; | 315 | struct pinctrl_dev *pctldev = setting->pctldev; |
316 | const struct pinmux_ops *pmxops = pctldev->desc->pmxops; | 316 | const struct pinmux_ops *pmxops = pctldev->desc->pmxops; |
317 | const struct pinctrl_ops *pctlops = pctldev->desc->pctlops; | ||
318 | char const * const *groups; | 317 | char const * const *groups; |
319 | unsigned num_groups; | 318 | unsigned num_groups; |
320 | int ret; | 319 | int ret; |
321 | const char *group; | 320 | const char *group; |
322 | int i; | 321 | int i; |
323 | const unsigned *pins; | ||
324 | unsigned num_pins; | ||
325 | 322 | ||
326 | if (!pmxops) { | 323 | if (!pmxops) { |
327 | dev_err(pctldev->dev, "does not support mux function\n"); | 324 | dev_err(pctldev->dev, "does not support mux function\n"); |
@@ -376,53 +373,12 @@ int pinmux_map_to_setting(struct pinctrl_map const *map, | |||
376 | } | 373 | } |
377 | setting->data.mux.group = ret; | 374 | setting->data.mux.group = ret; |
378 | 375 | ||
379 | ret = pctlops->get_group_pins(pctldev, setting->data.mux.group, &pins, | ||
380 | &num_pins); | ||
381 | if (ret) { | ||
382 | dev_err(pctldev->dev, | ||
383 | "could not get pins for device %s group selector %d\n", | ||
384 | pinctrl_dev_get_name(pctldev), setting->data.mux.group); | ||
385 | return -ENODEV; | ||
386 | } | ||
387 | |||
388 | /* Try to allocate all pins in this group, one by one */ | ||
389 | for (i = 0; i < num_pins; i++) { | ||
390 | ret = pin_request(pctldev, pins[i], map->dev_name, NULL); | ||
391 | if (ret) { | ||
392 | dev_err(pctldev->dev, | ||
393 | "could not request pin %d on device %s\n", | ||
394 | pins[i], pinctrl_dev_get_name(pctldev)); | ||
395 | /* On error release all taken pins */ | ||
396 | i--; /* this pin just failed */ | ||
397 | for (; i >= 0; i--) | ||
398 | pin_free(pctldev, pins[i], NULL); | ||
399 | return -ENODEV; | ||
400 | } | ||
401 | } | ||
402 | |||
403 | return 0; | 376 | return 0; |
404 | } | 377 | } |
405 | 378 | ||
406 | void pinmux_free_setting(struct pinctrl_setting const *setting) | 379 | void pinmux_free_setting(struct pinctrl_setting const *setting) |
407 | { | 380 | { |
408 | struct pinctrl_dev *pctldev = setting->pctldev; | 381 | /* This function is currently unused */ |
409 | const struct pinctrl_ops *pctlops = pctldev->desc->pctlops; | ||
410 | const unsigned *pins; | ||
411 | unsigned num_pins; | ||
412 | int ret; | ||
413 | int i; | ||
414 | |||
415 | ret = pctlops->get_group_pins(pctldev, setting->data.mux.group, | ||
416 | &pins, &num_pins); | ||
417 | if (ret) { | ||
418 | dev_err(pctldev->dev, | ||
419 | "could not get pins for device %s group selector %d\n", | ||
420 | pinctrl_dev_get_name(pctldev), setting->data.mux.group); | ||
421 | return; | ||
422 | } | ||
423 | |||
424 | for (i = 0; i < num_pins; i++) | ||
425 | pin_free(pctldev, pins[i], NULL); | ||
426 | } | 382 | } |
427 | 383 | ||
428 | int pinmux_enable_setting(struct pinctrl_setting const *setting) | 384 | int pinmux_enable_setting(struct pinctrl_setting const *setting) |
@@ -446,6 +402,22 @@ int pinmux_enable_setting(struct pinctrl_setting const *setting) | |||
446 | num_pins = 0; | 402 | num_pins = 0; |
447 | } | 403 | } |
448 | 404 | ||
405 | /* Try to allocate all pins in this group, one by one */ | ||
406 | for (i = 0; i < num_pins; i++) { | ||
407 | ret = pin_request(pctldev, pins[i], setting->dev_name, NULL); | ||
408 | if (ret) { | ||
409 | dev_err(pctldev->dev, | ||
410 | "could not request pin %d on device %s\n", | ||
411 | pins[i], pinctrl_dev_get_name(pctldev)); | ||
412 | /* On error release all taken pins */ | ||
413 | i--; /* this pin just failed */ | ||
414 | for (; i >= 0; i--) | ||
415 | pin_free(pctldev, pins[i], NULL); | ||
416 | return -ENODEV; | ||
417 | } | ||
418 | } | ||
419 | |||
420 | /* Now that we have acquired the pins, encode the mux setting */ | ||
449 | for (i = 0; i < num_pins; i++) { | 421 | for (i = 0; i < num_pins; i++) { |
450 | desc = pin_desc_get(pctldev, pins[i]); | 422 | desc = pin_desc_get(pctldev, pins[i]); |
451 | if (desc == NULL) { | 423 | if (desc == NULL) { |
@@ -482,6 +454,7 @@ void pinmux_disable_setting(struct pinctrl_setting const *setting) | |||
482 | num_pins = 0; | 454 | num_pins = 0; |
483 | } | 455 | } |
484 | 456 | ||
457 | /* Flag the descs that no setting is active */ | ||
485 | for (i = 0; i < num_pins; i++) { | 458 | for (i = 0; i < num_pins; i++) { |
486 | desc = pin_desc_get(pctldev, pins[i]); | 459 | desc = pin_desc_get(pctldev, pins[i]); |
487 | if (desc == NULL) { | 460 | if (desc == NULL) { |
@@ -493,6 +466,10 @@ void pinmux_disable_setting(struct pinctrl_setting const *setting) | |||
493 | desc->mux_setting = NULL; | 466 | desc->mux_setting = NULL; |
494 | } | 467 | } |
495 | 468 | ||
469 | /* And release the pins */ | ||
470 | for (i = 0; i < num_pins; i++) | ||
471 | pin_free(pctldev, pins[i], NULL); | ||
472 | |||
496 | if (ops->disable) | 473 | if (ops->disable) |
497 | ops->disable(pctldev, setting->data.mux.func, setting->data.mux.group); | 474 | ops->disable(pctldev, setting->data.mux.func, setting->data.mux.group); |
498 | } | 475 | } |