Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 282145
b: refs/heads/master
c: ae6b4d8
h: refs/heads/master
i:
  282143: 55aa057
v: v3
  • Loading branch information
Linus Walleij committed Jan 3, 2012
1 parent f3b419f commit 8031e85
Show file tree
Hide file tree
Showing 10 changed files with 583 additions and 11 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: b4e3ac74d5cd4152f2ec6b3280b1ff3428952f7f
refs/heads/master: ae6b4d8588f4fc95520b0e62c4b1f474c82191a9
96 changes: 90 additions & 6 deletions trunk/Documentation/pinctrl.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,9 @@ This subsystem deals with:

- Multiplexing of pins, pads, fingers (etc) see below for details

The intention is to also deal with:

- Software-controlled biasing and driving mode specific pins, such as
pull-up/down, open drain etc, load capacitance configuration when controlled
by software, etc.

- Configuration of pins, pads, fingers (etc), such as software-controlled
biasing and driving mode specific pins, such as pull-up/down, open drain,
load capacitance etc.

Top-level interface
===================
Expand Down Expand Up @@ -88,6 +85,11 @@ int __init foo_probe(void)
pr_err("could not register foo pin driver\n");
}

To enable the pinctrl subsystem and the subgroups for PINMUX and PINCONF and
selected drivers, you need to select them from your machine's Kconfig entry,
since these are so tightly integrated with the machines they are used on.
See for example arch/arm/mach-u300/Kconfig for an example.

Pins usually have fancier names than this. You can find these in the dataheet
for your chip. Notice that the core pinctrl.h file provides a fancy macro
called PINCTRL_PIN() to create the struct entries. As you can see I enumerated
Expand Down Expand Up @@ -193,6 +195,88 @@ structure, for example specific register ranges associated with each group
and so on.


Pin configuration
=================

Pins can sometimes be software-configured in an various ways, mostly related
to their electronic properties when used as inputs or outputs. For example you
may be able to make an output pin high impedance, or "tristate" meaning it is
effectively disconnected. You may be able to connect an input pin to VDD or GND
using a certain resistor value - pull up and pull down - so that the pin has a
stable value when nothing is driving the rail it is connected to, or when it's
unconnected.

For example, a platform may do this:

ret = pin_config_set(dev, "FOO_GPIO_PIN", PLATFORM_X_PULL_UP);

To pull up a pin to VDD. The pin configuration driver implements callbacks for
changing pin configuration in the pin controller ops like this:

#include <linux/pinctrl/pinctrl.h>
#include <linux/pinctrl/pinconf.h>
#include "platform_x_pindefs.h"

int foo_pin_config_get(struct pinctrl_dev *pctldev,
unsigned offset,
unsigned long *config)
{
struct my_conftype conf;

... Find setting for pin @ offset ...

*config = (unsigned long) conf;
}

int foo_pin_config_set(struct pinctrl_dev *pctldev,
unsigned offset,
unsigned long config)
{
struct my_conftype *conf = (struct my_conftype *) config;

switch (conf) {
case PLATFORM_X_PULL_UP:
...
}
}
}

int foo_pin_config_group_get (struct pinctrl_dev *pctldev,
unsigned selector,
unsigned long *config)
{
...
}

int foo_pin_config_group_set (struct pinctrl_dev *pctldev,
unsigned selector,
unsigned long config)
{
...
}

static struct pinconf_ops foo_pconf_ops = {
.pin_config_get = foo_pin_config_get,
.pin_config_set = foo_pin_config_set,
.pin_config_group_get = foo_pin_config_group_get,
.pin_config_group_set = foo_pin_config_group_set,
};

/* Pin config operations are handled by some pin controller */
static struct pinctrl_desc foo_desc = {
...
.confops = &foo_pconf_ops,
};

Since some controllers have special logic for handling entire groups of pins
they can exploit the special whole-group pin control function. The
pin_config_group_set() callback is allowed to return the error code -EAGAIN,
for groups it does not want to handle, or if it just wants to do some
group-level handling and then fall through to iterate over all pins, in which
case each individual pin will be treated by separate pin_config_set() calls as
well.


Interaction with the GPIO subsystem
===================================

Expand Down
5 changes: 4 additions & 1 deletion trunk/drivers/pinctrl/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ menu "Pin controllers"
depends on PINCTRL

config PINMUX
bool "Support pinmux controllers"
bool "Support pin multiplexing controllers"

config PINCONF
bool "Support pin configuration controllers"

config DEBUG_PINCTRL
bool "Debug PINCTRL calls"
Expand Down
1 change: 1 addition & 0 deletions trunk/drivers/pinctrl/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ ccflags-$(CONFIG_DEBUG_PINCTRL) += -DDEBUG

