aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--drivers/pinctrl/core.c598
-rw-r--r--drivers/pinctrl/core.h30
-rw-r--r--drivers/pinctrl/pinmux.c711
-rw-r--r--drivers/pinctrl/pinmux.h67
-rw-r--r--include/linux/pinctrl/consumer.h8
5 files changed, 779 insertions, 635 deletions
diff --git a/drivers/pinctrl/core.c b/drivers/pinctrl/core.c
index 75c6a6bb6c0a..ec32c545f07f 100644
--- a/drivers/pinctrl/core.c
+++ b/drivers/pinctrl/core.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * Core driver for the pin control subsystem 2 * Core driver for the pin control subsystem
3 * 3 *
4 * Copyright (C) 2011 ST-Ericsson SA 4 * Copyright (C) 2011-2012 ST-Ericsson SA
5 * Written on behalf of Linaro for ST-Ericsson 5 * Written on behalf of Linaro for ST-Ericsson
6 * Based on bits of regulator core, gpio core and clk core 6 * Based on bits of regulator core, gpio core and clk core
7 * 7 *
@@ -30,10 +30,30 @@
30#include "pinmux.h" 30#include "pinmux.h"
31#include "pinconf.h" 31#include "pinconf.h"
32 32
33/**
34 * struct pinctrl_hog - a list item to stash control hogs
35 * @node: pin control hog list node
36 * @map: map entry responsible for this hogging
37 * @pmx: the pin control hogged by this item
38 */
39struct pinctrl_hog {
40 struct list_head node;
41 struct pinctrl_map const *map;
42 struct pinctrl *p;
43};
44
33/* Global list of pin control devices */ 45/* Global list of pin control devices */
34static DEFINE_MUTEX(pinctrldev_list_mutex); 46static DEFINE_MUTEX(pinctrldev_list_mutex);
35static LIST_HEAD(pinctrldev_list); 47static LIST_HEAD(pinctrldev_list);
36 48
49/* List of pin controller handles */
50static DEFINE_MUTEX(pinctrl_list_mutex);
51static LIST_HEAD(pinctrl_list);
52
53/* Global pinctrl maps */
54static struct pinctrl_map *pinctrl_maps;
55static unsigned pinctrl_maps_num;
56
37const char *pinctrl_dev_get_name(struct pinctrl_dev *pctldev) 57const char *pinctrl_dev_get_name(struct pinctrl_dev *pctldev)
38{ 58{
39 /* We're not allowed to register devices without name */ 59 /* We're not allowed to register devices without name */
@@ -337,6 +357,476 @@ int pinctrl_get_group_selector(struct pinctrl_dev *pctldev,
337 return -EINVAL; 357 return -EINVAL;
338} 358}
339 359
360/**
361 * pinctrl_request_gpio() - request a single pin to be used in as GPIO
362 * @gpio: the GPIO pin number from the GPIO subsystem number space
363 *
364 * This function should *ONLY* be used from gpiolib-based GPIO drivers,
365 * as part of their gpio_request() semantics, platforms and individual drivers
366 * shall *NOT* request GPIO pins to be muxed in.
367 */
368int pinctrl_request_gpio(unsigned gpio)
369{
370 struct pinctrl_dev *pctldev;
371 struct pinctrl_gpio_range *range;
372 int ret;
373 int pin;
374
375 ret = pinctrl_get_device_gpio_range(gpio, &pctldev, &range);
376 if (ret)
377 return -EINVAL;
378
379 /* Convert to the pin controllers number space */
380 pin = gpio - range->base + range->pin_base;
381
382 return pinmux_request_gpio(pctldev, range, pin, gpio);
383}
384EXPORT_SYMBOL_GPL(pinctrl_request_gpio);
385
386/**
387 * pinctrl_free_gpio() - free control on a single pin, currently used as GPIO
388 * @gpio: the GPIO pin number from the GPIO subsystem number space
389 *
390 * This function should *ONLY* be used from gpiolib-based GPIO drivers,
391 * as part of their gpio_free() semantics, platforms and individual drivers
392 * shall *NOT* request GPIO pins to be muxed out.
393 */
394void pinctrl_free_gpio(unsigned gpio)
395{
396 struct pinctrl_dev *pctldev;
397 struct pinctrl_gpio_range *range;
398 int ret;
399 int pin;
400
401 ret = pinctrl_get_device_gpio_range(gpio, &pctldev, &range);
402 if (ret)
403 return;
404
405 /* Convert to the pin controllers number space */
406 pin = gpio - range->base + range->pin_base;
407
408 return pinmux_free_gpio(pctldev, pin, range);
409}
410EXPORT_SYMBOL_GPL(pinctrl_free_gpio);
411
412static int pinctrl_gpio_direction(unsigned gpio, bool input)
413{
414 struct pinctrl_dev *pctldev;
415 struct pinctrl_gpio_range *range;
416 int ret;
417 int pin;
418
419 ret = pinctrl_get_device_gpio_range(gpio, &pctldev, &range);
420 if (ret)
421 return ret;
422
423 /* Convert to the pin controllers number space */
424 pin = gpio - range->base + range->pin_base;
425
426 return pinmux_gpio_direction(pctldev, range, pin, input);
427}
428
429/**
430 * pinctrl_gpio_direction_input() - request a GPIO pin to go into input mode
431 * @gpio: the GPIO pin number from the GPIO subsystem number space
432 *
433 * This function should *ONLY* be used from gpiolib-based GPIO drivers,
434 * as part of their gpio_direction_input() semantics, platforms and individual
435 * drivers shall *NOT* touch pin control GPIO calls.
436 */
437int pinctrl_gpio_direction_input(unsigned gpio)
438{
439 return pinctrl_gpio_direction(gpio, true);
440}
441EXPORT_SYMBOL_GPL(pinctrl_gpio_direction_input);
442
443/**
444 * pinctrl_gpio_direction_output() - request a GPIO pin to go into output mode
445 * @gpio: the GPIO pin number from the GPIO subsystem number space
446 *
447 * This function should *ONLY* be used from gpiolib-based GPIO drivers,
448 * as part of their gpio_direction_output() semantics, platforms and individual
449 * drivers shall *NOT* touch pin control GPIO calls.
450 */
451int pinctrl_gpio_direction_output(unsigned gpio)
452{
453 return pinctrl_gpio_direction(gpio, false);
454}
455EXPORT_SYMBOL_GPL(pinctrl_gpio_direction_output);
456
457/**
458 * pinctrl_get() - retrieves the pin controller handle for a certain device
459 * @dev: the device to get the pin controller handle for
460 * @name: an optional specific control mapping name or NULL, the name is only
461 * needed if you want to have more than one mapping per device, or if you
462 * need an anonymous pin control (not tied to any specific device)
463 */
464struct pinctrl *pinctrl_get(struct device *dev, const char *name)
465{
466 struct pinctrl_map const *map = NULL;
467 struct pinctrl_dev *pctldev = NULL;
468 const char *devname = NULL;
469 struct pinctrl *p;
470 bool found_map;
471 unsigned num_maps = 0;
472 int ret = -ENODEV;
473 int i;
474
475 /* We must have dev or ID or both */
476 if (!dev && !name)
477 return ERR_PTR(-EINVAL);
478
479 if (dev)
480 devname = dev_name(dev);
481
482 pr_debug("get pin control handle %s for device %s\n", name,
483 devname ? devname : "(none)");
484
485 /*
486 * create the state cookie holder struct pinctrl for each
487 * mapping, this is what consumers will get when requesting
488 * a pin control handle with pinctrl_get()
489 */
490 p = kzalloc(sizeof(struct pinctrl), GFP_KERNEL);
491 if (p == NULL)
492 return ERR_PTR(-ENOMEM);
493 mutex_init(&p->mutex);
494 pinmux_init_pinctrl_handle(p);
495
496 /* Iterate over the pin control maps to locate the right ones */
497 for (i = 0; i < pinctrl_maps_num; i++) {
498 map = &pinctrl_maps[i];
499 found_map = false;
500
501 /*
502 * First, try to find the pctldev given in the map
503 */
504 pctldev = get_pinctrl_dev_from_devname(map->ctrl_dev_name);
505 if (!pctldev) {
506 pr_warning("could not find a pinctrl device for pinmux function %s, fishy, they shall all have one\n",
507 map->function);
508