From 28a8d14cc74a0180323d9150c3d3dbf9dd60d55a Mon Sep 17 00:00:00 2001 From: Linus Walleij Date: Thu, 9 Feb 2012 01:52:22 +0100 Subject: pinctrl: break out a pinctrl consumer header This breaks out a header to be used by all pinmux and pinconfig alike, so drivers needing services from pinctrl does not need to include different headers. This is similar to the approach taken by the regulator API. Acked-by: Stephen Warren Signed-off-by: Linus Walleij --- arch/arm/mach-u300/core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'arch/arm/mach-u300') diff --git a/arch/arm/mach-u300/core.c b/arch/arm/mach-u300/core.c index b4c6926a700c..1429e5282198 100644 --- a/arch/arm/mach-u300/core.c +++ b/arch/arm/mach-u300/core.c @@ -26,7 +26,7 @@ #include #include #include -#include +#include #include #include -- cgit v1.2.3 From e93bcee00c43e2bd4037291262111016f4c05793 Mon Sep 17 00:00:00 2001 From: Linus Walleij Date: Thu, 9 Feb 2012 07:23:28 +0100 Subject: pinctrl: move generic functions to the pinctrl_ namespace Since we want to use the former pinmux handles and mapping tables for generic control involving both muxing and configuration we begin refactoring by renaming them from pinmux_* to pinctrl_*. ChangeLog v1->v2: - Also rename the PINMUX_* macros in machine.h to PIN_ as indicated in the documentation so as to reflect the generic nature of these mapping entries from now on. Acked-by: Stephen Warren Signed-off-by: Linus Walleij --- Documentation/pinctrl.txt | 118 ++++++------- arch/arm/mach-u300/core.c | 34 ++-- drivers/pinctrl/core.c | 4 +- drivers/pinctrl/core.h | 8 +- drivers/pinctrl/pinctrl-coh901.c | 4 +- drivers/pinctrl/pinmux.c | 351 ++++++++++++++++++++------------------- drivers/pinctrl/pinmux.h | 8 +- include/linux/pinctrl/consumer.h | 34 ++-- include/linux/pinctrl/machine.h | 26 +-- 9 files changed, 294 insertions(+), 293 deletions(-) (limited to 'arch/arm/mach-u300') diff --git a/Documentation/pinctrl.txt b/Documentation/pinctrl.txt index b268832c49d2..2e7132355db8 100644 --- a/Documentation/pinctrl.txt +++ b/Documentation/pinctrl.txt @@ -728,19 +728,19 @@ same time. All the above functions are mandatory to implement for a pinmux driver. -Pinmux interaction with the GPIO subsystem -========================================== +Pin control interaction with the GPIO subsystem +=============================================== -The public pinmux API contains two functions named pinmux_request_gpio() -and pinmux_free_gpio(). These two functions shall *ONLY* be called from +The public pinmux API contains two functions named pinctrl_request_gpio() +and pinctrl_free_gpio(). These two functions shall *ONLY* be called from gpiolib-based drivers as part of their gpio_request() and -gpio_free() semantics. Likewise the pinmux_gpio_direction_[input|output] +gpio_free() semantics. Likewise the pinctrl_gpio_direction_[input|output] shall only be called from within respective gpio_direction_[input|output] gpiolib implementation. NOTE that platforms and individual drivers shall *NOT* request GPIO pins to be -muxed in. Instead, implement a proper gpiolib driver and have that driver -request proper muxing for its pins. +controlled e.g. muxed in. Instead, implement a proper gpiolib driver and have +that driver request proper muxing and other control for its pins. The function list could become long, especially if you can convert every individual pin into a GPIO pin independent of any other pins, and then try @@ -749,7 +749,7 @@ the approach to define every pin as a function. In this case, the function array would become 64 entries for each GPIO setting and then the device functions. -For this reason there are two functions a pinmux driver can implement +For this reason there are two functions a pin control driver can implement to enable only GPIO on an individual pin: .gpio_request_enable() and .gpio_disable_free(). @@ -764,7 +764,7 @@ gpiolib driver and the affected GPIO range, pin offset and desired direction will be passed along to this function. Alternatively to using these special functions, it is fully allowed to use -named functions for each GPIO pin, the pinmux_request_gpio() will attempt to +named functions for each GPIO pin, the pinctrl_request_gpio() will attempt to obtain the function "gpioN" where "N" is the global GPIO pin number if no special GPIO-handler is registered. @@ -783,7 +783,7 @@ spi on the second function mapping: #include -static const struct pinmux_map __initdata pmx_mapping[] = { +static const struct pinctrl_map __initdata mapping[] = { { .ctrl_dev_name = "pinctrl-foo", .function = "spi0", @@ -811,14 +811,14 @@ to map. You register this pinmux mapping to the pinmux subsystem by simply: - ret = pinmux_register_mappings(pmx_mapping, ARRAY_SIZE(pmx_mapping)); + ret = pinctrl_register_mappings(mapping, ARRAY_SIZE(mapping)); Since the above construct is pretty common there is a helper macro to make it even more compact which assumes you want to use pinctrl-foo and position 0 for mapping, for example: -static struct pinmux_map __initdata pmx_mapping[] = { - PINMUX_MAP("I2CMAP", "pinctrl-foo", "i2c0", "foo-i2c.0"), +static struct pinctrl_map __initdata mapping[] = { + PIN_MAP("I2CMAP", "pinctrl-foo", "i2c0", "foo-i2c.0"), }; @@ -901,7 +901,7 @@ case), we define a mapping like this: The result of grabbing this mapping from the device with something like this (see next paragraph): - pmx = pinmux_get(&device, "8bit"); + p = pinctrl_get(&device, "8bit"); Will be that you activate all the three bottom records in the mapping at once. Since they share the same name, pin controller device, funcion and @@ -913,44 +913,44 @@ pinmux core. Pinmux requests from drivers ============================ -Generally it is discouraged to let individual drivers get and enable pinmuxes. -So if possible, handle the pinmuxes in platform code or some other place where -you have access to all the affected struct device * pointers. In some cases -where a driver needs to switch between different mux mappings at runtime -this is not possible. +Generally it is discouraged to let individual drivers get and enable pin +control. So if possible, handle the pin control in platform code or some other +place where you have access to all the affected struct device * pointers. In +some cases where a driver needs to e.g. switch between different mux mappings +at runtime this is not possible. -A driver may request a certain mux to be activated, usually just the default -mux like this: +A driver may request a certain control state to be activated, usually just the +default state like this: #include struct foo_state { - struct pinmux *pmx; + struct pinctrl *p; ... }; foo_probe() { /* Allocate a state holder named "state" etc */ - struct pinmux pmx; + struct pinctrl p; - pmx = pinmux_get(&device, NULL); - if IS_ERR(pmx) - return PTR_ERR(pmx); - pinmux_enable(pmx); + p = pinctrl_get(&device, NULL); + if IS_ERR(p) + return PTR_ERR(p); + pinctrl_enable(p); - state->pmx = pmx; + state->p = p; } foo_remove() { - pinmux_disable(state->pmx); - pinmux_put(state->pmx); + pinctrl_disable(state->p); + pinctrl_put(state->p); } -If you want to grab a specific mux mapping and not just the first one found for -this device you can specify a specific mapping name, for example in the above -example the second i2c0 setting: pinmux_get(&device, "spi0-pos-B"); +If you want to grab a specific control mapping and not just the first one +found for this device you can specify a specific mapping name, for example in +the above example the second i2c0 setting: pinctrl_get(&device, "spi0-pos-B"); This get/enable/disable/put sequence can just as well be handled by bus drivers if you don't want each and every driver to handle it and you know the @@ -958,35 +958,35 @@ arrangement on your bus. The semantics of the get/enable respective disable/put is as follows: -- pinmux_get() is called in process context to reserve the pins affected with +- pinctrl_get() is called in process context to reserve the pins affected with a certain mapping and set up the pinmux core and the driver. It will allocate a struct from the kernel memory to hold the pinmux state. -- pinmux_enable()/pinmux_disable() is quick and can be called from fastpath +- pinctrl_enable()/pinctrl_disable() is quick and can be called from fastpath (irq context) when you quickly want to set up/tear down the hardware muxing when running a device driver. Usually it will just poke some values into a register. -- pinmux_disable() is called in process context to tear down the pin requests - and release the state holder struct for the mux setting. +- pinctrl_disable() is called in process context to tear down the pin requests + and release the state holder struct for the mux setting etc. -Usually the pinmux core handled the get/put pair and call out to the device -drivers bookkeeping operations, like checking available functions and the -associated pins, whereas the enable/disable pass on to the pin controller +Usually the pin control core handled the get/put pair and call out to the +device drivers bookkeeping operations, like checking available functions and +the associated pins, whereas the enable/disable pass on to the pin controller driver which takes care of activating and/or deactivating the mux setting by quickly poking some registers. -The pins are allocated for your device when you issue the pinmux_get() call, +The pins are allocated for your device when you issue the pinctrl_get() call, after this you should be able to see this in the debugfs listing of all pins. -System pinmux hogging -===================== +System pin control hogging +========================== -A system pinmux map entry, i.e. a pinmux setting that does not have a device -associated with it, can be hogged by the core when the pin controller is -registered. This means that the core will attempt to call pinmux_get() and -pinmux_enable() on it immediately after the pin control device has been +A system pin control map entry, i.e. a pin control setting that does not have +a device associated with it, can be hogged by the core when the pin controller +is registered. This means that the core will attempt to call pinctrl_get() and +pinctrl_enable() on it immediately after the pin control device has been registered. This is enabled by simply setting the .hog_on_boot field in the map to true, @@ -1003,7 +1003,7 @@ Since it may be common to request the core to hog a few always-applicable mux settings on the primary pin controller, there is a convenience macro for this: -PINMUX_MAP_PRIMARY_SYS_HOG("POWERMAP", "power_func") +PIN_MAP_PRIMARY_SYS_HOG("POWERMAP", "power_func") This gives the exact same result as the above construction. @@ -1025,23 +1025,23 @@ it, disables and releases it, and muxes it in on the pins defined by group B: foo_switch() { - struct pinmux *pmx; + struct pinctrl *p; /* Enable on position A */ - pmx = pinmux_get(&device, "spi0-pos-A"); - if IS_ERR(pmx) - return PTR_ERR(pmx); - pinmux_enable(pmx); + p = pinctrl_get(&device, "spi0-pos-A"); + if IS_ERR(p) + return PTR_ERR(p); + pinctrl_enable(p); /* This releases the pins again */ - pinmux_disable(pmx); - pinmux_put(pmx); + pinctrl_disable(p); + pinctrl_put(p); /* Enable on position B */ - pmx = pinmux_get(&device, "spi0-pos-B"); - if IS_ERR(pmx) - return PTR_ERR(pmx); - pinmux_enable(pmx); + p = pinctrl_get(&device, "spi0-pos-B"); + if IS_ERR(p) + return PTR_ERR(p); + pinctrl_enable(p); ... } diff --git a/arch/arm/mach-u300/core.c b/arch/arm/mach-u300/core.c index 1429e5282198..bb1034f8c2f5 100644 --- a/arch/arm/mach-u300/core.c +++ b/arch/arm/mach-u300/core.c @@ -1605,21 +1605,21 @@ static struct platform_device pinmux_device = { }; /* Pinmux settings */ -static struct pinmux_map __initdata u300_pinmux_map[] = { +static struct pinctrl_map __initdata u300_pinmux_map[] = { /* anonymous maps for chip power and EMIFs */ - PINMUX_MAP_SYS_HOG("POWER", "pinmux-u300", "power"), - PINMUX_MAP_SYS_HOG("EMIF0", "pinmux-u300", "emif0"), - PINMUX_MAP_SYS_HOG("EMIF1", "pinmux-u300", "emif1"), + PIN_MAP_SYS_HOG("POWER", "pinmux-u300", "power"), + PIN_MAP_SYS_HOG("EMIF0", "pinmux-u300", "emif0"), + PIN_MAP_SYS_HOG("EMIF1", "pinmux-u300", "emif1"), /* per-device maps for MMC/SD, SPI and UART */ - PINMUX_MAP("MMCSD", "pinmux-u300", "mmc0", "mmci"), - PINMUX_MAP("SPI", "pinmux-u300", "spi0", "pl022"), - PINMUX_MAP("UART0", "pinmux-u300", "uart0", "uart0"), + PIN_MAP("MMCSD", "pinmux-u300", "mmc0", "mmci"), + PIN_MAP("SPI", "pinmux-u300", "spi0", "pl022"), + PIN_MAP("UART0", "pinmux-u300", "uart0", "uart0"), }; struct u300_mux_hog { const char *name; struct device *dev; - struct pinmux *pmx; + struct pinctrl *p; }; static struct u300_mux_hog u300_mux_hogs[] = { @@ -1637,31 +1637,31 @@ static struct u300_mux_hog u300_mux_hogs[] = { }, }; -static int __init u300_pinmux_fetch(void) +static int __init u300_pinctrl_fetch(void) { int i; for (i = 0; i < ARRAY_SIZE(u300_mux_hogs); i++) { - struct pinmux *pmx; + struct pinctrl *p; int ret; - pmx = pinmux_get(u300_mux_hogs[i].dev, NULL); - if (IS_ERR(pmx)) { + p = pinctrl_get(u300_mux_hogs[i].dev, NULL); + if (IS_ERR(p)) { pr_err("u300: could not get pinmux hog %s\n", u300_mux_hogs[i].name); continue; } - ret = pinmux_enable(pmx); + ret = pinctrl_enable(p); if (ret) { pr_err("u300: could enable pinmux hog %s\n", u300_mux_hogs[i].name); continue; } - u300_mux_hogs[i].pmx = pmx; + u300_mux_hogs[i].p = p; } return 0; } -subsys_initcall(u300_pinmux_fetch); +subsys_initcall(u300_pinctrl_fetch); /* * Notice that AMBA devices are initialized before platform devices. @@ -1861,8 +1861,8 @@ void __init u300_init_devices(void) u300_assign_physmem(); /* Initialize pinmuxing */ - pinmux_register_mappings(u300_pinmux_map, - ARRAY_SIZE(u300_pinmux_map)); + pinctrl_register_mappings(u300_pinmux_map, + ARRAY_SIZE(u300_pinmux_map)); /* Register subdevices on the I2C buses */ u300_i2c_register_board_devices(); diff --git a/drivers/pinctrl/core.c b/drivers/pinctrl/core.c index 4f10476cc1f2..75c6a6bb6c0a 100644 --- a/drivers/pinctrl/core.c +++ b/drivers/pinctrl/core.c @@ -624,7 +624,7 @@ struct pinctrl_dev *pinctrl_register(struct pinctrl_desc *pctldesc, mutex_lock(&pinctrldev_list_mutex); list_add(&pctldev->node, &pinctrldev_list); mutex_unlock(&pinctrldev_list_mutex); - pinmux_hog_maps(pctldev); + pinctrl_hog_maps(pctldev); return pctldev; out_err: @@ -645,7 +645,7 @@ void pinctrl_unregister(struct pinctrl_dev *pctldev) return; pinctrl_remove_device_debugfs(pctldev); - pinmux_unhog_maps(pctldev); + pinctrl_unhog_maps(pctldev); /* TODO: check that no pinmuxes are still active? */ mutex_lock(&pinctrldev_list_mutex); list_del(&pctldev->node); diff --git a/drivers/pinctrl/core.h b/drivers/pinctrl/core.h index 8a8b02e9c18e..7a89888fce94 100644 --- a/drivers/pinctrl/core.h +++ b/drivers/pinctrl/core.h @@ -28,8 +28,8 @@ struct pinctrl_gpio_range; * @owner: module providing the pin controller, used for refcounting * @driver_data: driver data for drivers registering to the pin controller * subsystem - * @pinmux_hogs_lock: lock for the pinmux hog list - * @pinmux_hogs: list of pinmux maps hogged by this device + * @pinctrl_hogs_lock: lock for the pin control hog list + * @pinctrl_hogs: list of pin control maps hogged by this device */ struct pinctrl_dev { struct list_head node; @@ -45,8 +45,8 @@ struct pinctrl_dev { struct dentry *device_root; #endif #ifdef CONFIG_PINMUX - struct mutex pinmux_hogs_lock; - struct list_head pinmux_hogs; + struct mutex pinctrl_hogs_lock; + struct list_head pinctrl_hogs; #endif }; diff --git a/drivers/pinctrl/pinctrl-coh901.c b/drivers/pinctrl/pinctrl-coh901.c index 8bac3f093d58..eba232a46a82 100644 --- a/drivers/pinctrl/pinctrl-coh901.c +++ b/drivers/pinctrl/pinctrl-coh901.c @@ -360,14 +360,14 @@ static int u300_gpio_request(struct gpio_chip *chip, unsigned offset) */ int gpio = chip->base + offset; - return pinmux_request_gpio(gpio); + return pinctrl_request_gpio(gpio); } static void u300_gpio_free(struct gpio_chip *chip, unsigned offset) { int gpio = chip->base + offset; - pinmux_free_gpio(gpio); + pinctrl_free_gpio(gpio); } static int u300_gpio_get(struct gpio_chip *chip, unsigned offset) diff --git a/drivers/pinctrl/pinmux.c b/drivers/pinctrl/pinmux.c index 1311f1d22002..773835d18f55 100644 --- a/drivers/pinctrl/pinmux.c +++ b/drivers/pinctrl/pinmux.c @@ -1,7 +1,7 @@ /* * Core driver for the pin muxing portions of the pin control subsystem * - * Copyright (C) 2011 ST-Ericsson SA + * Copyright (C) 2011-2012 ST-Ericsson SA * Written on behalf of Linaro for ST-Ericsson * Based on bits of regulator core, gpio core and clk core * @@ -29,13 +29,13 @@ #include #include "core.h" -/* List of pinmuxes */ -static DEFINE_MUTEX(pinmux_list_mutex); -static LIST_HEAD(pinmux_list); +/* List of pin controller handles */ +static DEFINE_MUTEX(pinctrl_list_mutex); +static LIST_HEAD(pinctrl_list); -/* Global pinmux maps */ -static struct pinmux_map *pinmux_maps; -static unsigned pinmux_maps_num; +/* Global pinctrl maps */ +static struct pinctrl_map *pinctrl_maps; +static unsigned pinctrl_maps_num; /** * struct pinmux_group - group list item for pinmux groups @@ -48,12 +48,12 @@ struct pinmux_group { }; /** - * struct pinmux - per-device pinmux state holder + * struct pinctrl - per-device pin control state holder * @node: global list node - * @dev: the device using this pinmux - * @usecount: the number of active users of this mux setting, used to keep - * track of nested use cases - * @pctldev: pin control device handling this pinmux + * @dev: the device using this pin control handle + * @usecount: the number of active users of this pin controller setting, used + * to keep track of nested use cases + * @pctldev: pin control device handling this pin control handle * @func_selector: the function selector for the pinmux device handling * this pinmux * @groups: the group selectors for the pinmux device and @@ -62,7 +62,7 @@ struct pinmux_group { * get/put/enable/disable * @mutex: a lock for the pinmux state holder */ -struct pinmux { +struct pinctrl { struct list_head node; struct device *dev; unsigned usecount; @@ -73,15 +73,15 @@ struct pinmux { }; /** - * struct pinmux_hog - a list item to stash mux hogs - * @node: pinmux hog list node + * struct pinctrl_hog - a list item to stash control hogs + * @node: pin control hog list node * @map: map entry responsible for this hogging - * @pmx: the pinmux hogged by this item + * @pmx: the pin control hogged by this item */ -struct pinmux_hog { +struct pinctrl_hog { struct list_head node; - struct pinmux_map const *map; - struct pinmux *pmx; + struct pinctrl_map const *map; + struct pinctrl *p; }; /** @@ -207,14 +207,14 @@ static const char *pin_free(struct pinctrl_dev *pctldev, int pin, } /** - * pinmux_request_gpio() - request a single pin to be muxed in as GPIO + * pinctrl_request_gpio() - request a single pin to be used in as GPIO * @gpio: the GPIO pin number from the GPIO subsystem number space * * This function should *ONLY* be used from gpiolib-based GPIO drivers, * as part of their gpio_request() semantics, platforms and individual drivers * shall *NOT* request GPIO pins to be muxed in. */ -int pinmux_request_gpio(unsigned gpio) +int pinctrl_request_gpio(unsigned gpio) { char gpiostr[16]; const char *function; @@ -243,17 +243,17 @@ int pinmux_request_gpio(unsigned gpio) return ret; } -EXPORT_SYMBOL_GPL(pinmux_request_gpio); +EXPORT_SYMBOL_GPL(pinctrl_request_gpio); /** - * pinmux_free_gpio() - free a single pin, currently used as GPIO + * pinctrl_free_gpio() - free control on a single pin, currently used as GPIO * @gpio: the GPIO pin number from the GPIO subsystem number space * * This function should *ONLY* be used from gpiolib-based GPIO drivers, * as part of their gpio_free() semantics, platforms and individual drivers * shall *NOT* request GPIO pins to be muxed out. */ -void pinmux_free_gpio(unsigned gpio) +void pinctrl_free_gpio(unsigned gpio) { struct pinctrl_dev *pctldev; struct pinctrl_gpio_range *range; @@ -271,9 +271,9 @@ void pinmux_free_gpio(unsigned gpio) func = pin_free(pctldev, pin, range); kfree(func); } -EXPORT_SYMBOL_GPL(pinmux_free_gpio); +EXPORT_SYMBOL_GPL(pinctrl_free_gpio); -static int pinmux_gpio_direction(unsigned gpio, bool input) +static int pinctrl_gpio_direction(unsigned gpio, bool input) { struct pinctrl_dev *pctldev; struct pinctrl_gpio_range *range; @@ -299,36 +299,36 @@ static int pinmux_gpio_direction(unsigned gpio, bool input) } /** - * pinmux_gpio_direction_input() - request a GPIO pin to go into input mode + * pinctrl_gpio_direction_input() - request a GPIO pin to go into input mode * @gpio: the GPIO pin number from the GPIO subsystem number space * * This function should *ONLY* be used from gpiolib-based GPIO drivers, * as part of their gpio_direction_input() semantics, platforms and individual - * drivers shall *NOT* touch pinmux GPIO calls. + * drivers shall *NOT* touch pin control GPIO calls. */ -int pinmux_gpio_direction_input(unsigned gpio) +int pinctrl_gpio_direction_input(unsigned gpio) { - return pinmux_gpio_direction(gpio, true); + return pinctrl_gpio_direction(gpio, true); } -EXPORT_SYMBOL_GPL(pinmux_gpio_direction_input); +EXPORT_SYMBOL_GPL(pinctrl_gpio_direction_input); /** - * pinmux_gpio_direction_output() - request a GPIO pin to go into output mode + * pinctrl_gpio_direction_output() - request a GPIO pin to go into output mode * @gpio: the GPIO pin number from the GPIO subsystem number space * * This function should *ONLY* be used from gpiolib-based GPIO drivers, * as part of their gpio_direction_output() semantics, platforms and individual - * drivers shall *NOT* touch pinmux GPIO calls. + * drivers shall *NOT* touch pin control GPIO calls. */ -int pinmux_gpio_direction_output(unsigned gpio) +int pinctrl_gpio_direction_output(unsigned gpio) { - return pinmux_gpio_direction(gpio, false); + return pinctrl_gpio_direction(gpio, false); } -EXPORT_SYMBOL_GPL(pinmux_gpio_direction_output); +EXPORT_SYMBOL_GPL(pinctrl_gpio_direction_output); /** - * pinmux_register_mappings() - register a set of pinmux mappings - * @maps: the pinmux mappings table to register, this should be marked with + * pinctrl_register_mappings() - register a set of pin controller mappings + * @maps: the pincontrol mappings table to register, this should be marked with * __initdata so it can be discarded after boot, this function will * perform a shallow copy for the mapping entries. * @num_maps: the number of maps in the mapping table @@ -338,8 +338,8 @@ EXPORT_SYMBOL_GPL(pinmux_gpio_direction_output); * passed into this function will be owned by the pinmux core and cannot be * freed. */ -int __init pinmux_register_mappings(struct pinmux_map const *maps, - unsigned num_maps) +int __init pinctrl_register_mappings(struct pinctrl_map const *maps, + unsigned num_maps) { void *tmp_maps; int i; @@ -380,26 +380,27 @@ int __init pinmux_register_mappings(struct pinmux_map const *maps, * Make a copy of the map array - string pointers will end up in the * kernel const section anyway so these do not need to be deep copied. */ - if (!pinmux_maps_num) { + if (!pinctrl_maps_num) { /* On first call, just copy them */ tmp_maps = kmemdup(maps, - sizeof(struct pinmux_map) * num_maps, + sizeof(struct pinctrl_map) * num_maps, GFP_KERNEL); if (!tmp_maps) return -ENOMEM; } else { /* Subsequent calls, reallocate array to new size */ - size_t oldsize = sizeof(struct pinmux_map) * pinmux_maps_num; - size_t newsize = sizeof(struct pinmux_map) * num_maps; + size_t oldsize = sizeof(struct pinctrl_map) * pinctrl_maps_num; + size_t newsize = sizeof(struct pinctrl_map) * num_maps; - tmp_maps = krealloc(pinmux_maps, oldsize + newsize, GFP_KERNEL); + tmp_maps = krealloc(pinctrl_maps, + oldsize + newsize, GFP_KERNEL); if (!tmp_maps) return -ENOMEM; memcpy((tmp_maps + oldsize), maps, newsize); } - pinmux_maps = tmp_maps; - pinmux_maps_num += num_maps; + pinctrl_maps = tmp_maps; + pinctrl_maps_num += num_maps; return 0; } @@ -560,7 +561,7 @@ static int pinmux_check_pin_group(struct pinctrl_dev *pctldev, * negative otherwise */ static int pinmux_search_function(struct pinctrl_dev *pctldev, - struct pinmux_map const *map, + struct pinctrl_map const *map, unsigned *func_selector, unsigned *group_selector) { @@ -598,10 +599,10 @@ static int pinmux_search_function(struct pinctrl_dev *pctldev, * pinmux_enable_muxmap() - enable a map entry for a certain pinmux */ static int pinmux_enable_muxmap(struct pinctrl_dev *pctldev, - struct pinmux *pmx, + struct pinctrl *p, struct device *dev, const char *devname, - struct pinmux_map const *map) + struct pinctrl_map const *map) { unsigned func_selector; unsigned group_selector; @@ -615,14 +616,14 @@ static int pinmux_enable_muxmap(struct pinctrl_dev *pctldev, * by anyone else. */ - if (pmx->pctldev && pmx->pctldev != pctldev) { + if (p->pctldev && p->pctldev != pctldev) { dev_err(pctldev->dev, "different pin control devices given for device %s, function %s\n", devname, map->function); return -EINVAL; } - pmx->dev = dev; - pmx->pctldev = pctldev; + p->dev = dev; + p->pctldev = pctldev; /* Now go into the driver and try to match a function and group */ ret = pinmux_search_function(pctldev, map, &func_selector, @@ -635,14 +636,14 @@ static int pinmux_enable_muxmap(struct pinctrl_dev *pctldev, * we support several groups with one function but not several * functions with one or several groups in the same pinmux. */ - if (pmx->func_selector != UINT_MAX && - pmx->func_selector != func_selector) { + if (p->func_selector != UINT_MAX && + p->func_selector != func_selector) { dev_err(pctldev->dev, "dual function defines in the map for device %s\n", devname); return -EINVAL; } - pmx->func_selector = func_selector; + p->func_selector = func_selector; /* Now add this group selector, we may have many of them */ grp = kmalloc(sizeof(struct pinmux_group), GFP_KERNEL); @@ -654,38 +655,38 @@ static int pinmux_enable_muxmap(struct pinctrl_dev *pctldev, kfree(grp); return ret; } - list_add(&grp->node, &pmx->groups); + list_add(&grp->node, &p->groups); return 0; } -static void pinmux_free_groups(struct pinmux *pmx) +static void pinmux_free_groups(struct pinctrl *p) { struct list_head *node, *tmp; - list_for_each_safe(node, tmp, &pmx->groups) { + list_for_each_safe(node, tmp, &p->groups) { struct pinmux_group *grp = list_entry(node, struct pinmux_group, node); /* Release all pins taken by this group */ - release_pins(pmx->pctldev, grp->group_selector); + release_pins(p->pctldev, grp->group_selector); list_del(node); kfree(grp); } } /** - * pinmux_get() - retrieves the pinmux for a certain device - * @dev: the device to get the pinmux for - * @name: an optional specific mux mapping name or NULL, the name is only + * pinctrl_get() - retrieves the pin controller handle for a certain device + * @dev: the device to get the pin controller handle for + * @name: an optional specific control mapping name or NULL, the name is only * needed if you want to have more than one mapping per device, or if you - * need an anonymous pinmux (not tied to any specific device) + * need an anonymous pin control (not tied to any specific device) */ -struct pinmux *pinmux_get(struct device *dev, const char *name) +struct pinctrl *pinctrl_get(struct device *dev, const char *name) { - struct pinmux_map const *map = NULL; + struct pinctrl_map const *map = NULL; struct pinctrl_dev *pctldev = NULL; const char *devname = NULL; - struct pinmux *pmx; + struct pinctrl *p; bool found_map; unsigned num_maps = 0; int ret = -ENODEV; @@ -706,16 +707,16 @@ struct pinmux *pinmux_get(struct device *dev, const char *name) * mapping, this is what consumers will get when requesting * a pinmux handle with pinmux_get() */ - pmx = kzalloc(sizeof(struct pinmux), GFP_KERNEL); - if (pmx == NULL) + p = kzalloc(sizeof(struct pinctrl), GFP_KERNEL); + if (p == NULL) return ERR_PTR(-ENOMEM); - mutex_init(&pmx->mutex); - pmx->func_selector = UINT_MAX; - INIT_LIST_HEAD(&pmx->groups); + mutex_init(&p->mutex); + p->func_selector = UINT_MAX; + INIT_LIST_HEAD(&p->groups); - /* Iterate over the pinmux maps to locate the right ones */ - for (i = 0; i < pinmux_maps_num; i++) { - map = &pinmux_maps[i]; + /* Iterate over the pin control maps to locate the right ones */ + for (i = 0; i < pinctrl_maps_num; i++) { + map = &pinctrl_maps[i]; found_map = false; /* @@ -763,11 +764,11 @@ struct pinmux *pinmux_get(struct device *dev, const char *name) /* If this map is applicable, then apply it */ if (found_map) { - ret = pinmux_enable_muxmap(pctldev, pmx, dev, + ret = pinmux_enable_muxmap(pctldev, p, dev, devname, map); if (ret) { - pinmux_free_groups(pmx); - kfree(pmx); + pinmux_free_groups(p); + kfree(p); return ERR_PTR(ret); } num_maps++; @@ -780,7 +781,7 @@ struct pinmux *pinmux_get(struct device *dev, const char *name) pr_err("could not find any mux maps for device %s, ID %s\n", devname ? devname : "(anonymous)", name ? name : "(undefined)"); - kfree(pmx); + kfree(p); return ERR_PTR(-EINVAL); } @@ -790,96 +791,96 @@ struct pinmux *pinmux_get(struct device *dev, const char *name) name ? name : "(undefined)"); /* Add the pinmux to the global list */ - mutex_lock(&pinmux_list_mutex); - list_add(&pmx->node, &pinmux_list); - mutex_unlock(&pinmux_list_mutex); + mutex_lock(&pinctrl_list_mutex); + list_add(&p->node, &pinctrl_list); + mutex_unlock(&pinctrl_list_mutex); - return pmx; + return p; } -EXPORT_SYMBOL_GPL(pinmux_get); +EXPORT_SYMBOL_GPL(pinctrl_get); /** - * pinmux_put() - release a previously claimed pinmux - * @pmx: a pinmux previously claimed by pinmux_get() + * pinctrl_put() - release a previously claimed pin control handle + * @p: a pin control handle previously claimed by pinctrl_get() */ -void pinmux_put(struct pinmux *pmx) +void pinctrl_put(struct pinctrl *p) { - if (pmx == NULL) + if (p == NULL) return; - mutex_lock(&pmx->mutex); - if (pmx->usecount) - pr_warn("releasing pinmux with active users!\n"); + mutex_lock(&p->mutex); + if (p->usecount) + pr_warn("releasing pin control handle with active users!\n"); /* Free the groups and all acquired pins */ - pinmux_free_groups(pmx); - mutex_unlock(&pmx->mutex); + pinmux_free_groups(p); + mutex_unlock(&p->mutex); /* Remove from list */ - mutex_lock(&pinmux_list_mutex); - list_del(&pmx->node); - mutex_unlock(&pinmux_list_mutex); + mutex_lock(&pinctrl_list_mutex); + list_del(&p->node); + mutex_unlock(&pinctrl_list_mutex); - kfree(pmx); + kfree(p); } -EXPORT_SYMBOL_GPL(pinmux_put); +EXPORT_SYMBOL_GPL(pinctrl_put); /** - * pinmux_enable() - enable a certain pinmux setting - * @pmx: the pinmux to enable, previously claimed by pinmux_get() + * pinctrl_enable() - enable a certain pin controller setting + * @p: the pin control handle to enable, previously claimed by pinctrl_get() */ -int pinmux_enable(struct pinmux *pmx) +int pinctrl_enable(struct pinctrl *p) { int ret = 0; - if (pmx == NULL) + if (p == NULL) return -EINVAL; - mutex_lock(&pmx->mutex); - if (pmx->usecount++ == 0) { - struct pinctrl_dev *pctldev = pmx->pctldev; + mutex_lock(&p->mutex); + if (p->usecount++ == 0) { + struct pinctrl_dev *pctldev = p->pctldev; const struct pinmux_ops *ops = pctldev->desc->pmxops; struct pinmux_group *grp; - list_for_each_entry(grp, &pmx->groups, node) { - ret = ops->enable(pctldev, pmx->func_selector, + list_for_each_entry(grp, &p->groups, node) { + ret = ops->enable(pctldev, p->func_selector, grp->group_selector); if (ret) { /* * TODO: call disable() on all groups we called * enable() on to this point? */ - pmx->usecount--; + p->usecount--; break; } } } - mutex_unlock(&pmx->mutex); + mutex_unlock(&p->mutex); return ret; } -EXPORT_SYMBOL_GPL(pinmux_enable); +EXPORT_SYMBOL_GPL(pinctrl_enable); /** - * pinmux_disable() - disable a certain pinmux setting - * @pmx: the pinmux to disable, previously claimed by pinmux_get() + * pinctrl_disable() - disable a certain pin control setting + * @p: the pin control handle to disable, previously claimed by pinctrl_get() */ -void pinmux_disable(struct pinmux *pmx) +void pinctrl_disable(struct pinctrl *p) { - if (pmx == NULL) + if (p == NULL) return; - mutex_lock(&pmx->mutex); - if (--pmx->usecount == 0) { - struct pinctrl_dev *pctldev = pmx->pctldev; + mutex_lock(&p->mutex); + if (--p->usecount == 0) { + struct pinctrl_dev *pctldev = p->pctldev; const struct pinmux_ops *ops = pctldev->desc->pmxops; struct pinmux_group *grp; - list_for_each_entry(grp, &pmx->groups, node) { - ops->disable(pctldev, pmx->func_selector, + list_for_each_entry(grp, &p->groups, node) { + ops->disable(pctldev, p->func_selector, grp->group_selector); } } - mutex_unlock(&pmx->mutex); + mutex_unlock(&p->mutex); } -EXPORT_SYMBOL_GPL(pinmux_disable); +EXPORT_SYMBOL_GPL(pinctrl_disable); int pinmux_check_ops(struct pinctrl_dev *pctldev) { @@ -910,11 +911,11 @@ int pinmux_check_ops(struct pinctrl_dev *pctldev) } /* Hog a single map entry and add to the hoglist */ -static int pinmux_hog_map(struct pinctrl_dev *pctldev, - struct pinmux_map const *map) +static int pinctrl_hog_map(struct pinctrl_dev *pctldev, + struct pinctrl_map const *map) { - struct pinmux_hog *hog; - struct pinmux *pmx; + struct pinctrl_hog *hog; + struct pinctrl *p; int ret; if (map->dev_name) { @@ -929,61 +930,61 @@ static int pinmux_hog_map(struct pinctrl_dev *pctldev, return -EINVAL; } - hog = kzalloc(sizeof(struct pinmux_hog), GFP_KERNEL); + hog = kzalloc(sizeof(struct pinctrl_hog), GFP_KERNEL); if (!hog) return -ENOMEM; - pmx = pinmux_get(NULL, map->name); - if (IS_ERR(pmx)) { + p = pinctrl_get(NULL, map->name); + if (IS_ERR(p)) { kfree(hog); dev_err(pctldev->dev, - "could not get the %s pinmux mapping for hogging\n", + "could not get the %s pin control mapping for hogging\n", map->name); - return PTR_ERR(pmx); + return PTR_ERR(p); } - ret = pinmux_enable(pmx); + ret = pinctrl_enable(p); if (ret) { - pinmux_put(pmx); + pinctrl_put(p); kfree(hog); dev_err(pctldev->dev, - "could not enable the %s pinmux mapping for hogging\n", + "could not enable the %s pin control mapping for hogging\n", map->name); return ret; } hog->map = map; - hog->pmx = pmx; + hog->p = p; dev_info(pctldev->dev, "hogged map %s, function %s\n", map->name, map->function); - mutex_lock(&pctldev->pinmux_hogs_lock); - list_add(&hog->node, &pctldev->pinmux_hogs); - mutex_unlock(&pctldev->pinmux_hogs_lock); + mutex_lock(&pctldev->pinctrl_hogs_lock); + list_add(&hog->node, &pctldev->pinctrl_hogs); + mutex_unlock(&pctldev->pinctrl_hogs_lock); return 0; } /** - * pinmux_hog_maps() - hog specific map entries on controller device + * pinctrl_hog_maps() - hog specific map entries on controller device * @pctldev: the pin control device to hog entries on * * When the pin controllers are registered, there may be some specific pinmux * map entries that need to be hogged, i.e. get+enabled until the system shuts * down. */ -int pinmux_hog_maps(struct pinctrl_dev *pctldev) +int pinctrl_hog_maps(struct pinctrl_dev *pctldev) { struct device *dev = pctldev->dev; const char *devname = dev_name(dev); int ret; int i; - INIT_LIST_HEAD(&pctldev->pinmux_hogs); - mutex_init(&pctldev->pinmux_hogs_lock); + INIT_LIST_HEAD(&pctldev->pinctrl_hogs); + mutex_init(&pctldev->pinctrl_hogs_lock); - for (i = 0; i < pinmux_maps_num; i++) { - struct pinmux_map const *map = &pinmux_maps[i]; + for (i = 0; i < pinctrl_maps_num; i++) { + struct pinctrl_map const *map = &pinctrl_maps[i]; if (!map->hog_on_boot) continue; @@ -991,7 +992,7 @@ int pinmux_hog_maps(struct pinctrl_dev *pctldev) if (map->ctrl_dev_name && !strcmp(map->ctrl_dev_name, devname)) { /* OK time to hog! */ - ret = pinmux_hog_map(pctldev, map); + ret = pinctrl_hog_map(pctldev, map); if (ret) return ret; } @@ -1000,23 +1001,23 @@ int pinmux_hog_maps(struct pinctrl_dev *pctldev) } /** - * pinmux_unhog_maps() - unhog specific map entries on controller device + * pinctrl_unhog_maps() - unhog specific map entries on controller device * @pctldev: the pin control device to unhog entries on */ -void pinmux_unhog_maps(struct pinctrl_dev *pctldev) +void pinctrl_unhog_maps(struct pinctrl_dev *pctldev) { struct list_head *node, *tmp; - mutex_lock(&pctldev->pinmux_hogs_lock); - list_for_each_safe(node, tmp, &pctldev->pinmux_hogs) { - struct pinmux_hog *hog = - list_entry(node, struct pinmux_hog, node); - pinmux_disable(hog->pmx); - pinmux_put(hog->pmx); + mutex_lock(&pctldev->pinctrl_hogs_lock); + list_for_each_safe(node, tmp, &pctldev->pinctrl_hogs) { + struct pinctrl_hog *hog = + list_entry(node, struct pinctrl_hog, node); + pinctrl_disable(hog->p); + pinctrl_put(hog->p); list_del(node); kfree(hog); } - mutex_unlock(&pctldev->pinmux_hogs_lock); + mutex_unlock(&pctldev->pinctrl_hogs_lock); } #ifdef CONFIG_DEBUG_FS @@ -1085,11 +1086,11 @@ static int pinmux_pins_show(struct seq_file *s, void *what) static int pinmux_hogs_show(struct seq_file *s, void *what) { struct pinctrl_dev *pctldev = s->private; - struct pinmux_hog *hog; + struct pinctrl_hog *hog; - seq_puts(s, "Pinmux map hogs held by device\n"); + seq_puts(s, "Pin control map hogs held by device\n"); - list_for_each_entry(hog, &pctldev->pinmux_hogs, node) + list_for_each_entry(hog, &pctldev->pinctrl_hogs, node) seq_printf(s, "%s\n", hog->map->name); return 0; @@ -1097,11 +1098,11 @@ static int pinmux_hogs_show(struct seq_file *s, void *what) static int pinmux_show(struct seq_file *s, void *what) { - struct pinmux *pmx; + struct pinctrl *p; seq_puts(s, "Requested pinmuxes and their maps:\n"); - list_for_each_entry(pmx, &pinmux_list, node) { - struct pinctrl_dev *pctldev = pmx->pctldev; + list_for_each_entry(p, &pinctrl_list, node) { + struct pinctrl_dev *pctldev = p->pctldev; const struct pinmux_ops *pmxops; const struct pinctrl_ops *pctlops; struct pinmux_group *grp; @@ -1115,13 +1116,13 @@ static int pinmux_show(struct seq_file *s, void *what) pctlops = pctldev->desc->pctlops; seq_printf(s, "device: %s function: %s (%u),", - pinctrl_dev_get_name(pmx->pctldev), + pinctrl_dev_get_name(p->pctldev), pmxops->get_function_name(pctldev, - pmx->func_selector), - pmx->func_selector); + p->func_selector), + p->func_selector); seq_printf(s, " groups: ["); - list_for_each_entry(grp, &pmx->groups, node) { + list_for_each_entry(grp, &p->groups, node) { seq_printf(s, " %s (%u)", pctlops->get_group_name(pctldev, grp->group_selector), @@ -1130,21 +1131,21 @@ static int pinmux_show(struct seq_file *s, void *what) seq_printf(s, " ]"); seq_printf(s, " users: %u map-> %s\n", - pmx->usecount, - pmx->dev ? dev_name(pmx->dev) : "(system)"); + p->usecount, + p->dev ? dev_name(p->dev) : "(system)"); } return 0; } -static int pinmux_maps_show(struct seq_file *s, void *what) +static int pinctrl_maps_show(struct seq_file *s, void *what) { int i; - seq_puts(s, "Pinmux maps:\n"); + seq_puts(s, "Pinctrl maps:\n"); - for (i = 0; i < pinmux_maps_num; i++) { - struct pinmux_map const *map = &pinmux_maps[i]; + for (i = 0; i < pinctrl_maps_num; i++) { + struct pinctrl_map const *map = &pinctrl_maps[i]; seq_printf(s, "%s:\n", map->name); if (map->dev_name) @@ -1181,9 +1182,9 @@ static int pinmux_open(struct inode *inode, struct file *file) return single_open(file, pinmux_show, NULL); } -static int pinmux_maps_open(struct inode *inode, struct file *file) +static int pinctrl_maps_open(struct inode *inode, struct file *file) { - return single_open(file, pinmux_maps_show, NULL); + return single_open(file, pinctrl_maps_show, NULL); } static const struct file_operations pinmux_functions_ops = { @@ -1214,8 +1215,8 @@ static const struct file_operations pinmux_ops = { .release = single_release, }; -static const struct file_operations pinmux_maps_ops = { - .open = pinmux_maps_open, +static const struct file_operations pinctrl_maps_ops = { + .open = pinctrl_maps_open, .read = seq_read, .llseek = seq_lseek, .release = single_release, @@ -1236,8 +1237,8 @@ void pinmux_init_debugfs(struct dentry *subsys_root) { debugfs_create_file("pinmuxes", S_IFREG | S_IRUGO, subsys_root, NULL, &pinmux_ops); - debugfs_create_file("pinmux-maps", S_IFREG | S_IRUGO, - subsys_root, NULL, &pinmux_maps_ops); + debugfs_create_file("pinctrl-maps", S_IFREG | S_IRUGO, + subsys_root, NULL, &pinctrl_maps_ops); } #endif /* CONFIG_DEBUG_FS */ diff --git a/drivers/pinctrl/pinmux.h b/drivers/pinctrl/pinmux.h index 97f52223fbc2..dfe81726965c 100644 --- a/drivers/pinctrl/pinmux.h +++ b/drivers/pinctrl/pinmux.h @@ -16,8 +16,8 @@ int pinmux_check_ops(struct pinctrl_dev *pctldev); void pinmux_init_device_debugfs(struct dentry *devroot, struct pinctrl_dev *pctldev); void pinmux_init_debugfs(struct dentry *subsys_root); -int pinmux_hog_maps(struct pinctrl_dev *pctldev); -void pinmux_unhog_maps(struct pinctrl_dev *pctldev); +int pinctrl_hog_maps(struct pinctrl_dev *pctldev); +void pinctrl_unhog_maps(struct pinctrl_dev *pctldev); #else @@ -35,12 +35,12 @@ static inline void pinmux_init_debugfs(struct dentry *subsys_root) { } -static inline int pinmux_hog_maps(struct pinctrl_dev *pctldev) +static inline int pinctrl_hog_maps(struct pinctrl_dev *pctldev) { return 0; } -static inline void pinmux_unhog_maps(struct pinctrl_dev *pctldev) +static inline void pinctrl_unhog_maps(struct pinctrl_dev *pctldev) { } diff --git a/include/linux/pinctrl/consumer.h b/include/linux/pinctrl/consumer.h index 9c8513d5d0fb..c7d061776293 100644 --- a/include/linux/pinctrl/consumer.h +++ b/include/linux/pinctrl/consumer.h @@ -17,56 +17,56 @@ #include "pinctrl.h" /* This struct is private to the core and should be regarded as a cookie */ -struct pinmux; +struct pinctrl; #ifdef CONFIG_PINMUX /* External interface to pinmux */ -extern int pinmux_request_gpio(unsigned gpio); -extern void pinmux_free_gpio(unsigned gpio); -extern int pinmux_gpio_direction_input(unsigned gpio); -extern int pinmux_gpio_direction_output(unsigned gpio); -extern struct pinmux * __must_check pinmux_get(struct device *dev, const char *name); -extern void pinmux_put(struct pinmux *pmx); -extern int pinmux_enable(struct pinmux *pmx); -extern void pinmux_disable(struct pinmux *pmx); +extern int pinctrl_request_gpio(unsigned gpio); +extern void pinctrl_free_gpio(unsigned gpio); +extern int pinctrl_gpio_direction_input(unsigned gpio); +extern int pinctrl_gpio_direction_output(unsigned gpio); +extern struct pinctrl * __must_check pinctrl_get(struct device *dev, const char *name); +extern void pinctrl_put(struct pinctrl *p); +extern int pinctrl_enable(struct pinctrl *p); +extern void pinctrl_disable(struct pinctrl *p); #else /* !CONFIG_PINMUX */ -static inline int pinmux_request_gpio(unsigned gpio) +static inline int pinctrl_request_gpio(unsigned gpio) { return 0; } -static inline void pinmux_free_gpio(unsigned gpio) +static inline void pinctrl_free_gpio(unsigned gpio) { } -static inline int pinmux_gpio_direction_input(unsigned gpio) +static inline int pinctrl_gpio_direction_input(unsigned gpio) { return 0; } -static inline int pinmux_gpio_direction_output(unsigned gpio) +static inline int pinctrl_gpio_direction_output(unsigned gpio) { return 0; } -static inline struct pinmux * __must_check pinmux_get(struct device *dev, const char *name) +static inline struct pinctrl * __must_check pinctrl_get(struct device *dev, const char *name) { return NULL; } -static inline void pinmux_put(struct pinmux *pmx) +static inline void pinctrl_put(struct pinctrl *p) { } -static inline int pinmux_enable(struct pinmux *pmx) +static inline int pinctrl_enable(struct pinctrl *p) { return 0; } -static inline void pinmux_disable(struct pinmux *pmx) +static inline void pinctrl_disable(struct pinctrl *p) { } diff --git a/include/linux/pinctrl/machine.h b/include/linux/pinctrl/machine.h index f8593fdc6466..a2ab524a0106 100644 --- a/include/linux/pinctrl/machine.h +++ b/include/linux/pinctrl/machine.h @@ -9,11 +9,11 @@ * * License terms: GNU General Public License (GPL) version 2 */ -#ifndef __LINUX_PINMUX_MACHINE_H -#define __LINUX_PINMUX_MACHINE_H +#ifndef __LINUX_PINCTRL_MACHINE_H +#define __LINUX_PINCTRL_MACHINE_H /** - * struct pinmux_map - boards/machines shall provide this map for devices + * struct pinctrl_map - boards/machines shall provide this map for devices * @name: the name of this specific map entry for the particular machine. * This is the second parameter passed to pinmux_get() when you want * to have several mappings to the same device @@ -34,7 +34,7 @@ * a pinmux device supporting it is registered. These maps will not be * disabled and put until the system shuts down. */ -struct pinmux_map { +struct pinctrl_map { const char *name; const char *ctrl_dev_name; const char *function; @@ -47,41 +47,41 @@ struct pinmux_map { * Convenience macro to set a simple map from a certain pin controller and a * certain function to a named device */ -#define PINMUX_MAP(a, b, c, d) \ +#define PIN_MAP(a, b, c, d) \ { .name = a, .ctrl_dev_name = b, .function = c, .dev_name = d } /* * Convenience macro to map a system function onto a certain pinctrl device. * System functions are not assigned to a particular device. */ -#define PINMUX_MAP_SYS(a, b, c) \ +#define PIN_MAP_SYS(a, b, c) \ { .name = a, .ctrl_dev_name = b, .function = c } /* * Convenience macro to map a system function onto a certain pinctrl device, - * to be hogged by the pinmux core until the system shuts down. + * to be hogged by the pin control core until the system shuts down. */ -#define PINMUX_MAP_SYS_HOG(a, b, c) \ +#define PIN_MAP_SYS_HOG(a, b, c) \ { .name = a, .ctrl_dev_name = b, .function = c, \ .hog_on_boot = true } /* * Convenience macro to map a system function onto a certain pinctrl device - * using a specified group, to be hogged by the pinmux core until the system - * shuts down. + * using a specified group, to be hogged by the pin control core until the + * system shuts down. */ -#define PINMUX_MAP_SYS_HOG_GROUP(a, b, c, d) \ +#define PIN_MAP_SYS_HOG_GROUP(a, b, c, d) \ { .name = a, .ctrl_dev_name = b, .function = c, .group = d, \ .hog_on_boot = true } #ifdef CONFIG_PINMUX -extern int pinmux_register_mappings(struct pinmux_map const *map, +extern int pinctrl_register_mappings(struct pinctrl_map const *map, unsigned num_maps); #else -static inline int pinmux_register_mappings(struct pinmux_map const *map, +static inline int pinctrl_register_mappings(struct pinctrl_map const *map, unsigned num_maps) { return 0; -- cgit v1.2.3 From 128a06d4bb997d90158e668173a6944d376c84cb Mon Sep 17 00:00:00 2001 From: Linus Walleij Date: Tue, 21 Feb 2012 14:31:45 +0100 Subject: pinctrl: spawn U300 pinctrl from the COH901 GPIO This solves the riddle on how the U300 pin controller shall be able to reference the struct gpio_chip even though these are two separate drivers: spawn the pinctrl child from the GPIO driver and pass in the struct gpio_chip as platform data. In the process we rename the U300 "pinmux-u300" to "pinctrl-u300" so as not to confuse. Signed-off-by: Linus Walleij --- arch/arm/mach-u300/core.c | 30 ++++++++++++++--------------- arch/arm/mach-u300/include/mach/gpio-u300.h | 2 ++ drivers/pinctrl/pinctrl-coh901.c | 10 ++++++++-- drivers/pinctrl/pinctrl-u300.c | 20 ++++++++++++------- 4 files changed, 38 insertions(+), 24 deletions(-) (limited to 'arch/arm/mach-u300') diff --git a/arch/arm/mach-u300/core.c b/arch/arm/mach-u300/core.c index bb1034f8c2f5..030b2c0d322d 100644 --- a/arch/arm/mach-u300/core.c +++ b/arch/arm/mach-u300/core.c @@ -1477,7 +1477,7 @@ static struct coh901318_platform coh901318_platform = { .max_channels = U300_DMA_CHANNELS, }; -static struct resource pinmux_resources[] = { +static struct resource pinctrl_resources[] = { { .start = U300_SYSCON_BASE, .end = U300_SYSCON_BASE + SZ_4K - 1, @@ -1506,6 +1506,13 @@ static struct platform_device i2c1_device = { .resource = i2c1_resources, }; +static struct platform_device pinctrl_device = { + .name = "pinctrl-u300", + .id = -1, + .num_resources = ARRAY_SIZE(pinctrl_resources), + .resource = pinctrl_resources, +}; + /* * The different variants have a few different versions of the * GPIO block, with different number of ports. @@ -1525,6 +1532,7 @@ static struct u300_gpio_platform u300_gpio_plat = { #endif .gpio_base = 0, .gpio_irq_base = IRQ_U300_GPIO_BASE, + .pinctrl_device = &pinctrl_device, }; static struct platform_device gpio_device = { @@ -1597,23 +1605,16 @@ static struct platform_device dma_device = { }, }; -static struct platform_device pinmux_device = { - .name = "pinmux-u300", - .id = -1, - .num_resources = ARRAY_SIZE(pinmux_resources), - .resource = pinmux_resources, -}; - /* Pinmux settings */ static struct pinctrl_map __initdata u300_pinmux_map[] = { /* anonymous maps for chip power and EMIFs */ - PIN_MAP_SYS_HOG("POWER", "pinmux-u300", "power"), - PIN_MAP_SYS_HOG("EMIF0", "pinmux-u300", "emif0"), - PIN_MAP_SYS_HOG("EMIF1", "pinmux-u300", "emif1"), + PIN_MAP_SYS_HOG("POWER", "pinctrl-u300", "power"), + PIN_MAP_SYS_HOG("EMIF0", "pinctrl-u300", "emif0"), + PIN_MAP_SYS_HOG("EMIF1", "pinctrl-u300", "emif1"), /* per-device maps for MMC/SD, SPI and UART */ - PIN_MAP("MMCSD", "pinmux-u300", "mmc0", "mmci"), - PIN_MAP("SPI", "pinmux-u300", "spi0", "pl022"), - PIN_MAP("UART0", "pinmux-u300", "uart0", "uart0"), + PIN_MAP("MMCSD", "pinctrl-u300", "mmc0", "mmci"), + PIN_MAP("SPI", "pinctrl-u300", "spi0", "pl022"), + PIN_MAP("UART0", "pinctrl-u300", "uart0", "uart0"), }; struct u300_mux_hog { @@ -1676,7 +1677,6 @@ static struct platform_device *platform_devs[] __initdata = { &gpio_device, &nand_device, &wdog_device, - &pinmux_device, }; /* diff --git a/arch/arm/mach-u300/include/mach/gpio-u300.h b/arch/arm/mach-u300/include/mach/gpio-u300.h index bf4c7935aecd..e81400c1753a 100644 --- a/arch/arm/mach-u300/include/mach/gpio-u300.h +++ b/arch/arm/mach-u300/include/mach/gpio-u300.h @@ -24,12 +24,14 @@ enum u300_gpio_variant { * @ports: number of GPIO block ports * @gpio_base: first GPIO number for this block (use a free range) * @gpio_irq_base: first GPIO IRQ number for this block (use a free range) + * @pinctrl_device: pin control device to spawn as child */ struct u300_gpio_platform { enum u300_gpio_variant variant; u8 ports; int gpio_base; int gpio_irq_base; + struct platform_device *pinctrl_device; }; #endif /* __MACH_U300_GPIO_U300_H */ diff --git a/drivers/pinctrl/pinctrl-coh901.c b/drivers/pinctrl/pinctrl-coh901.c index eba232a46a82..b90c01144fea 100644 --- a/drivers/pinctrl/pinctrl-coh901.c +++ b/drivers/pinctrl/pinctrl-coh901.c @@ -705,7 +705,6 @@ static inline void u300_gpio_free_ports(struct u300_gpio *gpio) list_for_each_safe(p, n, &gpio->port_list) { port = list_entry(p, struct u300_gpio_port, node); list_del(&port->node); - free_irq(port->irq, port); kfree(port); } } @@ -861,10 +860,18 @@ static int __init u300_gpio_probe(struct platform_device *pdev) goto err_no_chip; } + /* Spawn pin controller device as child of the GPIO, pass gpio chip */ + plat->pinctrl_device->dev.platform_data = &gpio->chip; + err = platform_device_register(plat->pinctrl_device); + if (err) + goto err_no_pinctrl; + platform_set_drvdata(pdev, gpio); return 0; +err_no_pinctrl: + err = gpiochip_remove(&gpio->chip); err_no_chip: err_no_port: u300_gpio_free_ports(gpio); @@ -919,7 +926,6 @@ static struct platform_driver u300_gpio_driver = { .remove = __exit_p(u300_gpio_remove), }; - static int __init u300_gpio_init(void) { return platform_driver_probe(&u300_gpio_driver, u300_gpio_probe); diff --git a/drivers/pinctrl/pinctrl-u300.c b/drivers/pinctrl/pinctrl-u300.c index c8d02f1c2b5e..fc4a281caba5 100644 --- a/drivers/pinctrl/pinctrl-u300.c +++ b/drivers/pinctrl/pinctrl-u300.c @@ -162,7 +162,7 @@ #define U300_SYSCON_PMC4R_APP_MISC_16_APP_UART1_CTS 0x0100 #define U300_SYSCON_PMC4R_APP_MISC_16_EMIF_1_STATIC_CS5_N 0x0200 -#define DRIVER_NAME "pinmux-u300" +#define DRIVER_NAME "pinctrl-u300" /* * The DB3350 has 467 pads, I have enumerated the pads clockwise around the @@ -1053,13 +1053,16 @@ static struct pinctrl_desc u300_pmx_desc = { .owner = THIS_MODULE, }; -static int __init u300_pmx_probe(struct platform_device *pdev) +static int __devinit u300_pmx_probe(struct platform_device *pdev) { struct u300_pmx *upmx; struct resource *res; + struct gpio_chip *gpio_chip = dev_get_platdata(&pdev->dev); int ret; int i; + pr_err("U300 PMX PROBE\n"); + /* Create state holders etc for this driver */ upmx = devm_kzalloc(&pdev->dev, sizeof(*upmx), GFP_KERNEL); if (!upmx) @@ -1095,12 +1098,14 @@ static int __init u300_pmx_probe(struct platform_device *pdev) } /* We will handle a range of GPIO pins */ - for (i = 0; i < ARRAY_SIZE(u300_gpio_ranges); i++) + for (i = 0; i < ARRAY_SIZE(u300_gpio_ranges); i++) { + u300_gpio_ranges[i].gc = gpio_chip; pinctrl_add_gpio_range(upmx->pctl, &u300_gpio_ranges[i]); + } platform_set_drvdata(pdev, upmx); - dev_info(&pdev->dev, "initialized U300 pinmux driver\n"); + dev_info(&pdev->dev, "initialized U300 pin control driver\n"); return 0; @@ -1115,7 +1120,7 @@ out_no_resource: return ret; } -static int __exit u300_pmx_remove(struct platform_device *pdev) +static int __devexit u300_pmx_remove(struct platform_device *pdev) { struct u300_pmx *upmx = platform_get_drvdata(pdev); int i; @@ -1136,12 +1141,13 @@ static struct platform_driver u300_pmx_driver = { .name = DRIVER_NAME, .owner = THIS_MODULE, }, - .remove = __exit_p(u300_pmx_remove), + .probe = u300_pmx_probe, + .remove = __devexit_p(u300_pmx_remove), }; static int __init u300_pmx_init(void) { - return platform_driver_probe(&u300_pmx_driver, u300_pmx_probe); + return platform_driver_register(&u300_pmx_driver); } arch_initcall(u300_pmx_init); -- cgit v1.2.3 From 46919ae63d4820e76724beb655274ce143f0da0b Mon Sep 17 00:00:00 2001 From: Stephen Warren Date: Thu, 1 Mar 2012 18:48:32 -0700 Subject: pinctrl: introduce PINCTRL_STATE_DEFAULT, define hogs as that state This provides a single centralized name for the default state. Update PIN_MAP_* macros to use this state name, instead of requiring the user to pass a state name in. With this change, hog entries in the mapping table are defined as those with state name PINCTRL_STATE_DEFAULT, i.e. all entries have the same name. This interacts badly with the nested iteration over mapping table entries in pinctrl_hog_maps() and pinctrl_hog_map() which would now attempt to claim each hog mapping table entry multiple times. Replacing the custom hog code with a simple pinctrl_get()/pinctrl_enable(). Update documentation and mapping tables to use this. Signed-off-by: Stephen Warren Acked-by: Dong Aisheng Signed-off-by: Linus Walleij --- Documentation/pinctrl.txt | 8 +-- arch/arm/mach-u300/core.c | 6 +- drivers/pinctrl/core.c | 145 ++-------------------------------------- drivers/pinctrl/core.h | 4 +- include/linux/pinctrl/machine.h | 13 ++-- include/linux/pinctrl/pinctrl.h | 2 + 6 files changed, 26 insertions(+), 152 deletions(-) (limited to 'arch/arm/mach-u300') diff --git a/Documentation/pinctrl.txt b/Documentation/pinctrl.txt index 5e314cecab77..6fe3232e798e 100644 --- a/Documentation/pinctrl.txt +++ b/Documentation/pinctrl.txt @@ -814,7 +814,7 @@ it even more compact which assumes you want to use pinctrl-foo and position 0 for mapping, for example: static struct pinctrl_map __initdata mapping[] = { - PIN_MAP("I2CMAP", "pinctrl-foo", "i2c0", "foo-i2c.0"), + PIN_MAP(PINCTRL_STATE_DEFAULT, "pinctrl-foo", "i2c0", "foo-i2c.0"), }; @@ -930,7 +930,7 @@ foo_probe() /* Allocate a state holder named "state" etc */ struct pinctrl p; - p = pinctrl_get(&device, NULL); + p = pinctrl_get(&device, PINCTRL_STATE_DEFAULT); if IS_ERR(p) return PTR_ERR(p); pinctrl_enable(p); @@ -989,7 +989,7 @@ of the pin controller itself, like this: { .dev_name = "pinctrl-foo", - .name = "POWERMAP" + .name = PINCTRL_STATE_DEFAULT, .ctrl_dev_name = "pinctrl-foo", .function = "power_func", }, @@ -998,7 +998,7 @@ Since it may be common to request the core to hog a few always-applicable mux settings on the primary pin controller, there is a convenience macro for this: -PIN_MAP_PRIMARY_SYS_HOG("POWERMAP", "pinctrl-foo", "power_func") +PIN_MAP_SYS_HOG("pinctrl-foo", "power_func") This gives the exact same result as the above construction. diff --git a/arch/arm/mach-u300/core.c b/arch/arm/mach-u300/core.c index 030b2c0d322d..ea6c79076a91 100644 --- a/arch/arm/mach-u300/core.c +++ b/arch/arm/mach-u300/core.c @@ -1608,9 +1608,9 @@ static struct platform_device dma_device = { /* Pinmux settings */ static struct pinctrl_map __initdata u300_pinmux_map[] = { /* anonymous maps for chip power and EMIFs */ - PIN_MAP_SYS_HOG("POWER", "pinctrl-u300", "power"), - PIN_MAP_SYS_HOG("EMIF0", "pinctrl-u300", "emif0"), - PIN_MAP_SYS_HOG("EMIF1", "pinctrl-u300", "emif1"), + PIN_MAP_SYS_HOG("pinctrl-u300", "power"), + PIN_MAP_SYS_HOG("pinctrl-u300", "emif0"), + PIN_MAP_SYS_HOG("pinctrl-u300", "emif1"), /* per-device maps for MMC/SD, SPI and UART */ PIN_MAP("MMCSD", "pinctrl-u300", "mmc0", "mmci"), PIN_MAP("SPI", "pinctrl-u300", "spi0", "pl022"), diff --git a/drivers/pinctrl/core.c b/drivers/pinctrl/core.c index 376cede29662..f25307b0e00a 100644 --- a/drivers/pinctrl/core.c +++ b/drivers/pinctrl/core.c @@ -44,18 +44,6 @@ struct pinctrl_maps { unsigned num_maps; }; -/** - * struct pinctrl_hog - a list item to stash control hogs - * @node: pin control hog list node - * @map: map entry responsible for this hogging - * @pmx: the pin control hogged by this item - */ -struct pinctrl_hog { - struct list_head node; - struct pinctrl_map const *map; - struct pinctrl *p; -}; - /* Global list of pin control devices */ static DEFINE_MUTEX(pinctrldev_list_mutex); static LIST_HEAD(pinctrldev_list); @@ -702,103 +690,6 @@ int pinctrl_register_mappings(struct pinctrl_map const *maps, return 0; } -/* Hog a single map entry and add to the hoglist */ -static int pinctrl_hog_map(struct pinctrl_dev *pctldev, - struct pinctrl_map const *map) -{ - struct pinctrl_hog *hog; - struct pinctrl *p; - int ret; - - hog = kzalloc(sizeof(*hog), GFP_KERNEL); - if (!hog) { - dev_err(pctldev->dev, "failed to alloc struct pinctrl_hog\n"); - return -ENOMEM; - } - - p = pinctrl_get_locked(pctldev->dev, map->name); - if (IS_ERR(p)) { - kfree(hog); - dev_err(pctldev->dev, - "could not get the %s pin control mapping for hogging\n", - map->name); - return PTR_ERR(p); - } - - ret = pinctrl_enable(p); - if (ret) { - pinctrl_put(p); - kfree(hog); - dev_err(pctldev->dev, - "could not enable the %s pin control mapping for hogging\n", - map->name); - return ret; - } - - hog->map = map; - hog->p = p; - - dev_info(pctldev->dev, "hogged map %s, function %s\n", map->name, - map->function); - list_add_tail(&hog->node, &pctldev->pinctrl_hogs); - - return 0; -} - -/** - * pinctrl_hog_maps() - hog specific map entries on controller device - * @pctldev: the pin control device to hog entries on - * - * When the pin controllers are registered, there may be some specific pinmux - * map entries that need to be hogged, i.e. get+enabled until the system shuts - * down. - */ -static int pinctrl_hog_maps(struct pinctrl_dev *pctldev) -{ - struct device *dev = pctldev->dev; - const char *devname = dev_name(dev); - int ret; - struct pinctrl_maps *maps_node; - int i; - struct pinctrl_map const *map; - - INIT_LIST_HEAD(&pctldev->pinctrl_hogs); - - mutex_lock(&pinctrl_maps_mutex); - for_each_maps(maps_node, i, map) { - if (!strcmp(map->ctrl_dev_name, devname) && - !strcmp(map->dev_name, devname)) { - /* OK time to hog! */ - ret = pinctrl_hog_map(pctldev, map); - if (ret) { - mutex_unlock(&pinctrl_maps_mutex); - return ret; - } - } - } - mutex_unlock(&pinctrl_maps_mutex); - - return 0; -} - -/** - * pinctrl_unhog_maps() - unhog specific map entries on controller device - * @pctldev: the pin control device to unhog entries on - */ -static void pinctrl_unhog_maps(struct pinctrl_dev *pctldev) -{ - struct list_head *node, *tmp; - - list_for_each_safe(node, tmp, &pctldev->pinctrl_hogs) { - struct pinctrl_hog *hog = - list_entry(node, struct pinctrl_hog, node); - pinctrl_disable(hog->p); - pinctrl_put(hog->p); - list_del(node); - kfree(hog); - } -} - #ifdef CONFIG_DEBUG_FS static int pinctrl_pins_show(struct seq_file *s, void *what) @@ -889,19 +780,6 @@ static int pinctrl_gpioranges_show(struct seq_file *s, void *what) return 0; } -static int pinmux_hogs_show(struct seq_file *s, void *what) -{ - struct pinctrl_dev *pctldev = s->private; - struct pinctrl_hog *hog; - - seq_puts(s, "Pin control map hogs held by device\n"); - - list_for_each_entry(hog, &pctldev->pinctrl_hogs, node) - seq_printf(s, "%s\n", hog->map->name); - - return 0; -} - static int pinctrl_devices_show(struct seq_file *s, void *what) { struct pinctrl_dev *pctldev; @@ -988,11 +866,6 @@ static int pinctrl_gpioranges_open(struct inode *inode, struct file *file) return single_open(file, pinctrl_gpioranges_show, inode->i_private); } -static int pinmux_hogs_open(struct inode *inode, struct file *file) -{ - return single_open(file, pinmux_hogs_show, inode->i_private); -} - static int pinctrl_devices_open(struct inode *inode, struct file *file) { return single_open(file, pinctrl_devices_show, NULL); @@ -1029,13 +902,6 @@ static const struct file_operations pinctrl_gpioranges_ops = { .release = single_release, }; -static const struct file_operations pinmux_hogs_ops = { - .open = pinmux_hogs_open, - .read = seq_read, - .llseek = seq_lseek, - .release = single_release, -}; - static const struct file_operations pinctrl_devices_ops = { .open = pinctrl_devices_open, .read = seq_read, @@ -1078,8 +944,6 @@ static void pinctrl_init_device_debugfs(struct pinctrl_dev *pctldev) device_root, pctldev, &pinctrl_groups_ops); debugfs_create_file("gpio-ranges", S_IFREG | S_IRUGO, device_root, pctldev, &pinctrl_gpioranges_ops); - debugfs_create_file("pinmux-hogs", S_IFREG | S_IRUGO, - device_root, pctldev, &pinmux_hogs_ops); pinmux_init_device_debugfs(device_root, pctldev); pinconf_init_device_debugfs(device_root, pctldev); } @@ -1188,7 +1052,9 @@ struct pinctrl_dev *pinctrl_register(struct pinctrl_desc *pctldesc, mutex_lock(&pinctrldev_list_mutex); list_add_tail(&pctldev->node, &pinctrldev_list); mutex_unlock(&pinctrldev_list_mutex); - pinctrl_hog_maps(pctldev); + pctldev->p = pinctrl_get(pctldev->dev, PINCTRL_STATE_DEFAULT); + if (!IS_ERR(pctldev->p)) + pinctrl_enable(pctldev->p); pinctrl_init_device_debugfs(pctldev); return pctldev; @@ -1211,7 +1077,10 @@ void pinctrl_unregister(struct pinctrl_dev *pctldev) return; pinctrl_remove_device_debugfs(pctldev); - pinctrl_unhog_maps(pctldev); + if (!IS_ERR(pctldev->p)) { + pinctrl_disable(pctldev->p); + pinctrl_put(pctldev->p); + } /* TODO: check that no pinmuxes are still active? */ mutex_lock(&pinctrldev_list_mutex); list_del(&pctldev->node); diff --git a/drivers/pinctrl/core.h b/drivers/pinctrl/core.h index 8164e7b4182b..97f8124b4381 100644 --- a/drivers/pinctrl/core.h +++ b/drivers/pinctrl/core.h @@ -27,7 +27,7 @@ struct pinctrl_gpio_range; * @owner: module providing the pin controller, used for refcounting * @driver_data: driver data for drivers registering to the pin controller * subsystem - * @pinctrl_hogs: list of pin control maps hogged by this device + * @p: result of pinctrl_get() for this device * @device_root: debugfs root for this device */ struct pinctrl_dev { @@ -39,7 +39,7 @@ struct pinctrl_dev { struct device *dev; struct module *owner; void *driver_data; - struct list_head pinctrl_hogs; + struct pinctrl *p; #ifdef CONFIG_DEBUG_FS struct dentry *device_root; #endif diff --git a/include/linux/pinctrl/machine.h b/include/linux/pinctrl/machine.h index 73fbb2745301..20e97353d5f9 100644 --- a/include/linux/pinctrl/machine.h +++ b/include/linux/pinctrl/machine.h @@ -12,6 +12,8 @@ #ifndef __LINUX_PINCTRL_MACHINE_H #define __LINUX_PINCTRL_MACHINE_H +#include "pinctrl.h" + /** * struct pinctrl_map - boards/machines shall provide this map for devices * @dev_name: the name of the device using this specific mapping, the name @@ -49,17 +51,18 @@ struct pinctrl_map { * Convenience macro to map a system function onto a certain pinctrl device, * to be hogged by the pin control core until the system shuts down. */ -#define PIN_MAP_SYS_HOG(a, b, c) \ - { .name = a, .ctrl_dev_name = b, .dev_name = b, .function = c, } +#define PIN_MAP_SYS_HOG(a, b) \ + { .name = PINCTRL_STATE_DEFAULT, .ctrl_dev_name = a, .dev_name = a, \ + .function = b, } /* * Convenience macro to map a system function onto a certain pinctrl device * using a specified group, to be hogged by the pin control core until the * system shuts down. */ -#define PIN_MAP_SYS_HOG_GROUP(a, b, c, d) \ - { .name = a, .ctrl_dev_name = b, .dev_name = b, .function = c, \ - .group = d, } +#define PIN_MAP_SYS_HOG_GROUP(a, b, c) \ + { .name = PINCTRL_STATE_DEFAULT, .ctrl_dev_name = a, .dev_name = a, \ + .function = b, .group = c, } #ifdef CONFIG_PINMUX diff --git a/include/linux/pinctrl/pinctrl.h b/include/linux/pinctrl/pinctrl.h index 8bd22ee7aa09..411fe232adf1 100644 --- a/include/linux/pinctrl/pinctrl.h +++ b/include/linux/pinctrl/pinctrl.h @@ -19,6 +19,8 @@ #include #include +#define PINCTRL_STATE_DEFAULT "default" + struct pinctrl_dev; struct pinmux_ops; struct pinconf_ops; -- cgit v1.2.3 From 110e4ec5a1cfe20190e7f8c2b8b4eef369de3c99 Mon Sep 17 00:00:00 2001 From: Stephen Warren Date: Thu, 1 Mar 2012 18:48:33 -0700 Subject: pinctrl: assume map table entries can't have a NULL name field pinctrl_register_mappings() already requires that every mapping table entry have a non-NULL name field. Logically, this makes sense too; drivers should always request a specific named state so they know what they're getting. Relying on getting the first mentioned state in the mapping table is error-prone, and a nasty special case to implement, given that a given the mapping table may define multiple states for a device. Remove a small part of the documentation that talked about optionally requesting a specific state; it's mandatory now. Signed-off-by: Stephen Warren Acked-by: Dong Aisheng Signed-off-by: Linus Walleij --- Documentation/pinctrl.txt | 7 +++---- arch/arm/mach-u300/core.c | 8 ++++---- drivers/pinctrl/core.c | 17 +++++------------ drivers/tty/serial/sirfsoc_uart.c | 2 +- 4 files changed, 13 insertions(+), 21 deletions(-) (limited to 'arch/arm/mach-u300') diff --git a/Documentation/pinctrl.txt b/Documentation/pinctrl.txt index 6fe3232e798e..558aac554d09 100644 --- a/Documentation/pinctrl.txt +++ b/Documentation/pinctrl.txt @@ -782,16 +782,19 @@ spi on the second function mapping: static const struct pinctrl_map __initdata mapping[] = { { .dev_name = "foo-spi.0", + .name = PINCTRL_STATE_DEFAULT, .ctrl_dev_name = "pinctrl-foo", .function = "spi0", }, { .dev_name = "foo-i2c.0", + .name = PINCTRL_STATE_DEFAULT, .ctrl_dev_name = "pinctrl-foo", .function = "i2c0", }, { .dev_name = "foo-mmc.0", + .name = PINCTRL_STATE_DEFAULT, .ctrl_dev_name = "pinctrl-foo", .function = "mmc0", }, @@ -944,10 +947,6 @@ foo_remove() pinctrl_put(state->p); } -If you want to grab a specific control mapping and not just the first one -found for this device you can specify a specific mapping name, for example in -the above example the second i2c0 setting: pinctrl_get(&device, "spi0-pos-B"); - This get/enable/disable/put sequence can just as well be handled by bus drivers if you don't want each and every driver to handle it and you know the arrangement on your bus. diff --git a/arch/arm/mach-u300/core.c b/arch/arm/mach-u300/core.c index ea6c79076a91..f29565a10e2e 100644 --- a/arch/arm/mach-u300/core.c +++ b/arch/arm/mach-u300/core.c @@ -1612,9 +1612,9 @@ static struct pinctrl_map __initdata u300_pinmux_map[] = { PIN_MAP_SYS_HOG("pinctrl-u300", "emif0"), PIN_MAP_SYS_HOG("pinctrl-u300", "emif1"), /* per-device maps for MMC/SD, SPI and UART */ - PIN_MAP("MMCSD", "pinctrl-u300", "mmc0", "mmci"), - PIN_MAP("SPI", "pinctrl-u300", "spi0", "pl022"), - PIN_MAP("UART0", "pinctrl-u300", "uart0", "uart0"), + PIN_MAP(PINCTRL_STATE_DEFAULT, "pinctrl-u300", "mmc0", "mmci"), + PIN_MAP(PINCTRL_STATE_DEFAULT, "pinctrl-u300", "spi0", "pl022"), + PIN_MAP(PINCTRL_STATE_DEFAULT, "pinctrl-u300", "uart0", "uart0"), }; struct u300_mux_hog { @@ -1646,7 +1646,7 @@ static int __init u300_pinctrl_fetch(void) struct pinctrl *p; int ret; - p = pinctrl_get(u300_mux_hogs[i].dev, NULL); + p = pinctrl_get(u300_mux_hogs[i].dev, PINCTRL_STATE_DEFAULT); if (IS_ERR(p)) { pr_err("u300: could not get pinmux hog %s\n", u300_mux_hogs[i].name); diff --git a/drivers/pinctrl/core.c b/drivers/pinctrl/core.c index f25307b0e00a..6af6d8d117df 100644 --- a/drivers/pinctrl/core.c +++ b/drivers/pinctrl/core.c @@ -461,8 +461,8 @@ static struct pinctrl *pinctrl_get_locked(struct device *dev, const char *name) int i; struct pinctrl_map const *map; - /* We must have a dev name */ - if (WARN_ON(!dev)) + /* We must have both a dev and state name */ + if (WARN_ON(!dev || !name)) return ERR_PTR(-EINVAL); devname = dev_name(dev); @@ -504,16 +504,9 @@ static struct pinctrl *pinctrl_get_locked(struct device *dev, const char *name) if (strcmp(map->dev_name, devname)) continue; - /* - * If we're looking for a specific named map, this must match, - * else we loop and look for the next. - */ - if (name != NULL) { - if (map->name == NULL) - continue; - if (strcmp(map->name, name)) - continue; - } + /* State name must be the one we're looking for */ + if (strcmp(map->name, name)) + continue; ret = pinmux_apply_muxmap(pctldev, p, dev, devname, map); if (ret) { diff --git a/drivers/tty/serial/sirfsoc_uart.c b/drivers/tty/serial/sirfsoc_uart.c index c1a871eac450..3cabb650a1c1 100644 --- a/drivers/tty/serial/sirfsoc_uart.c +++ b/drivers/tty/serial/sirfsoc_uart.c @@ -673,7 +673,7 @@ int sirfsoc_uart_probe(struct platform_device *pdev) port->irq = res->start; if (sirfport->hw_flow_ctrl) { - sirfport->p = pinctrl_get(&pdev->dev, NULL); + sirfport->p = pinctrl_get(&pdev->dev, PINCTRL_STATE_DEFAULT); ret = IS_ERR(sirfport->p); if (ret) goto pin_err; -- cgit v1.2.3 From 6e5e959dde0d92d177f035652aeaa77f9330c9c6 Mon Sep 17 00:00:00 2001 From: Stephen Warren Date: Fri, 2 Mar 2012 13:05:47 -0700 Subject: pinctrl: API changes to support multiple states per device The API model is changed from: p = pinctrl_get(dev, "state1"); pinctrl_enable(p); ... pinctrl_disable(p); pinctrl_put(p); p = pinctrl_get(dev, "state2"); pinctrl_enable(p); ... pinctrl_disable(p); pinctrl_put(p); to this: p = pinctrl_get(dev); s1 = pinctrl_lookup_state(p, "state1"); s2 = pinctrl_lookup_state(p, "state2"); pinctrl_select_state(p, s1); ... pinctrl_select_state(p, s2); ... pinctrl_put(p); This allows devices to directly transition between states without disabling the pin controller programming and put()/get()ing the configuration data each time. This model will also better suit pinconf programming, which doesn't have a concept of "disable". The special-case hogging feature of pin controllers is re-written to use the regular APIs instead of special-case code. Hence, the pinmux-hogs debugfs file is removed; see the top-level pinctrl-handles files for equivalent data. Signed-off-by: Stephen Warren Acked-by: Dong Aisheng Signed-off-by: Linus Walleij --- Documentation/pinctrl.txt | 120 ++++++++----- arch/arm/mach-u300/core.c | 16 +- drivers/pinctrl/core.c | 363 +++++++++++++++++++++++--------------- drivers/pinctrl/core.h | 23 ++- drivers/tty/serial/sirfsoc_uart.c | 12 +- include/linux/pinctrl/consumer.h | 55 +++++- include/linux/pinctrl/machine.h | 11 +- 7 files changed, 375 insertions(+), 225 deletions(-) (limited to 'arch/arm/mach-u300') diff --git a/Documentation/pinctrl.txt b/Documentation/pinctrl.txt index 558aac554d09..23426c7bc8dc 100644 --- a/Documentation/pinctrl.txt +++ b/Documentation/pinctrl.txt @@ -847,8 +847,8 @@ As it is possible to map a function to different groups of pins an optional This example mapping is used to switch between two positions for spi0 at runtime, as described further below under the heading "Runtime pinmuxing". -Further it is possible to match several groups of pins to the same function -for a single device, say for example in the mmc0 example above, where you can +Further it is possible for one named state to affect the muxing of several +groups of pins, say for example in the mmc0 example above, where you can additively expand the mmc0 bus from 2 to 4 to 8 pins. If we want to use all three groups for a total of 2+2+4 = 8 pins (for an 8-bit MMC bus as is the case), we define a mapping like this: @@ -879,6 +879,7 @@ case), we define a mapping like this: .dev_name = "foo-mmc.0", .name = "8bit" .ctrl_dev_name = "pinctrl-foo", + .function = "mmc0", .group = "mmc0_1_grp", }, { @@ -900,10 +901,16 @@ case), we define a mapping like this: The result of grabbing this mapping from the device with something like this (see next paragraph): - p = pinctrl_get(&device, "8bit"); + p = pinctrl_get(dev); + s = pinctrl_lookup_state(p, "8bit"); + ret = pinctrl_select_state(p, s); + +or more simply: + + p = pinctrl_get_select(dev, "8bit"); Will be that you activate all the three bottom records in the mapping at -once. Since they share the same name, pin controller device, funcion and +once. Since they share the same name, pin controller device, function and device, and since we allow multiple groups to match to a single device, they all get selected, and they all get enabled and disable simultaneously by the pinmux core. @@ -925,45 +932,63 @@ default state like this: struct foo_state { struct pinctrl *p; + struct pinctrl_state *s; ... }; foo_probe() { - /* Allocate a state holder named "state" etc */ - struct pinctrl p; + /* Allocate a state holder named "foo" etc */ + struct foo_state *foo = ...; + + foo->p = pinctrl_get(&device); + if (IS_ERR(foo->p)) { + /* FIXME: clean up "foo" here */ + return PTR_ERR(foo->p); + } - p = pinctrl_get(&device, PINCTRL_STATE_DEFAULT); - if IS_ERR(p) - return PTR_ERR(p); - pinctrl_enable(p); + foo->s = pinctrl_lookup_state(foo->p, PINCTRL_STATE_DEFAULT); + if (IS_ERR(foo->s)) { + pinctrl_put(foo->p); + /* FIXME: clean up "foo" here */ + return PTR_ERR(s); + } - state->p = p; + ret = pinctrl_select_state(foo->s); + if (ret < 0) { + pinctrl_put(foo->p); + /* FIXME: clean up "foo" here */ + return ret; + } } foo_remove() { - pinctrl_disable(state->p); pinctrl_put(state->p); } -This get/enable/disable/put sequence can just as well be handled by bus drivers +This get/lookup/select/put sequence can just as well be handled by bus drivers if you don't want each and every driver to handle it and you know the arrangement on your bus. -The semantics of the get/enable respective disable/put is as follows: +The semantics of the pinctrl APIs are: + +- pinctrl_get() is called in process context to obtain a handle to all pinctrl + information for a given client device. It will allocate a struct from the + kernel memory to hold the pinmux state. All mapping table parsing or similar + slow operations take place within this API. -- pinctrl_get() is called in process context to reserve the pins affected with - a certain mapping and set up the pinmux core and the driver. It will allocate - a struct from the kernel memory to hold the pinmux state. +- pinctrl_lookup_state() is called in process context to obtain a handle to a + specific state for a the client device. This operation may be slow too. -- pinctrl_enable()/pinctrl_disable() is quick and can be called from fastpath - (irq context) when you quickly want to set up/tear down the hardware muxing - when running a device driver. Usually it will just poke some values into a - register. +- pinctrl_select_state() programs pin controller hardware according to the + definition of the state as given by the mapping table. In theory this is a + fast-path operation, since it only involved blasting some register settings + into hardware. However, note that some pin controllers may have their + registers on a slow/IRQ-based bus, so client devices should not assume they + can call pinctrl_select_state() from non-blocking contexts. -- pinctrl_disable() is called in process context to tear down the pin requests - and release the state holder struct for the mux setting etc. +- pinctrl_put() frees all information associated with a pinctrl handle. Usually the pin control core handled the get/put pair and call out to the device drivers bookkeeping operations, like checking available functions and @@ -979,12 +1004,12 @@ System pin control hogging ========================== Pin control map entries can be hogged by the core when the pin controller -is registered. This means that the core will attempt to call pinctrl_get() and -pinctrl_enable() on it immediately after the pin control device has been -registered. +is registered. This means that the core will attempt to call pinctrl_get(), +lookup_state() and select_state() on it immediately after the pin control +device has been registered. -This is enabled by simply setting the .dev_name field in the map to the name -of the pin controller itself, like this: +This occurs for mapping table entries where the client device name is equal +to the pin controller device name, and the state name is PINCTRL_STATE_DEFAULT. { .dev_name = "pinctrl-foo", @@ -1009,8 +1034,8 @@ It is possible to mux a certain function in and out at runtime, say to move an SPI port from one set of pins to another set of pins. Say for example for spi0 in the example above, we expose two different groups of pins for the same function, but with different named in the mapping as described under -"Advanced mapping" above. So we have two mappings named "spi0-pos-A" and -"spi0-pos-B". +"Advanced mapping" above. So that for an SPI device, we have two states named +"pos-A" and "pos-B". This snippet first muxes the function in the pins defined by group A, enables it, disables and releases it, and muxes it in on the pins defined by group B: @@ -1020,23 +1045,36 @@ it, disables and releases it, and muxes it in on the pins defined by group B: foo_switch() { struct pinctrl *p; + struct pinctrl_state *s1, *s2; + + /* Setup */ + p = pinctrl_get(&device); + if (IS_ERR(p)) + ... + + s1 = pinctrl_lookup_state(foo->p, "pos-A"); + if (IS_ERR(s1)) + ... + + s2 = pinctrl_lookup_state(foo->p, "pos-B"); + if (IS_ERR(s2)) + ... /* Enable on position A */ - p = pinctrl_get(&device, "spi0-pos-A"); - if IS_ERR(p) - return PTR_ERR(p); - pinctrl_enable(p); + ret = pinctrl_select_state(s1); + if (ret < 0) + ... - /* This releases the pins again */ - pinctrl_disable(p); - pinctrl_put(p); + ... /* Enable on position B */ - p = pinctrl_get(&device, "spi0-pos-B"); - if IS_ERR(p) - return PTR_ERR(p); - pinctrl_enable(p); + ret = pinctrl_select_state(s2); + if (ret < 0) + ... + ... + + pinctrl_put(p); } The above has to be done from process context. diff --git a/arch/arm/mach-u300/core.c b/arch/arm/mach-u300/core.c index f29565a10e2e..c092cf92e8ea 100644 --- a/arch/arm/mach-u300/core.c +++ b/arch/arm/mach-u300/core.c @@ -1618,22 +1618,18 @@ static struct pinctrl_map __initdata u300_pinmux_map[] = { }; struct u300_mux_hog { - const char *name; struct device *dev; struct pinctrl *p; }; static struct u300_mux_hog u300_mux_hogs[] = { { - .name = "uart0", .dev = &uart0_device.dev, }, { - .name = "spi0", .dev = &pl022_device.dev, }, { - .name = "mmc0", .dev = &mmcsd_device.dev, }, }; @@ -1646,16 +1642,10 @@ static int __init u300_pinctrl_fetch(void) struct pinctrl *p; int ret; - p = pinctrl_get(u300_mux_hogs[i].dev, PINCTRL_STATE_DEFAULT); + p = pinctrl_get_select_default(u300_mux_hogs[i].dev); if (IS_ERR(p)) { - pr_err("u300: could not get pinmux hog %s\n", - u300_mux_hogs[i].name); - continue; - } - ret = pinctrl_enable(p); - if (ret) { - pr_err("u300: could enable pinmux hog %s\n", - u300_mux_hogs[i].name); + pr_err("u300: could not get pinmux hog for dev %s\n", + dev_name(u300_mux_hogs[i].dev)); continue; } u300_mux_hogs[i].p = p; diff --git a/drivers/pinctrl/core.c b/drivers/pinctrl/core.c index 535f8d53c289..c6f3ca32189e 100644 --- a/drivers/pinctrl/core.c +++ b/drivers/pinctrl/core.c @@ -458,25 +458,98 @@ int pinctrl_gpio_direction_output(unsigned gpio) } EXPORT_SYMBOL_GPL(pinctrl_gpio_direction_output); -static struct pinctrl *pinctrl_get_locked(struct device *dev, const char *name) +static struct pinctrl_state *find_state(struct pinctrl *p, + const char *name) { - struct pinctrl_dev *pctldev; - const char *devname; - struct pinctrl *p; - unsigned num_maps = 0; - int ret; - struct pinctrl_maps *maps_node; - int i; - struct pinctrl_map const *map; + struct pinctrl_state *state; + + list_for_each_entry(state, &p->states, node) + if (!strcmp(state->name, name)) + return state; + + return NULL; +} + +static struct pinctrl_state *create_state(struct pinctrl *p, + const char *name) +{ + struct pinctrl_state *state; + + state = kzalloc(sizeof(*state), GFP_KERNEL); + if (state == NULL) { + dev_err(p->dev, + "failed to alloc struct pinctrl_state\n"); + return ERR_PTR(-ENOMEM); + } + + state->name = name; + INIT_LIST_HEAD(&state->settings); + + list_add_tail(&state->node, &p->states); + + return state; +} + +static int add_setting(struct pinctrl *p, struct pinctrl_map const *map) +{ + struct pinctrl_state *state; struct pinctrl_setting *setting; + int ret; - /* We must have both a dev and state name */ - if (WARN_ON(!dev || !name)) - return ERR_PTR(-EINVAL); + state = find_state(p, map->name); + if (!state) + state = create_state(p, map->name); + if (IS_ERR(state)) + return PTR_ERR(state); - devname = dev_name(dev); + setting = kzalloc(sizeof(*setting), GFP_KERNEL); + if (setting == NULL) { + dev_err(p->dev, + "failed to alloc struct pinctrl_setting\n"); + return -ENOMEM; + } - dev_dbg(dev, "pinctrl_get() for device %s state %s\n", devname, name); + setting->pctldev = get_pinctrl_dev_from_devname(map->ctrl_dev_name); + if (setting->pctldev == NULL) { + dev_err(p->dev, "unknown pinctrl device %s in map entry", + map->ctrl_dev_name); + kfree(setting); + /* Eventually, this should trigger deferred probe */ + return -ENODEV; + } + + ret = pinmux_map_to_setting(map, setting); + if (ret < 0) { + kfree(setting); + return ret; + } + + list_add_tail(&setting->node, &state->settings); + + return 0; +} + +static struct pinctrl *find_pinctrl(struct device *dev) +{ + struct pinctrl *p; + + list_for_each_entry(p, &pinctrldev_list, node) + if (p->dev == dev) + return p; + + return NULL; +} + +static void pinctrl_put_locked(struct pinctrl *p, bool inlist); + +static struct pinctrl *create_pinctrl(struct device *dev) +{ + struct pinctrl *p; + const char *devname; + struct pinctrl_maps *maps_node; + int i; + struct pinctrl_map const *map; + int ret; /* * create the state cookie holder struct pinctrl for each @@ -489,8 +562,9 @@ static struct pinctrl *pinctrl_get_locked(struct device *dev, const char *name) return ERR_PTR(-ENOMEM); } p->dev = dev; - p->state = name; - INIT_LIST_HEAD(&p->settings); + INIT_LIST_HEAD(&p->states); + + devname = dev_name(dev); /* Iterate over the pin control maps to locate the right ones */ for_each_maps(maps_node, i, map) { @@ -498,183 +572,179 @@ static struct pinctrl *pinctrl_get_locked(struct device *dev, const char *name) if (strcmp(map->dev_name, devname)) continue; - /* State name must be the one we're looking for */ - if (strcmp(map->name, name)) - continue; - - /* - * Try to find the pctldev given in the map - */ - pctldev = get_pinctrl_dev_from_devname(map->ctrl_dev_name); - if (!pctldev) { - dev_err(dev, "unknown pinctrl device %s in map entry", - map->ctrl_dev_name); - /* Eventually, this should trigger deferred probe */ - ret = -ENODEV; - goto error; - } - - dev_dbg(dev, "in map, found pctldev %s to handle function %s", - dev_name(pctldev->dev), map->function); - - setting = kzalloc(sizeof(*setting), GFP_KERNEL); - if (setting == NULL) { - dev_err(dev, - "failed to alloc struct pinctrl_setting\n"); - ret = -ENOMEM; - goto error; + ret = add_setting(p, map); + if (ret < 0) { + pinctrl_put_locked(p, false); + return ERR_PTR(ret); } - - setting->pctldev = pctldev; - ret = pinmux_map_to_setting(map, setting); - if (ret < 0) - goto error; - - list_add_tail(&setting->node, &p->settings); - - num_maps++; } - /* - * This may be perfectly legitimate. An IP block may get re-used - * across SoCs. Not all of those SoCs may need pinmux settings for the - * IP block, e.g. if one SoC dedicates pins to that function but - * another doesn't. The driver won't know this, and will always - * attempt to set up the pinmux. The mapping table defines whether any - * HW programming is actually needed. - */ - if (!num_maps) - dev_info(dev, "zero maps found for mapping %s\n", name); - - dev_dbg(dev, "found %u maps for device %s state %s\n", - num_maps, devname, name ? name : "(undefined)"); - /* Add the pinmux to the global list */ list_add_tail(&p->node, &pinctrl_list); return p; +} -error: - list_for_each_entry(setting, &p->settings, node) - pinmux_free_setting(setting); +static struct pinctrl *pinctrl_get_locked(struct device *dev) +{ + struct pinctrl *p; - kfree(p); + if (WARN_ON(!dev)) + return ERR_PTR(-EINVAL); + + p = find_pinctrl(dev); + if (p != NULL) + return ERR_PTR(-EBUSY); - return ERR_PTR(ret); + p = create_pinctrl(dev); + if (IS_ERR(p)) + return p; + + return p; } /** - * pinctrl_get() - retrieves the pin controller handle for a certain device - * @dev: the device to get the pin controller handle for - * @name: an optional specific control mapping name or NULL, the name is only - * needed if you want to have more than one mapping per device, or if you - * need an anonymous pin control (not tied to any specific device) + * pinctrl_get() - retrieves the pinctrl handle for a device + * @dev: the device to obtain the handle for */ -struct pinctrl *pinctrl_get(struct device *dev, const char *name) +struct pinctrl *pinctrl_get(struct device *dev) { struct pinctrl *p; mutex_lock(&pinctrl_mutex); - p = pinctrl_get_locked(dev, name); + p = pinctrl_get_locked(dev); mutex_unlock(&pinctrl_mutex); return p; } EXPORT_SYMBOL_GPL(pinctrl_get); -static void pinctrl_put_locked(struct pinctrl *p) +static void pinctrl_put_locked(struct pinctrl *p, bool inlist) { - struct pinctrl_setting *setting, *n; - - if (p == NULL) - return; - - if (p->usecount) - pr_warn("releasing pin control handle with active users!\n"); - list_for_each_entry_safe(setting, n, &p->settings, node) { - pinmux_free_setting(setting); - list_del(&setting->node); - kfree(setting); + struct pinctrl_state *state, *n1; + struct pinctrl_setting *setting, *n2; + + list_for_each_entry_safe(state, n1, &p->states, node) { + list_for_each_entry_safe(setting, n2, &state->settings, node) { + if (state == p->state) + pinmux_disable_setting(setting); + pinmux_free_setting(setting); + list_del(&setting->node); + kfree(setting); + } + list_del(&state->node); + kfree(state); } - /* Remove from list */ - list_del(&p->node); - + if (inlist) + list_del(&p->node); kfree(p); } /** - * pinctrl_put() - release a previously claimed pin control handle - * @p: a pin control handle previously claimed by pinctrl_get() + * pinctrl_put() - release a previously claimed pinctrl handle + * @p: the pinctrl handle to release */ void pinctrl_put(struct pinctrl *p) { mutex_lock(&pinctrl_mutex); - pinctrl_put(p); + pinctrl_put_locked(p, true); mutex_unlock(&pinctrl_mutex); } EXPORT_SYMBOL_GPL(pinctrl_put); -static int pinctrl_enable_locked(struct pinctrl *p) +static struct pinctrl_state *pinctrl_lookup_state_locked(struct pinctrl *p, + const char *name) { - struct pinctrl_setting *setting; - int ret; + struct pinctrl_state *state; - if (p == NULL) - return -EINVAL; + state = find_state(p, name); + if (!state) + return ERR_PTR(-ENODEV); - if (p->usecount++ == 0) { - list_for_each_entry(setting, &p->settings, node) { - ret = pinmux_enable_setting(setting); - if (ret < 0) { - /* FIXME: Difficult to return to prev state */ - p->usecount--; - return ret; - } - } - } - - return 0; + return state; } /** - * pinctrl_enable() - enable a certain pin controller setting - * @p: the pin control handle to enable, previously claimed by pinctrl_get() + * pinctrl_lookup_state() - retrieves a state handle from a pinctrl handle + * @p: the pinctrl handle to retrieve the state from + * @name: the state name to retrieve */ -int pinctrl_enable(struct pinctrl *p) +struct pinctrl_state *pinctrl_lookup_state(struct pinctrl *p, const char *name) { - int ret; + struct pinctrl_state *s; + mutex_lock(&pinctrl_mutex); - ret = pinctrl_enable_locked(p); + s = pinctrl_lookup_state_locked(p, name); mutex_unlock(&pinctrl_mutex); - return ret; + + return s; } -EXPORT_SYMBOL_GPL(pinctrl_enable); +EXPORT_SYMBOL_GPL(pinctrl_lookup_state); -static void pinctrl_disable_locked(struct pinctrl *p) +static int pinctrl_select_state_locked(struct pinctrl *p, + struct pinctrl_state *state) { - struct pinctrl_setting *setting; + struct pinctrl_setting *setting, *setting2; + int ret; - if (p == NULL) - return; + if (p->state == state) + return 0; - if (--p->usecount == 0) { - list_for_each_entry(setting, &p->settings, node) - pinmux_disable_setting(setting); + if (p->state) { + /* + * The set of groups with a mux configuration in the old state + * may not be identical to the set of groups with a mux setting + * in the new state. While this might be unusual, it's entirely + * possible for the "user"-supplied mapping table to be written + * that way. For each group that was configured in the old state + * but not in the new state, this code puts that group into a + * safe/disabled state. + */ + list_for_each_entry(setting, &p->state->settings, node) { + bool found = false; + list_for_each_entry(setting2, &state->settings, node) { + if (setting2->group_selector == + setting->group_selector) { + found = true; + break; + } + } + if (!found) + pinmux_disable_setting(setting); + } + } + + p->state = state; + + /* Apply all the settings for the new state */ + list_for_each_entry(setting, &state->settings, node) { + ret = pinmux_enable_setting(setting); + if (ret < 0) { + /* FIXME: Difficult to return to prev state */ + return ret; + } } + + return 0; } /** - * pinctrl_disable() - disable a certain pin control setting - * @p: the pin control handle to disable, previously claimed by pinctrl_get() + * pinctrl_select() - select/activate/program a pinctrl state to HW + * @p: the pinctrl handle for the device that requests configuratio + * @state: the state handle to select/activate/program */ -void pinctrl_disable(struct pinctrl *p) +int pinctrl_select_state(struct pinctrl *p, struct pinctrl_state *state) { + int ret; + mutex_lock(&pinctrl_mutex); - pinctrl_disable_locked(p); + ret = pinctrl_select_state_locked(p, state); mutex_unlock(&pinctrl_mutex); + + return ret; } -EXPORT_SYMBOL_GPL(pinctrl_disable); +EXPORT_SYMBOL_GPL(pinctrl_select_state); /** * pinctrl_register_mappings() - register a set of pin controller mappings @@ -891,6 +961,7 @@ static int pinctrl_maps_show(struct seq_file *s, void *what) static int pinctrl_show(struct seq_file *s, void *what) { struct pinctrl *p; + struct pinctrl_state *state; struct pinctrl_setting *setting; seq_puts(s, "Requested pin control handlers their pinmux maps:\n"); @@ -898,12 +969,17 @@ static int pinctrl_show(struct seq_file *s, void *what) mutex_lock(&pinctrl_mutex); list_for_each_entry(p, &pinctrl_list, node) { - seq_printf(s, "device: %s state: %s users: %u\n", - dev_name(p->dev), p->state, p->usecount); + seq_printf(s, "device: %s current state: %s\n", + dev_name(p->dev), + p->state ? p->state->name : "none"); + + list_for_each_entry(state, &p->states, node) { + seq_printf(s, " state: %s\n", state->name); - list_for_each_entry(setting, &p->settings, node) { - seq_printf(s, " "); - pinmux_dbg_show(s, setting); + list_for_each_entry(setting, &state->settings, node) { + seq_printf(s, " "); + pinmux_dbg_show(s, setting); + } } } @@ -1113,9 +1189,14 @@ struct pinctrl_dev *pinctrl_register(struct pinctrl_desc *pctldesc, list_add_tail(&pctldev->node, &pinctrldev_list); - pctldev->p = pinctrl_get_locked(pctldev->dev, PINCTRL_STATE_DEFAULT); - if (!IS_ERR(pctldev->p)) - pinctrl_enable_locked(pctldev->p); + pctldev->p = pinctrl_get_locked(pctldev->dev); + if (!IS_ERR(pctldev->p)) { + struct pinctrl_state *s = + pinctrl_lookup_state_locked(pctldev->p, + PINCTRL_STATE_DEFAULT); + if (!IS_ERR(s)) + pinctrl_select_state_locked(pctldev->p, s); + } mutex_unlock(&pinctrl_mutex); @@ -1144,10 +1225,8 @@ void pinctrl_unregister(struct pinctrl_dev *pctldev) mutex_lock(&pinctrl_mutex); - if (!IS_ERR(pctldev->p)) { - pinctrl_disable_locked(pctldev->p); - pinctrl_put_locked(pctldev->p); - } + if (!IS_ERR(pctldev->p)) + pinctrl_put_locked(pctldev->p, true); /* TODO: check that no pinmuxes are still active? */ list_del(&pctldev->node); diff --git a/drivers/pinctrl/core.h b/drivers/pinctrl/core.h index 0bc52ecaf710..5691d312e15a 100644 --- a/drivers/pinctrl/core.h +++ b/drivers/pinctrl/core.h @@ -49,22 +49,31 @@ struct pinctrl_dev { * struct pinctrl - per-device pin control state holder * @node: global list node * @dev: the device using this pin control handle - * @state: the state name passed to pinctrl_get() - * @usecount: the number of active users of this pin controller setting, used - * to keep track of nested use cases - * @settings: a list of settings for this device/state + * @states: a list of states for this device + * @state: the current state */ struct pinctrl { struct list_head node; struct device *dev; - const char *state; - unsigned usecount; + struct list_head states; + struct pinctrl_state *state; +}; + +/** + * struct pinctrl_state - a pinctrl state for a device + * @node: list not for struct pinctrl's @states field + * @name: the name of this state + * @settings: a list of settings for this state + */ +struct pinctrl_state { + struct list_head node; + const char *name; struct list_head settings; }; /** * struct pinctrl_setting - an individual mux setting - * @node: list node for struct pinctrl's @settings field + * @node: list node for struct pinctrl_settings's @settings field * @pctldev: pin control device handling to be programmed * @group_selector: the group selector to program * @func_selector: the function selector to program diff --git a/drivers/tty/serial/sirfsoc_uart.c b/drivers/tty/serial/sirfsoc_uart.c index 3cabb650a1c1..5b3eda2024fe 100644 --- a/drivers/tty/serial/sirfsoc_uart.c +++ b/drivers/tty/serial/sirfsoc_uart.c @@ -673,12 +673,10 @@ int sirfsoc_uart_probe(struct platform_device *pdev) port->irq = res->start; if (sirfport->hw_flow_ctrl) { - sirfport->p = pinctrl_get(&pdev->dev, PINCTRL_STATE_DEFAULT); + sirfport->p = pinctrl_get_select_default(&pdev->dev); ret = IS_ERR(sirfport->p); if (ret) goto pin_err; - - pinctrl_enable(sirfport->p); } port->ops = &sirfsoc_uart_ops; @@ -695,10 +693,8 @@ int sirfsoc_uart_probe(struct platform_device *pdev) port_err: platform_set_drvdata(pdev, NULL); - if (sirfport->hw_flow_ctrl) { - pinctrl_disable(sirfport->p); + if (sirfport->hw_flow_ctrl) pinctrl_put(sirfport->p); - } pin_err: irq_err: devm_iounmap(&pdev->dev, port->membase); @@ -711,10 +707,8 @@ static int sirfsoc_uart_remove(struct platform_device *pdev) struct sirfsoc_uart_port *sirfport = platform_get_drvdata(pdev); struct uart_port *port = &sirfport->port; platform_set_drvdata(pdev, NULL); - if (sirfport->hw_flow_ctrl) { - pinctrl_disable(sirfport->p); + if (sirfport->hw_flow_ctrl) pinctrl_put(sirfport->p); - } devm_iounmap(&pdev->dev, port->membase); uart_remove_one_port(&sirfsoc_uart_drv, port); return 0; diff --git a/include/linux/pinctrl/consumer.h b/include/linux/pinctrl/consumer.h index 30865947f2d9..9ad5896cfa0e 100644 --- a/include/linux/pinctrl/consumer.h +++ b/include/linux/pinctrl/consumer.h @@ -12,12 +12,14 @@ #ifndef __LINUX_PINCTRL_CONSUMER_H #define __LINUX_PINCTRL_CONSUMER_H +#include #include #include #include "pinctrl.h" /* This struct is private to the core and should be regarded as a cookie */ struct pinctrl; +struct pinctrl_state; #ifdef CONFIG_PINCTRL @@ -26,10 +28,13 @@ extern int pinctrl_request_gpio(unsigned gpio); extern void pinctrl_free_gpio(unsigned gpio); extern int pinctrl_gpio_direction_input(unsigned gpio); extern int pinctrl_gpio_direction_output(unsigned gpio); -extern struct pinctrl * __must_check pinctrl_get(struct device *dev, const char *name); + +extern struct pinctrl * __must_check pinctrl_get(struct device *dev); extern void pinctrl_put(struct pinctrl *p); -extern int pinctrl_enable(struct pinctrl *p); -extern void pinctrl_disable(struct pinctrl *p); +extern struct pinctrl_state * __must_check pinctrl_lookup_state( + struct pinctrl *p, + const char *name); +extern int pinctrl_select_state(struct pinctrl *p, struct pinctrl_state *s); #else /* !CONFIG_PINCTRL */ @@ -52,7 +57,7 @@ static inline int pinctrl_gpio_direction_output(unsigned gpio) return 0; } -static inline struct pinctrl * __must_check pinctrl_get(struct device *dev, const char *name) +static inline struct pinctrl * __must_check pinctrl_get(struct device *dev) { return NULL; } @@ -61,17 +66,53 @@ static inline void pinctrl_put(struct pinctrl *p) { } -static inline int pinctrl_enable(struct pinctrl *p) +static inline struct pinctrl_state * __must_check pinctrl_lookup_state( + struct pinctrl *p, + const char *name) { - return 0; + return NULL; } -static inline void pinctrl_disable(struct pinctrl *p) +static inline int pinctrl_select_state(struct pinctrl *p, + struct pinctrl_state *s) { + return 0; } #endif /* CONFIG_PINCTRL */ +static inline struct pinctrl * __must_check pinctrl_get_select( + struct device *dev, const char *name) +{ + struct pinctrl *p; + struct pinctrl_state *s; + int ret; + + p = pinctrl_get(dev); + if (IS_ERR(p)) + return p; + + s = pinctrl_lookup_state(p, name); + if (IS_ERR(s)) { + pinctrl_put(p); + return ERR_PTR(PTR_ERR(s)); + } + + ret = pinctrl_select_state(p, s); + if (ret < 0) { + pinctrl_put(p); + return ERR_PTR(ret); + } + + return p; +} + +static inline struct pinctrl * __must_check pinctrl_get_select_default( + struct device *dev) +{ + return pinctrl_get_select(dev, PINCTRL_STATE_DEFAULT); +} + #ifdef CONFIG_PINCONF extern int pin_config_get(const char *dev_name, const char *name, diff --git a/include/linux/pinctrl/machine.h b/include/linux/pinctrl/machine.h index 20e97353d5f9..05d25c8adbaf 100644 --- a/include/linux/pinctrl/machine.h +++ b/include/linux/pinctrl/machine.h @@ -21,23 +21,22 @@ * same name as the pin controllers own dev_name(), the map entry will be * hogged by the driver itself upon registration * @name: the name of this specific map entry for the particular machine. - * This is the second parameter passed to pinmux_get() when you want - * to have several mappings to the same device + * This is the parameter passed to pinmux_lookup_state() * @ctrl_dev_name: the name of the device controlling this specific mapping, * the name must be the same as in your struct device* - * @function: a function in the driver to use for this mapping, the driver - * will lookup the function referenced by this ID on the specified - * pin control device * @group: sometimes a function can map to different pin groups, so this * selects a certain specific pin group to activate for the function, if * left as NULL, the first applicable group will be used + * @function: a function in the driver to use for this mapping, the driver + * will lookup the function referenced by this ID on the specified + * pin control device */ struct pinctrl_map { const char *dev_name; const char *name; const char *ctrl_dev_name; - const char *function; const char *group; + const char *function; }; /* -- cgit v1.2.3 From 1e2082b520721734c358f776d34a069867214c8e Mon Sep 17 00:00:00 2001 From: Stephen Warren Date: Fri, 2 Mar 2012 13:05:48 -0700 Subject: pinctrl: enhance mapping table to support pin config operations The pinctrl mapping table can now contain entries to: * Set the mux function of a pin group * Apply a set of pin config options to a pin or a group This allows pinctrl_select_state() to apply pin configs settings as well as mux settings. v3: Fix find_pinctrl() to iterate over the correct list. s/_MUX_CONFIGS_/_CONFIGS_/ in mapping table macros. Fix documentation to use correct mapping table macro. v2: Added numerous extra PIN_MAP_*() special-case macros. Fixed kerneldoc typo. Delete pinctrl_get_pin_id() and replace it with pin_get_from_name(). Various minor fixes. Updates due to rebase. Signed-off-by: Stephen Warren Acked-by: Dong Aisheng Signed-off-by: Linus Walleij --- Documentation/pinctrl.txt | 76 +++++++++++++++--- arch/arm/mach-u300/core.c | 12 +-- drivers/pinctrl/core.c | 154 ++++++++++++++++++++++++++++++------- drivers/pinctrl/core.h | 35 ++++++++- drivers/pinctrl/pinconf.c | 165 ++++++++++++++++++++++++++++++++++++++++ drivers/pinctrl/pinconf.h | 40 ++++++++++ drivers/pinctrl/pinmux.c | 69 ++++++++++------- drivers/pinctrl/pinmux.h | 23 +++++- include/linux/pinctrl/machine.h | 145 +++++++++++++++++++++++++++-------- 9 files changed, 611 insertions(+), 108 deletions(-) (limited to 'arch/arm/mach-u300') diff --git a/Documentation/pinctrl.txt b/Documentation/pinctrl.txt index 23426c7bc8dc..d97bccf46147 100644 --- a/Documentation/pinctrl.txt +++ b/Documentation/pinctrl.txt @@ -206,14 +206,21 @@ 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: +Pin configuration can be programmed either using the explicit APIs described +immediately below, or by adding configuration entries into the mapping table; +see section "Board/machine configuration" below. + +For example, a platform may do the following to pull up a pin to VDD: #include ret = pin_config_set("foo-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: +The format and meaning of the configuration parameter, PLATFORM_X_PULL_UP +above, is entirely defined by the pin controller driver. + +The pin configuration driver implements callbacks for changing pin +configuration in the pin controller ops like this: #include #include @@ -765,7 +772,7 @@ obtain the function "gpioN" where "N" is the global GPIO pin number if no special GPIO-handler is registered. -Pinmux board/machine configuration +Board/machine configuration ================================== Boards and machines define how a certain complete running system is put @@ -773,9 +780,9 @@ together, including how GPIOs and devices are muxed, how regulators are constrained and how the clock tree looks. Of course pinmux settings are also part of this. -A pinmux config for a machine looks pretty much like a simple regulator -configuration, so for the example array above we want to enable i2c and -spi on the second function mapping: +A pin controller configuration for a machine looks pretty much like a simple +regulator configuration, so for the example array above we want to enable i2c +and spi on the second function mapping: #include @@ -783,20 +790,23 @@ static const struct pinctrl_map __initdata mapping[] = { { .dev_name = "foo-spi.0", .name = PINCTRL_STATE_DEFAULT, + .type = PIN_MAP_TYPE_MUX_GROUP, .ctrl_dev_name = "pinctrl-foo", - .function = "spi0", + .data.mux.function = "spi0", }, { .dev_name = "foo-i2c.0", .name = PINCTRL_STATE_DEFAULT, + .type = PIN_MAP_TYPE_MUX_GROUP, .ctrl_dev_name = "pinctrl-foo", - .function = "i2c0", + .data.mux.function = "i2c0", }, { .dev_name = "foo-mmc.0", .name = PINCTRL_STATE_DEFAULT, + .type = PIN_MAP_TYPE_MUX_GROUP, .ctrl_dev_name = "pinctrl-foo", - .function = "mmc0", + .data.mux.function = "mmc0", }, }; @@ -817,7 +827,40 @@ it even more compact which assumes you want to use pinctrl-foo and position 0 for mapping, for example: static struct pinctrl_map __initdata mapping[] = { - PIN_MAP(PINCTRL_STATE_DEFAULT, "pinctrl-foo", "i2c0", "foo-i2c.0"), + PIN_MAP_MUX_GROUP("foo-i2c.o", PINCTRL_STATE_DEFAULT, "pinctrl-foo", NULL, "i2c0"), +}; + +The mapping table may also contain pin configuration entries. It's common for +each pin/group to have a number of configuration entries that affect it, so +the table entries for configuration reference an array of config parameters +and values. An example using the convenience macros is shown below: + +static unsigned long i2c_grp_configs[] = { + FOO_PIN_DRIVEN, + FOO_PIN_PULLUP, +}; + +static unsigned long i2c_pin_configs[] = { + FOO_OPEN_COLLECTOR, + FOO_SLEW_RATE_SLOW, +}; + +static struct pinctrl_map __initdata mapping[] = { + PIN_MAP_MUX_GROUP("foo-i2c.0", PINCTRL_STATE_DEFAULT, "pinctrl-foo", "i2c0", "i2c0"), + PIN_MAP_MUX_CONFIGS_GROUP("foo-i2c.0", PINCTRL_STATE_DEFAULT, "pinctrl-foo", "i2c0", i2c_grp_configs), + PIN_MAP_MUX_CONFIGS_PIN("foo-i2c.0", PINCTRL_STATE_DEFAULT, "pinctrl-foo", "i2c0scl", i2c_pin_configs), + PIN_MAP_MUX_CONFIGS_PIN("foo-i2c.0", PINCTRL_STATE_DEFAULT, "pinctrl-foo", "i2c0sda", i2c_pin_configs), +}; + +Finally, some devices expect the mapping table to contain certain specific +named states. When running on hardware that doesn't need any pin controller +configuration, the mapping table must still contain those named states, in +order to explicitly indicate that the states were provided and intended to +be empty. Table entry macro PIN_MAP_DUMMY_STATE serves the purpose of defining +a named state without causing any pin controller to be programmed: + +static struct pinctrl_map __initdata mapping[] = { + PIN_MAP_DUMMY_STATE("foo-i2c.0", PINCTRL_STATE_DEFAULT), }; @@ -831,6 +874,7 @@ As it is possible to map a function to different groups of pins an optional { .dev_name = "foo-spi.0", .name = "spi0-pos-A", + .type = PIN_MAP_TYPE_MUX_GROUP, .ctrl_dev_name = "pinctrl-foo", .function = "spi0", .group = "spi0_0_grp", @@ -838,6 +882,7 @@ As it is possible to map a function to different groups of pins an optional { .dev_name = "foo-spi.0", .name = "spi0-pos-B", + .type = PIN_MAP_TYPE_MUX_GROUP, .ctrl_dev_name = "pinctrl-foo", .function = "spi0", .group = "spi0_1_grp", @@ -857,6 +902,7 @@ case), we define a mapping like this: { .dev_name = "foo-mmc.0", .name = "2bit" + .type = PIN_MAP_TYPE_MUX_GROUP, .ctrl_dev_name = "pinctrl-foo", .function = "mmc0", .group = "mmc0_1_grp", @@ -864,6 +910,7 @@ case), we define a mapping like this: { .dev_name = "foo-mmc.0", .name = "4bit" + .type = PIN_MAP_TYPE_MUX_GROUP, .ctrl_dev_name = "pinctrl-foo", .function = "mmc0", .group = "mmc0_1_grp", @@ -871,6 +918,7 @@ case), we define a mapping like this: { .dev_name = "foo-mmc.0", .name = "4bit" + .type = PIN_MAP_TYPE_MUX_GROUP, .ctrl_dev_name = "pinctrl-foo", .function = "mmc0", .group = "mmc0_2_grp", @@ -878,6 +926,7 @@ case), we define a mapping like this: { .dev_name = "foo-mmc.0", .name = "8bit" + .type = PIN_MAP_TYPE_MUX_GROUP, .ctrl_dev_name = "pinctrl-foo", .function = "mmc0", .group = "mmc0_1_grp", @@ -885,6 +934,7 @@ case), we define a mapping like this: { .dev_name = "foo-mmc.0", .name = "8bit" + .type = PIN_MAP_TYPE_MUX_GROUP, .ctrl_dev_name = "pinctrl-foo", .function = "mmc0", .group = "mmc0_2_grp", @@ -892,6 +942,7 @@ case), we define a mapping like this: { .dev_name = "foo-mmc.0", .name = "8bit" + .type = PIN_MAP_TYPE_MUX_GROUP, .ctrl_dev_name = "pinctrl-foo", .function = "mmc0", .group = "mmc0_3_grp", @@ -1014,6 +1065,7 @@ to the pin controller device name, and the state name is PINCTRL_STATE_DEFAULT. { .dev_name = "pinctrl-foo", .name = PINCTRL_STATE_DEFAULT, + .type = PIN_MAP_TYPE_MUX_GROUP, .ctrl_dev_name = "pinctrl-foo", .function = "power_func", }, @@ -1022,7 +1074,7 @@ Since it may be common to request the core to hog a few always-applicable mux settings on the primary pin controller, there is a convenience macro for this: -PIN_MAP_SYS_HOG("pinctrl-foo", "power_func") +PIN_MAP_MUX_GROUP_HOG_DEFAULT("pinctrl-foo", NULL /* group */, "power_func") This gives the exact same result as the above construction. diff --git a/arch/arm/mach-u300/core.c b/arch/arm/mach-u300/core.c index c092cf92e8ea..f326d3136128 100644 --- a/arch/arm/mach-u300/core.c +++ b/arch/arm/mach-u300/core.c @@ -1608,13 +1608,13 @@ static struct platform_device dma_device = { /* Pinmux settings */ static struct pinctrl_map __initdata u300_pinmux_map[] = { /* anonymous maps for chip power and EMIFs */ - PIN_MAP_SYS_HOG("pinctrl-u300", "power"), - PIN_MAP_SYS_HOG("pinctrl-u300", "emif0"), - PIN_MAP_SYS_HOG("pinctrl-u300", "emif1"), + PIN_MAP_MUX_GROUP_HOG_DEFAULT("pinctrl-u300", NULL, "power"), + PIN_MAP_MUX_GROUP_HOG_DEFAULT("pinctrl-u300", NULL, "emif0"), + PIN_MAP_MUX_GROUP_HOG_DEFAULT("pinctrl-u300", NULL, "emif1"), /* per-device maps for MMC/SD, SPI and UART */ - PIN_MAP(PINCTRL_STATE_DEFAULT, "pinctrl-u300", "mmc0", "mmci"), - PIN_MAP(PINCTRL_STATE_DEFAULT, "pinctrl-u300", "spi0", "pl022"), - PIN_MAP(PINCTRL_STATE_DEFAULT, "pinctrl-u300", "uart0", "uart0"), + PIN_MAP_MUX_GROUP_DEFAULT("mmci", "pinctrl-u300", NULL, "mmc0"), + PIN_MAP_MUX_GROUP_DEFAULT("pl022", "pinctrl-u300", NULL, "spi0"), + PIN_MAP_MUX_GROUP_DEFAULT("uart0", "pinctrl-u300", NULL, "uart0"), }; struct u300_mux_hog { diff --git a/drivers/pinctrl/core.c b/drivers/pinctrl/core.c index c6f3ca32189e..ec3b8cc188af 100644 --- a/drivers/pinctrl/core.c +++ b/drivers/pinctrl/core.c @@ -502,6 +502,9 @@ static int add_setting(struct pinctrl *p, struct pinctrl_map const *map) if (IS_ERR(state)) return PTR_ERR(state); + if (map->type == PIN_MAP_TYPE_DUMMY_STATE) + return 0; + setting = kzalloc(sizeof(*setting), GFP_KERNEL); if (setting == NULL) { dev_err(p->dev, @@ -509,6 +512,8 @@ static int add_setting(struct pinctrl *p, struct pinctrl_map const *map) return -ENOMEM; } + setting->type = map->type; + setting->pctldev = get_pinctrl_dev_from_devname(map->ctrl_dev_name); if (setting->pctldev == NULL) { dev_err(p->dev, "unknown pinctrl device %s in map entry", @@ -518,7 +523,18 @@ static int add_setting(struct pinctrl *p, struct pinctrl_map const *map) return -ENODEV; } - ret = pinmux_map_to_setting(map, setting); + switch (map->type) { + case PIN_MAP_TYPE_MUX_GROUP: + ret = pinmux_map_to_setting(map, setting); + break; + case PIN_MAP_TYPE_CONFIGS_PIN: + case PIN_MAP_TYPE_CONFIGS_GROUP: + ret = pinconf_map_to_setting(map, setting); + break; + default: + ret = -EINVAL; + break; + } if (ret < 0) { kfree(setting); return ret; @@ -533,7 +549,7 @@ static struct pinctrl *find_pinctrl(struct device *dev) { struct pinctrl *p; - list_for_each_entry(p, &pinctrldev_list, node) + list_for_each_entry(p, &pinctrl_list, node) if (p->dev == dev) return p; @@ -626,9 +642,19 @@ static void pinctrl_put_locked(struct pinctrl *p, bool inlist) list_for_each_entry_safe(state, n1, &p->states, node) { list_for_each_entry_safe(setting, n2, &state->settings, node) { - if (state == p->state) - pinmux_disable_setting(setting); - pinmux_free_setting(setting); + switch (setting->type) { + case PIN_MAP_TYPE_MUX_GROUP: + if (state == p->state) + pinmux_disable_setting(setting); + pinmux_free_setting(setting); + break; + case PIN_MAP_TYPE_CONFIGS_PIN: + case PIN_MAP_TYPE_CONFIGS_GROUP: + pinconf_free_setting(setting); + break; + default: + break; + } list_del(&setting->node); kfree(setting); } @@ -703,9 +729,13 @@ static int pinctrl_select_state_locked(struct pinctrl *p, */ list_for_each_entry(setting, &p->state->settings, node) { bool found = false; + if (setting->type != PIN_MAP_TYPE_MUX_GROUP) + continue; list_for_each_entry(setting2, &state->settings, node) { - if (setting2->group_selector == - setting->group_selector) { + if (setting2->type != PIN_MAP_TYPE_MUX_GROUP) + continue; + if (setting2->data.mux.group == + setting->data.mux.group) { found = true; break; } @@ -719,7 +749,18 @@ static int pinctrl_select_state_locked(struct pinctrl *p, /* Apply all the settings for the new state */ list_for_each_entry(setting, &state->settings, node) { - ret = pinmux_enable_setting(setting); + switch (setting->type) { + case PIN_MAP_TYPE_MUX_GROUP: + ret = pinmux_enable_setting(setting); + break; + case PIN_MAP_TYPE_CONFIGS_PIN: + case PIN_MAP_TYPE_CONFIGS_GROUP: + ret = pinconf_apply_setting(setting); + break; + default: + ret = -EINVAL; + break; + } if (ret < 0) { /* FIXME: Difficult to return to prev state */ return ret; @@ -756,33 +797,48 @@ EXPORT_SYMBOL_GPL(pinctrl_select_state); int pinctrl_register_mappings(struct pinctrl_map const *maps, unsigned num_maps) { - int i; + int i, ret; struct pinctrl_maps *maps_node; pr_debug("add %d pinmux maps\n", num_maps); /* First sanity check the new mapping */ for (i = 0; i < num_maps; i++) { + if (!maps[i].dev_name) { + pr_err("failed to register map %s (%d): no device given\n", + maps[i].name, i); + return -EINVAL; + } + if (!maps[i].name) { pr_err("failed to register map %d: no map name given\n", i); return -EINVAL; } - if (!maps[i].ctrl_dev_name) { + if (maps[i].type != PIN_MAP_TYPE_DUMMY_STATE && + !maps[i].ctrl_dev_name) { pr_err("failed to register map %s (%d): no pin control device given\n", maps[i].name, i); return -EINVAL; } - if (!maps[i].function) { - pr_err("failed to register map %s (%d): no function ID given\n", - maps[i].name, i); - return -EINVAL; - } - - if (!maps[i].dev_name) { - pr_err("failed to register map %s (%d): no device given\n", + switch (maps[i].type) { + case PIN_MAP_TYPE_DUMMY_STATE: + break; + case PIN_MAP_TYPE_MUX_GROUP: + ret = pinmux_validate_map(&maps[i], i); + if (ret < 0) + return 0; + break; + case PIN_MAP_TYPE_CONFIGS_PIN: + case PIN_MAP_TYPE_CONFIGS_GROUP: + ret = pinconf_validate_map(&maps[i], i); + if (ret < 0) + return 0; + break; + default: + pr_err("failed to register map %s (%d): invalid type given\n", maps[i].name, i); return -EINVAL; } @@ -934,6 +990,22 @@ static int pinctrl_devices_show(struct seq_file *s, void *what) return 0; } +static inline const char *map_type(enum pinctrl_map_type type) +{ + static const char * const names[] = { + "INVALID", + "DUMMY_STATE", + "MUX_GROUP", + "CONFIGS_PIN", + "CONFIGS_GROUP", + }; + + if (type >= ARRAY_SIZE(names)) + return "UNKNOWN"; + + return names[type]; +} + static int pinctrl_maps_show(struct seq_file *s, void *what) { struct pinctrl_maps *maps_node; @@ -945,12 +1017,27 @@ static int pinctrl_maps_show(struct seq_file *s, void *what) mutex_lock(&pinctrl_mutex); for_each_maps(maps_node, i, map) { - seq_printf(s, "%s:\n", map->name); - seq_printf(s, " device: %s\n", map->dev_name); - seq_printf(s, " controlling device %s\n", map->ctrl_dev_name); - seq_printf(s, " function: %s\n", map->function); - seq_printf(s, " group: %s\n", map->group ? map->group : - "(default)"); + seq_printf(s, "device %s\nstate %s\ntype %s (%d)\n", + map->dev_name, map->name, map_type(map->type), + map->type); + + if (map->type != PIN_MAP_TYPE_DUMMY_STATE) + seq_printf(s, "controlling device %s\n", + map->ctrl_dev_name); + + switch (map->type) { + case PIN_MAP_TYPE_MUX_GROUP: + pinmux_show_map(s, map); + break; + case PIN_MAP_TYPE_CONFIGS_PIN: + case PIN_MAP_TYPE_CONFIGS_GROUP: + pinconf_show_map(s, map); + break; + default: + break; + } + + seq_printf(s, "\n"); } mutex_unlock(&pinctrl_mutex); @@ -977,8 +1064,23 @@ static int pinctrl_show(struct seq_file *s, void *what) seq_printf(s, " state: %s\n", state->name); list_for_each_entry(setting, &state->settings, node) { - seq_printf(s, " "); - pinmux_dbg_show(s, setting); + struct pinctrl_dev *pctldev = setting->pctldev; + + seq_printf(s, " type: %s controller %s ", + map_type(setting->type), + pinctrl_dev_get_name(pctldev)); + + switch (setting->type) { + case PIN_MAP_TYPE_MUX_GROUP: + pinmux_show_setting(s, setting); + break; + case PIN_MAP_TYPE_CONFIGS_PIN: + case PIN_MAP_TYPE_CONFIGS_GROUP: + pinconf_show_setting(s, setting); + break; + default: + break; + } } } } diff --git a/drivers/pinctrl/core.h b/drivers/pinctrl/core.h index 5691d312e15a..1cae3723bbed 100644 --- a/drivers/pinctrl/core.h +++ b/drivers/pinctrl/core.h @@ -71,18 +71,45 @@ struct pinctrl_state { struct list_head settings; }; +/** + * struct pinctrl_setting_mux - setting data for MAP_TYPE_MUX_GROUP + * @group: the group selector to program + * @func: the function selector to program + */ +struct pinctrl_setting_mux { + unsigned group; + unsigned func; +}; + +/** + * struct pinctrl_setting_configs - setting data for MAP_TYPE_CONFIGS_* + * @group_or_pin: the group selector or pin ID to program + * @configs: a pointer to an array of config parameters/values to program into + * hardware. Each individual pin controller defines the format and meaning + * of config parameters. + * @num_configs: the number of entries in array @configs + */ +struct pinctrl_setting_configs { + unsigned group_or_pin; + unsigned long *configs; + unsigned num_configs; +}; + /** * struct pinctrl_setting - an individual mux setting * @node: list node for struct pinctrl_settings's @settings field + * @type: the type of setting * @pctldev: pin control device handling to be programmed - * @group_selector: the group selector to program - * @func_selector: the function selector to program + * @data: Data specific to the setting type */ struct pinctrl_setting { struct list_head node; + enum pinctrl_map_type type; struct pinctrl_dev *pctldev; - unsigned group_selector; - unsigned func_selector; + union { + struct pinctrl_setting_mux mux; + struct pinctrl_setting_configs configs; + } data; }; /** diff --git a/drivers/pinctrl/pinconf.c b/drivers/pinctrl/pinconf.c index e0a453790a40..84869f28b101 100644 --- a/drivers/pinctrl/pinconf.c +++ b/drivers/pinctrl/pinconf.c @@ -36,6 +36,24 @@ int pinconf_check_ops(struct pinctrl_dev *pctldev) return 0; } +int pinconf_validate_map(struct pinctrl_map const *map, int i) +{ + if (!map->data.configs.group_or_pin) { + pr_err("failed to register map %s (%d): no group/pin given\n", + map->name, i); + return -EINVAL; + } + + if (map->data.configs.num_configs && + !map->data.configs.configs) { + pr_err("failed to register map %s (%d): no configs ptr given\n", + map->name, i); + return -EINVAL; + } + + return 0; +} + static int pin_config_get_for_pin(struct pinctrl_dev *pctldev, unsigned pin, unsigned long *config) { @@ -260,8 +278,155 @@ unlock: } EXPORT_SYMBOL(pin_config_group_set); +int pinconf_map_to_setting(struct pinctrl_map const *map, + struct pinctrl_setting *setting) +{ + struct pinctrl_dev *pctldev = setting->pctldev; + + switch (setting->type) { + case PIN_MAP_TYPE_CONFIGS_PIN: + setting->data.configs.group_or_pin = + pin_get_from_name(pctldev, + map->data.configs.group_or_pin); + if (setting->data.configs.group_or_pin < 0) + return setting->data.configs.group_or_pin; + break; + case PIN_MAP_TYPE_CONFIGS_GROUP: + setting->data.configs.group_or_pin = + pinctrl_get_group_selector(pctldev, + map->data.configs.group_or_pin); + if (setting->data.configs.group_or_pin < 0) + return setting->data.configs.group_or_pin; + break; + default: + return -EINVAL; + } + + setting->data.configs.num_configs = map->data.configs.num_configs; + setting->data.configs.configs = map->data.configs.configs; + + return 0; +} + +void pinconf_free_setting(struct pinctrl_setting const *setting) +{ +} + +int pinconf_apply_setting(struct pinctrl_setting const *setting) +{ + struct pinctrl_dev *pctldev = setting->pctldev; + const struct pinconf_ops *ops = pctldev->desc->confops; + int i, ret; + + if (!ops) { + dev_err(pctldev->dev, "missing confops\n"); + return -EINVAL; + } + + switch (setting->type) { + case PIN_MAP_TYPE_CONFIGS_PIN: + if (!ops->pin_config_set) { + dev_err(pctldev->dev, "missing pin_config_set op\n"); + return -EINVAL; + } + for (i = 0; i < setting->data.configs.num_configs; i++) { + ret = ops->pin_config_set(pctldev, + setting->data.configs.group_or_pin, + setting->data.configs.configs[i]); + if (ret < 0) { + dev_err(pctldev->dev, + "pin_config_set op failed for pin %d config %08lx\n", + setting->data.configs.group_or_pin, + setting->data.configs.configs[i]); + return ret; + } + } + break; + case PIN_MAP_TYPE_CONFIGS_GROUP: + if (!ops->pin_config_group_set) { + dev_err(pctldev->dev, + "missing pin_config_group_set op\n"); + return -EINVAL; + } + for (i = 0; i < setting->data.configs.num_configs; i++) { + ret = ops->pin_config_group_set(pctldev, + setting->data.configs.group_or_pin, + setting->data.configs.configs[i]); + if (ret < 0) { + dev_err(pctldev->dev, + "pin_config_group_set op failed for group %d config %08lx\n", + setting->data.configs.group_or_pin, + setting->data.configs.configs[i]); + return ret; + } + } + break; + default: + return -EINVAL; + } + + return 0; +} + #ifdef CONFIG_DEBUG_FS +void pinconf_show_map(struct seq_file *s, struct pinctrl_map const *map) +{ + int i; + + switch (map->type) { + case PIN_MAP_TYPE_CONFIGS_PIN: + seq_printf(s, "pin "); + break; + case PIN_MAP_TYPE_CONFIGS_GROUP: + seq_printf(s, "group "); + break; + default: + break; + } + + seq_printf(s, "%s\n", map->data.configs.group_or_pin); + + for (i = 0; i < map->data.configs.num_configs; i++) + seq_printf(s, "config %08lx\n", map->data.configs.configs[i]); +} + +void pinconf_show_setting(struct seq_file *s, + struct pinctrl_setting const *setting) +{ + struct pinctrl_dev *pctldev = setting->pctldev; + const struct pinctrl_ops *pctlops = pctldev->desc->pctlops; + struct pin_desc *desc; + int i; + + switch (setting->type) { + case PIN_MAP_TYPE_CONFIGS_PIN: + desc = pin_desc_get(setting->pctldev, + setting->data.configs.group_or_pin); + seq_printf(s, "pin %s (%d)", + desc->name ? desc->name : "unnamed", + setting->data.configs.group_or_pin); + break; + case PIN_MAP_TYPE_CONFIGS_GROUP: + seq_printf(s, "group %s (%d)", + pctlops->get_group_name(pctldev, + setting->data.configs.group_or_pin), + setting->data.configs.group_or_pin); + break; + default: + break; + } + + /* + * FIXME: We should really get the pin controler to dump the config + * values, so they can be decoded to something meaningful. + */ + for (i = 0; i < setting->data.configs.num_configs; i++) + seq_printf(s, " %08lx", setting->data.configs.configs[i]); + + seq_printf(s, "\n"); +} + static void pinconf_dump_pin(struct pinctrl_dev *pctldev, struct seq_file *s, int pin) { diff --git a/drivers/pinctrl/pinconf.h b/drivers/pinctrl/pinconf.h index 1d6ea9de75fc..0ded227661a5 100644 --- a/drivers/pinctrl/pinconf.h +++ b/drivers/pinctrl/pinconf.h @@ -15,6 +15,16 @@ int pinconf_check_ops(struct pinctrl_dev *pctldev); +int pinconf_validate_map(struct pinctrl_map const *map, int i); + +int pinconf_map_to_setting(struct pinctrl_map const *map, + struct pinctrl_setting *setting); +void pinconf_free_setting(struct pinctrl_setting const *setting); +int pinconf_apply_setting(struct pinctrl_setting const *setting); + +void pinconf_show_map(struct seq_file *s, struct pinctrl_map const *map); +void pinconf_show_setting(struct seq_file *s, + struct pinctrl_setting const *setting); void pinconf_init_device_debugfs(struct dentry *devroot, struct pinctrl_dev *pctldev); @@ -25,6 +35,36 @@ static inline int pinconf_check_ops(struct pinctrl_dev *pctldev) return 0; } +static inline int pinconf_validate_map(struct pinctrl_map const *map, int i) +{ + return 0; +} + +static inline int pinconf_map_to_setting(struct pinctrl_map const *map, + struct pinctrl_setting *setting) +{ + return 0; +} + +static inline void pinconf_free_setting(struct pinctrl_setting const *setting) +{ +} + +static inline int pinconf_apply_setting(struct pinctrl_setting const *setting) +{ + return 0; +} + +static inline void pinconf_show_map(struct seq_file *s, + struct pinctrl_map const *map) +{ +} + +static inline void pinconf_show_setting(struct seq_file *s, + struct pinctrl_setting const *setting) +{ +} + static inline void pinconf_init_device_debugfs(struct dentry *devroot, struct pinctrl_dev *pctldev) { diff --git a/drivers/pinctrl/pinmux.c b/drivers/pinctrl/pinmux.c index 56ca42e6a6ec..4852ebe5712e 100644 --- a/drivers/pinctrl/pinmux.c +++ b/drivers/pinctrl/pinmux.c @@ -58,6 +58,17 @@ int pinmux_check_ops(struct pinctrl_dev *pctldev) return 0; } +int pinmux_validate_map(struct pinctrl_map const *map, int i) +{ + if (!map->data.mux.function) { + pr_err("failed to register map %s (%d): no function given\n", + map->name, i); + return -EINVAL; + } + + return 0; +} + /** * pin_request() - request a single pin to be muxed in, typically for GPIO * @pin: the pin number in the global pin space @@ -284,21 +295,21 @@ int pinmux_map_to_setting(struct pinctrl_map const *map, const unsigned *pins; unsigned num_pins; - setting->func_selector = - pinmux_func_name_to_selector(pctldev, map->function); - if (setting->func_selector < 0) - return setting->func_selector; + setting->data.mux.func = + pinmux_func_name_to_selector(pctldev, map->data.mux.function); + if (setting->data.mux.func < 0) + return setting->data.mux.func; - ret = pmxops->get_function_groups(pctldev, setting->func_selector, + ret = pmxops->get_function_groups(pctldev, setting->data.mux.func, &groups, &num_groups); if (ret < 0) return ret; if (!num_groups) return -EINVAL; - if (map->group) { + if (map->data.mux.group) { bool found = false; - group = map->group; + group = map->data.mux.group; for (i = 0; i < num_groups; i++) { if (!strcmp(group, groups[i])) { found = true; @@ -311,17 +322,16 @@ int pinmux_map_to_setting(struct pinctrl_map const *map, group = groups[0]; } - setting->group_selector = - pinctrl_get_group_selector(pctldev, group); - if (setting->group_selector < 0) - return setting->group_selector; + setting->data.mux.group = pinctrl_get_group_selector(pctldev, group); + if (setting->data.mux.group < 0) + return setting->data.mux.group; - ret = pctlops->get_group_pins(pctldev, setting->group_selector, - &pins, &num_pins); + ret = pctlops->get_group_pins(pctldev, setting->data.mux.group, &pins, + &num_pins); if (ret) { dev_err(pctldev->dev, "could not get pins for device %s group selector %d\n", - pinctrl_dev_get_name(pctldev), setting->group_selector); + pinctrl_dev_get_name(pctldev), setting->data.mux.group); return -ENODEV; } @@ -352,12 +362,12 @@ void pinmux_free_setting(struct pinctrl_setting const *setting) int ret; int i; - ret = pctlops->get_group_pins(pctldev, setting->group_selector, + ret = pctlops->get_group_pins(pctldev, setting->data.mux.group, &pins, &num_pins); if (ret) { dev_err(pctldev->dev, "could not get pins for device %s group selector %d\n", - pinctrl_dev_get_name(pctldev), setting->group_selector); + pinctrl_dev_get_name(pctldev), setting->data.mux.group); return; } @@ -370,8 +380,8 @@ int pinmux_enable_setting(struct pinctrl_setting const *setting) struct pinctrl_dev *pctldev = setting->pctldev; const struct pinmux_ops *ops = pctldev->desc->pmxops; - return ops->enable(pctldev, setting->func_selector, - setting->group_selector); + return ops->enable(pctldev, setting->data.mux.func, + setting->data.mux.group); } void pinmux_disable_setting(struct pinctrl_setting const *setting) @@ -379,7 +389,7 @@ void pinmux_disable_setting(struct pinctrl_setting const *setting) struct pinctrl_dev *pctldev = setting->pctldev; const struct pinmux_ops *ops = pctldev->desc->pmxops; - ops->disable(pctldev, setting->func_selector, setting->group_selector); + ops->disable(pctldev, setting->data.mux.func, setting->data.mux.group); } #ifdef CONFIG_DEBUG_FS @@ -456,18 +466,25 @@ static int pinmux_pins_show(struct seq_file *s, void *what) return 0; } -void pinmux_dbg_show(struct seq_file *s, struct pinctrl_setting const *setting) +void pinmux_show_map(struct seq_file *s, struct pinctrl_map const *map) +{ + seq_printf(s, "group %s\nfunction %s\n", + map->data.mux.group ? map->data.mux.group : "(default)", + map->data.mux.function); +} + +void pinmux_show_setting(struct seq_file *s, + struct pinctrl_setting const *setting) { struct pinctrl_dev *pctldev = setting->pctldev; const struct pinmux_ops *pmxops = pctldev->desc->pmxops; const struct pinctrl_ops *pctlops = pctldev->desc->pctlops; - seq_printf(s, "controller: %s group: %s (%u) function: %s (%u)\n", - pinctrl_dev_get_name(pctldev), - pctlops->get_group_name(pctldev, setting->group_selector), - setting->group_selector, - pmxops->get_function_name(pctldev, setting->func_selector), - setting->func_selector); + seq_printf(s, "group: %s (%u) function: %s (%u)\n", + pctlops->get_group_name(pctldev, setting->data.mux.group), + setting->data.mux.group, + pmxops->get_function_name(pctldev, setting->data.mux.func), + setting->data.mux.func); } static int pinmux_functions_open(struct inode *inode, struct file *file) diff --git a/drivers/pinctrl/pinmux.h b/drivers/pinctrl/pinmux.h index 1500ae88f87c..6fc47003e95d 100644 --- a/drivers/pinctrl/pinmux.h +++ b/drivers/pinctrl/pinmux.h @@ -14,6 +14,8 @@ int pinmux_check_ops(struct pinctrl_dev *pctldev); +int pinmux_validate_map(struct pinctrl_map const *map, int i); + int pinmux_request_gpio(struct pinctrl_dev *pctldev, struct pinctrl_gpio_range *range, unsigned pin, unsigned gpio); @@ -29,7 +31,9 @@ void pinmux_free_setting(struct pinctrl_setting const *setting); int pinmux_enable_setting(struct pinctrl_setting const *setting); void pinmux_disable_setting(struct pinctrl_setting const *setting); -void pinmux_dbg_show(struct seq_file *s, struct pinctrl_setting const *setting); +void pinmux_show_map(struct seq_file *s, struct pinctrl_map const *map); +void pinmux_show_setting(struct seq_file *s, + struct pinctrl_setting const *setting); void pinmux_init_device_debugfs(struct dentry *devroot, struct pinctrl_dev *pctldev); @@ -40,6 +44,11 @@ static inline int pinmux_check_ops(struct pinctrl_dev *pctldev) return 0; } +static inline int pinmux_validate_map(struct pinctrl_map const *map, int i) +{ + return 0; +} + static inline int pinmux_request_gpio(struct pinctrl_dev *pctldev, struct pinctrl_gpio_range *range, unsigned pin, unsigned gpio) @@ -80,12 +89,18 @@ static inline void pinmux_disable_setting( { } -static inline void pinmux_init_device_debugfs(struct dentry *devroot, - struct pinctrl_dev *pctldev) +static inline void pinmux_show_map(struct seq_file *s, + struct pinctrl_map const *map) +{ +} + +static inline void pinmux_show_setting(struct seq_file *s, + struct pinctrl_setting const *setting) { } -static inline void pinmux_dbg_show(struct seq_file *s, struct pinctrl *p) +static inline void pinmux_init_device_debugfs(struct dentry *devroot, + struct pinctrl_dev *pctldev) { } diff --git a/include/linux/pinctrl/machine.h b/include/linux/pinctrl/machine.h index 05d25c8adbaf..3fd2f9dfc645 100644 --- a/include/linux/pinctrl/machine.h +++ b/include/linux/pinctrl/machine.h @@ -14,6 +14,41 @@ #include "pinctrl.h" +enum pinctrl_map_type { + PIN_MAP_TYPE_INVALID, + PIN_MAP_TYPE_DUMMY_STATE, + PIN_MAP_TYPE_MUX_GROUP, + PIN_MAP_TYPE_CONFIGS_PIN, + PIN_MAP_TYPE_CONFIGS_GROUP, +}; + +/** + * struct pinctrl_map_mux - mapping table content for MAP_TYPE_MUX_GROUP + * @group: the name of the group whose mux function is to be configured. This + * field may be left NULL, and the first applicable group for the function + * will be used. + * @function: the mux function to select for the group + */ +struct pinctrl_map_mux { + const char *group; + const char *function; +}; + +/** + * struct pinctrl_map_configs - mapping table content for MAP_TYPE_CONFIGS_* + * @group_or_pin: the name of the pin or group whose configuration parameters + * are to be configured. + * @configs: a pointer to an array of config parameters/values to program into + * hardware. Each individual pin controller defines the format and meaning + * of config parameters. + * @num_configs: the number of entries in array @configs + */ +struct pinctrl_map_configs { + const char *group_or_pin; + unsigned long *configs; + unsigned num_configs; +}; + /** * struct pinctrl_map - boards/machines shall provide this map for devices * @dev_name: the name of the device using this specific mapping, the name @@ -22,46 +57,96 @@ * hogged by the driver itself upon registration * @name: the name of this specific map entry for the particular machine. * This is the parameter passed to pinmux_lookup_state() + * @type: the type of mapping table entry * @ctrl_dev_name: the name of the device controlling this specific mapping, - * the name must be the same as in your struct device* - * @group: sometimes a function can map to different pin groups, so this - * selects a certain specific pin group to activate for the function, if - * left as NULL, the first applicable group will be used - * @function: a function in the driver to use for this mapping, the driver - * will lookup the function referenced by this ID on the specified - * pin control device + * the name must be the same as in your struct device*. This field is not + * used for PIN_MAP_TYPE_DUMMY_STATE + * @data: Data specific to the mapping type */ struct pinctrl_map { const char *dev_name; const char *name; + enum pinctrl_map_type type; const char *ctrl_dev_name; - const char *group; - const char *function; + union { + struct pinctrl_map_mux mux; + struct pinctrl_map_configs configs; + } data; }; -/* - * Convenience macro to set a simple map from a certain pin controller and a - * certain function to a named device - */ -#define PIN_MAP(a, b, c, d) \ - { .name = a, .ctrl_dev_name = b, .function = c, .dev_name = d } +/* Convenience macros to create mapping table entries */ -/* - * Convenience macro to map a system function onto a certain pinctrl device, - * to be hogged by the pin control core until the system shuts down. - */ -#define PIN_MAP_SYS_HOG(a, b) \ - { .name = PINCTRL_STATE_DEFAULT, .ctrl_dev_name = a, .dev_name = a, \ - .function = b, } +#define PIN_MAP_DUMMY_STATE(dev, state) \ + { \ + .dev_name = dev, \ + .name = state, \ + .type = PIN_MAP_TYPE_DUMMY_STATE, \ + } -/* - * Convenience macro to map a system function onto a certain pinctrl device - * using a specified group, to be hogged by the pin control core until the - * system shuts down. - */ -#define PIN_MAP_SYS_HOG_GROUP(a, b, c) \ - { .name = PINCTRL_STATE_DEFAULT, .ctrl_dev_name = a, .dev_name = a, \ - .function = b, .group = c, } +#define PIN_MAP_MUX_GROUP(dev, state, pinctrl, grp, func) \ + { \ + .dev_name = dev, \ + .name = state, \ + .type = PIN_MAP_TYPE_MUX_GROUP, \ + .ctrl_dev_name = pinctrl, \ + .data.mux = { \ + .group = grp, \ + .function = func, \ + }, \ + } + +#define PIN_MAP_MUX_GROUP_DEFAULT(dev, pinctrl, grp, func) \ + PIN_MAP_MUX_GROUP(dev, PINCTRL_STATE_DEFAULT, pinctrl, grp, func) + +#define PIN_MAP_MUX_GROUP_HOG(dev, state, grp, func) \ + PIN_MAP_MUX_GROUP(dev, state, dev, grp, func) + +#define PIN_MAP_MUX_GROUP_HOG_DEFAULT(dev, grp, func) \ + PIN_MAP_MUX_GROUP(dev, PINCTRL_STATE_DEFAULT, dev, grp, func) + +#define PIN_MAP_CONFIGS_PIN(dev, state, pinctrl, pin, cfgs) \ + { \ + .dev_name = dev, \ + .name = state, \ + .type = PIN_MAP_TYPE_CONFIGS_PIN, \ + .ctrl_dev_name = pinctrl, \ + .data.configs = { \ + .group_or_pin = pin, \ + .configs = cfgs, \ + .num_configs = ARRAY_SIZE(cfgs), \ + }, \ + } + +#define PIN_MAP_CONFIGS_PIN_DEFAULT(dev, pinctrl, pin, cfgs) \ + PIN_MAP_CONFIGS_PIN(dev, PINCTRL_STATE_DEFAULT, pinctrl, pin, cfgs) + +#define PIN_MAP_CONFIGS_PIN_HOG(dev, state, pin, cfgs) \ + PIN_MAP_CONFIGS_PIN(dev, state, dev, pin, cfgs) + +#define PIN_MAP_CONFIGS_PIN_HOG_DEFAULT(dev, pin, cfgs) \ + PIN_MAP_CONFIGS_PIN(dev, PINCTRL_STATE_DEFAULT, dev, pin, cfgs) + +#define PIN_MAP_CONFIGS_GROUP(dev, state, pinctrl, grp, cfgs) \ + { \ + .dev_name = dev, \ + .name = state, \ + .type = PIN_MAP_TYPE_CONFIGS_GROUP, \ + .ctrl_dev_name = pinctrl, \ + .data.configs = { \ + .group_or_pin = grp, \ + .configs = cfgs, \ + .num_configs = ARRAY_SIZE(cfgs), \ + }, \ + } + +#define PIN_MAP_CONFIGS_GROUP_DEFAULT(dev, pinctrl, grp, cfgs) \ + PIN_MAP_CONFIGS_GROUP(dev, PINCTRL_STATE_DEFAULT, pinctrl, grp, cfgs) + +#define PIN_MAP_CONFIGS_GROUP_HOG(dev, state, grp, cfgs) \ + PIN_MAP_CONFIGS_GROUP(dev, state, dev, grp, cfgs) + +#define PIN_MAP_CONFIGS_GROUP_HOG_DEFAULT(dev, grp, cfgs) \ + PIN_MAP_CONFIGS_GROUP(dev, PINCTRL_STATE_DEFAULT, dev, grp, cfgs) #ifdef CONFIG_PINMUX -- cgit v1.2.3 From 51dddfe839a0ebcb5ff61a779e3f2768714f9957 Mon Sep 17 00:00:00 2001 From: Linus Walleij Date: Fri, 20 Jan 2012 17:53:15 +0100 Subject: ARM: u300: configure some pins as an example To show how the pin configuration is used on the U300, let's include some configs for two GPIO pins. ChangeLog v1->v2: - Provide a better example, set the clock return pin to pull-up and set the card detect pin to high impedance. Signed-off-by: Linus Walleij --- arch/arm/mach-u300/core.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'arch/arm/mach-u300') diff --git a/arch/arm/mach-u300/core.c b/arch/arm/mach-u300/core.c index f326d3136128..a7b3f36e2262 100644 --- a/arch/arm/mach-u300/core.c +++ b/arch/arm/mach-u300/core.c @@ -27,6 +27,7 @@ #include #include #include +#include #include #include @@ -1605,7 +1606,15 @@ static struct platform_device dma_device = { }, }; -/* Pinmux settings */ +static unsigned long pin_pullup_conf[] = { + PIN_CONF_PACKED(PIN_CONFIG_BIAS_PULL_UP, 1), +}; + +static unsigned long pin_highz_conf[] = { + PIN_CONF_PACKED(PIN_CONFIG_BIAS_HIGH_IMPEDANCE, 0), +}; + +/* Pin control settings */ static struct pinctrl_map __initdata u300_pinmux_map[] = { /* anonymous maps for chip power and EMIFs */ PIN_MAP_MUX_GROUP_HOG_DEFAULT("pinctrl-u300", NULL, "power"), @@ -1615,6 +1624,12 @@ static struct pinctrl_map __initdata u300_pinmux_map[] = { PIN_MAP_MUX_GROUP_DEFAULT("mmci", "pinctrl-u300", NULL, "mmc0"), PIN_MAP_MUX_GROUP_DEFAULT("pl022", "pinctrl-u300", NULL, "spi0"), PIN_MAP_MUX_GROUP_DEFAULT("uart0", "pinctrl-u300", NULL, "uart0"), + /* This pin is used for clock return rather than GPIO */ + PIN_MAP_CONFIGS_PIN_DEFAULT("mmci", "pinctrl-u300", "PIO APP GPIO 11", + pin_pullup_conf), + /* This pin is used for card detect */ + PIN_MAP_CONFIGS_PIN_DEFAULT("mmci", "pinctrl-u300", "PIO MS INS", + pin_highz_conf), }; struct u300_mux_hog { @@ -1640,7 +1655,6 @@ static int __init u300_pinctrl_fetch(void) for (i = 0; i < ARRAY_SIZE(u300_mux_hogs); i++) { struct pinctrl *p; - int ret; p = pinctrl_get_select_default(u300_mux_hogs[i].dev); if (IS_ERR(p)) { -- cgit v1.2.3