obj-$(CONFIG_PINCTRL) += core.o
obj-$(CONFIG_PINMUX) += pinmux.o
obj-$(CONFIG_PINCONF) += pinconf.o
obj-$(CONFIG_PINMUX_SIRF) += pinmux-sirf.o
obj-$(CONFIG_PINMUX_U300) += pinmux-u300.o
obj-$(CONFIG_PINCTRL_COH901) += pinctrl-coh901.o
43 changes: 42 additions & 1 deletion trunk/drivers/pinctrl/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include <linux/pinctrl/machine.h>
#include "core.h"
#include "pinmux.h"
#include "pinconf.h"

/* Global list of pin control devices */
static DEFINE_MUTEX(pinctrldev_list_mutex);
Expand Down Expand Up @@ -100,6 +101,30 @@ struct pin_desc *pin_desc_get(struct pinctrl_dev *pctldev, unsigned int pin)
return pindesc;
}

/**
* pin_get_from_name() - look up a pin number from a name
* @pctldev: the pin control device to lookup the pin on
* @name: the name of the pin to look up
*/
int pin_get_from_name(struct pinctrl_dev *pctldev, const char *name)
{
unsigned pin;

/* The highest pin number need to be included in the loop, thus <= */
for (pin = 0; pin <= pctldev->desc->maxpin; pin++) {
struct pin_desc *desc;

desc = pin_desc_get(pctldev, pin);
/* Pin space may be sparse */
if (desc == NULL)
continue;
if (desc->name && !strcmp(name, desc->name))
return pin;
}

return -EINVAL;
}

/**
* pin_is_valid() - check if pin exists on controller
* @pctldev: the pin control device to check the pin on
Expand Down Expand Up @@ -160,6 +185,7 @@ static int pinctrl_register_one_pin(struct pinctrl_dev *pctldev,
pindesc = kzalloc(sizeof(*pindesc), GFP_KERNEL);
if (pindesc == NULL)
return -ENOMEM;

spin_lock_init(&pindesc->lock);

/* Set owner */
Expand Down Expand Up @@ -409,11 +435,15 @@ static int pinctrl_devices_show(struct seq_file *s, void *what)
{
struct pinctrl_dev *pctldev;

seq_puts(s, "name [pinmux]\n");
seq_puts(s, "name [pinmux] [pinconf]\n");
mutex_lock(&pinctrldev_list_mutex);
list_for_each_entry(pctldev, &pinctrldev_list, node) {
seq_printf(s, "%s ", pctldev->desc->name);
if (pctldev->desc->pmxops)
seq_puts(s, "yes ");
else
seq_puts(s, "no ");
if (pctldev->desc->confops)
seq_puts(s, "yes");
else
seq_puts(s, "no");
Expand Down Expand Up @@ -492,6 +522,7 @@ static void pinctrl_init_device_debugfs(struct pinctrl_dev *pctldev)
debugfs_create_file("gpio-ranges", S_IFREG | S_IRUGO,
device_root, pctldev, &pinctrl_gpioranges_ops);
pinmux_init_device_debugfs(device_root, pctldev);
pinconf_init_device_debugfs(device_root, pctldev);
}

static void pinctrl_init_debugfs(void)
Expand Down Expand Up @@ -548,6 +579,16 @@ struct pinctrl_dev *pinctrl_register(struct pinctrl_desc *pctldesc,
}
}

/* If we're implementing pinconfig, check the ops for sanity */
if (pctldesc->confops) {
ret = pinconf_check_ops(pctldesc->confops);
if (ret) {
pr_err("%s pin config ops lacks necessary functions\n",
pctldesc->name);
return NULL;
}
}

pctldev = kzalloc(sizeof(struct pinctrl_dev), GFP_KERNEL);
if (pctldev == NULL)
return NULL;
Expand Down
5 changes: 5 additions & 0 deletions trunk/drivers/pinctrl/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
* License terms: GNU General Public License (GPL) version 2
*/

#include <linux/pinctrl/pinconf.h>

struct pinctrl_gpio_range;

/**
* struct pinctrl_dev - pin control class device
* @node: node to include this pin controller in the global pin controller list
Expand Down Expand Up @@ -66,6 +70,7 @@ struct pin_desc {
struct pinctrl_dev *get_pinctrl_dev_from_dev(struct device *dev,
const char *dev_name);
struct pin_desc *pin_desc_get(struct pinctrl_dev *pctldev, unsigned int pin);
int pin_get_from_name(struct pinctrl_dev *pctldev, const char *name);
int pinctrl_get_device_gpio_range(unsigned gpio,
struct pinctrl_dev **outdev,
struct pinctrl_gpio_range **outrange);
Expand Down
Loading

0 comments on commit 8031e85

Please sign in to comment.