From d4e62d0094e1b0f69946c3f16ce8ec882302a461 Mon Sep 17 00:00:00 2001 From: Laurent Pinchart Date: Sat, 15 Dec 2012 23:50:43 +0100 Subject: sh-pfc: Split platform data from the sh_pfc structure Create a sh_pfc_platform_data structure to store platform data and reference it from the core sh_pfc structure. Signed-off-by: Laurent Pinchart Acked-by: Paul Mundt Acked-by: Linus Walleij Signed-off-by: Simon Horman --- drivers/sh/pfc/core.c | 89 +++++++++++++++++++++++------------------------- drivers/sh/pfc/gpio.c | 19 ++++++----- drivers/sh/pfc/pinctrl.c | 27 ++++++++------- 3 files changed, 67 insertions(+), 68 deletions(-) (limited to 'drivers/sh') diff --git a/drivers/sh/pfc/core.c b/drivers/sh/pfc/core.c index 68169373c98..ecbe51d9f56 100644 --- a/drivers/sh/pfc/core.c +++ b/drivers/sh/pfc/core.c @@ -21,18 +21,13 @@ #include #include -static struct sh_pfc *sh_pfc __read_mostly; - -static inline bool sh_pfc_initialized(void) -{ - return !!sh_pfc; -} +static struct sh_pfc sh_pfc __read_mostly; static void pfc_iounmap(struct sh_pfc *pfc) { int k; - for (k = 0; k < pfc->num_resources; k++) + for (k = 0; k < pfc->pdata->num_resources; k++) if (pfc->window[k].virt) iounmap(pfc->window[k].virt); @@ -45,16 +40,16 @@ static int pfc_ioremap(struct sh_pfc *pfc) struct resource *res; int k; - if (!pfc->num_resources) + if (!pfc->pdata->num_resources) return 0; - pfc->window = kzalloc(pfc->num_resources * sizeof(*pfc->window), + pfc->window = kzalloc(pfc->pdata->num_resources * sizeof(*pfc->window), GFP_NOWAIT); if (!pfc->window) goto err1; - for (k = 0; k < pfc->num_resources; k++) { - res = pfc->resource + k; + for (k = 0; k < pfc->pdata->num_resources; k++) { + res = pfc->pdata->resource + k; WARN_ON(resource_type(res) != IORESOURCE_MEM); pfc->window[k].phys = res->start; pfc->window[k].size = resource_size(res); @@ -79,7 +74,7 @@ static void __iomem *pfc_phys_to_virt(struct sh_pfc *pfc, int k; /* scan through physical windows and convert address */ - for (k = 0; k < pfc->num_resources; k++) { + for (k = 0; k < pfc->pdata->num_resources; k++) { window = pfc->window + k; if (address < window->phys) @@ -232,8 +227,8 @@ static void write_config_reg(struct sh_pfc *pfc, data &= mask; data |= value; - if (pfc->unlock_reg) - gpio_write_raw_reg(pfc_phys_to_virt(pfc, pfc->unlock_reg), + if (pfc->pdata->unlock_reg) + gpio_write_raw_reg(pfc_phys_to_virt(pfc, pfc->pdata->unlock_reg), 32, ~data); gpio_write_raw_reg(mapped_reg, crp->reg_width, data); @@ -241,16 +236,16 @@ static void write_config_reg(struct sh_pfc *pfc, static int setup_data_reg(struct sh_pfc *pfc, unsigned gpio) { - struct pinmux_gpio *gpiop = &pfc->gpios[gpio]; + struct pinmux_gpio *gpiop = &pfc->pdata->gpios[gpio]; struct pinmux_data_reg *data_reg; int k, n; - if (!enum_in_range(gpiop->enum_id, &pfc->data)) + if (!enum_in_range(gpiop->enum_id, &pfc->pdata->data)) return -1; k = 0; while (1) { - data_reg = pfc->data_regs + k; + data_reg = pfc->pdata->data_regs + k; if (!data_reg->reg_width) break; @@ -279,12 +274,12 @@ static void setup_data_regs(struct sh_pfc *pfc) struct pinmux_data_reg *drp; int k; - for (k = pfc->first_gpio; k <= pfc->last_gpio; k++) + for (k = pfc->pdata->first_gpio; k <= pfc->pdata->last_gpio; k++) setup_data_reg(pfc, k); k = 0; while (1) { - drp = pfc->data_regs + k; + drp = pfc->pdata->data_regs + k; if (!drp->reg_width) break; @@ -298,15 +293,15 @@ static void setup_data_regs(struct sh_pfc *pfc) int sh_pfc_get_data_reg(struct sh_pfc *pfc, unsigned gpio, struct pinmux_data_reg **drp, int *bitp) { - struct pinmux_gpio *gpiop = &pfc->gpios[gpio]; + struct pinmux_gpio *gpiop = &pfc->pdata->gpios[gpio]; int k, n; - if (!enum_in_range(gpiop->enum_id, &pfc->data)) + if (!enum_in_range(gpiop->enum_id, &pfc->pdata->data)) return -1; k = (gpiop->flags & PINMUX_FLAG_DREG) >> PINMUX_FLAG_DREG_SHIFT; n = (gpiop->flags & PINMUX_FLAG_DBIT) >> PINMUX_FLAG_DBIT_SHIFT; - *drp = pfc->data_regs + k; + *drp = pfc->pdata->data_regs + k; *bitp = n; return 0; } @@ -323,7 +318,7 @@ static int get_config_reg(struct sh_pfc *pfc, pinmux_enum_t enum_id, k = 0; while (1) { - config_reg = pfc->cfg_regs + k; + config_reg = pfc->pdata->cfg_regs + k; r_width = config_reg->reg_width; f_width = config_reg->field_width; @@ -361,12 +356,12 @@ static int get_config_reg(struct sh_pfc *pfc, pinmux_enum_t enum_id, int sh_pfc_gpio_to_enum(struct sh_pfc *pfc, unsigned gpio, int pos, pinmux_enum_t *enum_idp) { - pinmux_enum_t enum_id = pfc->gpios[gpio].enum_id; - pinmux_enum_t *data = pfc->gpio_data; + pinmux_enum_t enum_id = pfc->pdata->gpios[gpio].enum_id; + pinmux_enum_t *data = pfc->pdata->gpio_data; int k; - if (!enum_in_range(enum_id, &pfc->data)) { - if (!enum_in_range(enum_id, &pfc->mark)) { + if (!enum_in_range(enum_id, &pfc->pdata->data)) { + if (!enum_in_range(enum_id, &pfc->pdata->mark)) { pr_err("non data/mark enum_id for gpio %d\n", gpio); return -1; } @@ -377,7 +372,7 @@ int sh_pfc_gpio_to_enum(struct sh_pfc *pfc, unsigned gpio, int pos, return pos + 1; } - for (k = 0; k < pfc->gpio_data_size; k++) { + for (k = 0; k < pfc->pdata->gpio_data_size; k++) { if (data[k] == enum_id) { *enum_idp = data[k + 1]; return k + 1; @@ -405,19 +400,19 @@ int sh_pfc_config_gpio(struct sh_pfc *pfc, unsigned gpio, int pinmux_type, break; case PINMUX_TYPE_OUTPUT: - range = &pfc->output; + range = &pfc->pdata->output; break; case PINMUX_TYPE_INPUT: - range = &pfc->input; + range = &pfc->pdata->input; break; case PINMUX_TYPE_INPUT_PULLUP: - range = &pfc->input_pu; + range = &pfc->pdata->input_pu; break; case PINMUX_TYPE_INPUT_PULLDOWN: - range = &pfc->input_pd; + range = &pfc->pdata->input_pd; break; default: @@ -437,7 +432,7 @@ int sh_pfc_config_gpio(struct sh_pfc *pfc, unsigned gpio, int pinmux_type, break; /* first check if this is a function enum */ - in_range = enum_in_range(enum_id, &pfc->function); + in_range = enum_in_range(enum_id, &pfc->pdata->function); if (!in_range) { /* not a function enum */ if (range) { @@ -502,7 +497,7 @@ int sh_pfc_config_gpio(struct sh_pfc *pfc, unsigned gpio, int pinmux_type, } EXPORT_SYMBOL_GPL(sh_pfc_config_gpio); -int register_sh_pfc(struct sh_pfc *pfc) +int register_sh_pfc(struct sh_pfc_platform_data *pdata) { int (*initroutine)(struct sh_pfc *) = NULL; int ret; @@ -512,26 +507,28 @@ int register_sh_pfc(struct sh_pfc *pfc) */ BUILD_BUG_ON(PINMUX_FLAG_TYPE > ((1 << PINMUX_FLAG_DBIT_SHIFT) - 1)); - if (sh_pfc) + if (sh_pfc.pdata) return -EBUSY; - ret = pfc_ioremap(pfc); - if (unlikely(ret < 0)) + sh_pfc.pdata = pdata; + + ret = pfc_ioremap(&sh_pfc); + if (unlikely(ret < 0)) { + sh_pfc.pdata = NULL; return ret; + } - spin_lock_init(&pfc->lock); + spin_lock_init(&sh_pfc.lock); pinctrl_provide_dummies(); - setup_data_regs(pfc); - - sh_pfc = pfc; + setup_data_regs(&sh_pfc); /* * Initialize pinctrl bindings first */ initroutine = symbol_request(sh_pfc_register_pinctrl); if (initroutine) { - ret = (*initroutine)(pfc); + ret = (*initroutine)(&sh_pfc); symbol_put_addr(initroutine); if (unlikely(ret != 0)) @@ -546,7 +543,7 @@ int register_sh_pfc(struct sh_pfc *pfc) */ initroutine = symbol_request(sh_pfc_register_gpiochip); if (initroutine) { - ret = (*initroutine)(pfc); + ret = (*initroutine)(&sh_pfc); symbol_put_addr(initroutine); /* @@ -560,13 +557,13 @@ int register_sh_pfc(struct sh_pfc *pfc) } } - pr_info("%s support registered\n", pfc->name); + pr_info("%s support registered\n", sh_pfc.pdata->name); return 0; err: - pfc_iounmap(pfc); - sh_pfc = NULL; + pfc_iounmap(&sh_pfc); + sh_pfc.pdata = NULL; return ret; } diff --git a/drivers/sh/pfc/gpio.c b/drivers/sh/pfc/gpio.c index 6a24f07c201..7597a024fac 100644 --- a/drivers/sh/pfc/gpio.c +++ b/drivers/sh/pfc/gpio.c @@ -103,11 +103,11 @@ static int sh_gpio_to_irq(struct gpio_chip *gc, unsigned offset) if (pos <= 0 || !enum_id) break; - for (i = 0; i < pfc->gpio_irq_size; i++) { - enum_ids = pfc->gpio_irq[i].enum_ids; + for (i = 0; i < pfc->pdata->gpio_irq_size; i++) { + enum_ids = pfc->pdata->gpio_irq[i].enum_ids; for (k = 0; enum_ids[k]; k++) { if (enum_ids[k] == enum_id) - return pfc->gpio_irq[i].irq; + return pfc->pdata->gpio_irq[i].irq; } } } @@ -128,12 +128,12 @@ static void sh_pfc_gpio_setup(struct sh_pfc_chip *chip) gc->set = sh_gpio_set; gc->to_irq = sh_gpio_to_irq; - WARN_ON(pfc->first_gpio != 0); /* needs testing */ + WARN_ON(pfc->pdata->first_gpio != 0); /* needs testing */ - gc->label = pfc->name; + gc->label = pfc->pdata->name; gc->owner = THIS_MODULE; - gc->base = pfc->first_gpio; - gc->ngpio = (pfc->last_gpio - pfc->first_gpio) + 1; + gc->base = pfc->pdata->first_gpio; + gc->ngpio = (pfc->pdata->last_gpio - pfc->pdata->first_gpio) + 1; } int sh_pfc_register_gpiochip(struct sh_pfc *pfc) @@ -154,7 +154,8 @@ int sh_pfc_register_gpiochip(struct sh_pfc *pfc) kfree(chip); pr_info("%s handling gpio %d -> %d\n", - pfc->name, pfc->first_gpio, pfc->last_gpio); + pfc->pdata->name, pfc->pdata->first_gpio, + pfc->pdata->last_gpio); return ret; } @@ -179,7 +180,7 @@ static int sh_pfc_gpio_probe(struct platform_device *pdev) chip = gpio_to_pfc_chip(gc); platform_set_drvdata(pdev, chip); - pr_info("attaching to GPIO chip %s\n", chip->pfc->name); + pr_info("attaching to GPIO chip %s\n", chip->pfc->pdata->name); return 0; } diff --git a/drivers/sh/pfc/pinctrl.c b/drivers/sh/pfc/pinctrl.c index 4109b769eac..3a2c77d3248 100644 --- a/drivers/sh/pfc/pinctrl.c +++ b/drivers/sh/pfc/pinctrl.c @@ -140,7 +140,7 @@ static int sh_pfc_reconfig_pin(struct sh_pfc *pfc, unsigned offset, spin_lock_irqsave(&pfc->lock, flags); - pinmux_type = pfc->gpios[offset].flags & PINMUX_FLAG_TYPE; + pinmux_type = pfc->pdata->gpios[offset].flags & PINMUX_FLAG_TYPE; /* * See if the present config needs to first be de-configured. @@ -172,8 +172,8 @@ static int sh_pfc_reconfig_pin(struct sh_pfc *pfc, unsigned offset, GPIO_CFG_REQ) != 0) goto err; - pfc->gpios[offset].flags &= ~PINMUX_FLAG_TYPE; - pfc->gpios[offset].flags |= new_type; + pfc->pdata->gpios[offset].flags &= ~PINMUX_FLAG_TYPE; + pfc->pdata->gpios[offset].flags |= new_type; ret = 0; @@ -195,7 +195,7 @@ static int sh_pfc_gpio_request_enable(struct pinctrl_dev *pctldev, spin_lock_irqsave(&pfc->lock, flags); - pinmux_type = pfc->gpios[offset].flags & PINMUX_FLAG_TYPE; + pinmux_type = pfc->pdata->gpios[offset].flags & PINMUX_FLAG_TYPE; switch (pinmux_type) { case PINMUX_TYPE_FUNCTION: @@ -236,7 +236,7 @@ static void sh_pfc_gpio_disable_free(struct pinctrl_dev *pctldev, spin_lock_irqsave(&pfc->lock, flags); - pinmux_type = pfc->gpios[offset].flags & PINMUX_FLAG_TYPE; + pinmux_type = pfc->pdata->gpios[offset].flags & PINMUX_FLAG_TYPE; sh_pfc_config_gpio(pfc, offset, pinmux_type, GPIO_CFG_FREE); @@ -270,7 +270,7 @@ static int sh_pfc_pinconf_get(struct pinctrl_dev *pctldev, unsigned pin, struct sh_pfc_pinctrl *pmx = pinctrl_dev_get_drvdata(pctldev); struct sh_pfc *pfc = pmx->pfc; - *config = pfc->gpios[pin].flags & PINMUX_FLAG_TYPE; + *config = pfc->pdata->gpios[pin].flags & PINMUX_FLAG_TYPE; return 0; } @@ -356,7 +356,7 @@ static int sh_pfc_map_gpios(struct sh_pfc *pfc, struct sh_pfc_pinctrl *pmx) unsigned long flags; int i; - pmx->nr_pads = pfc->last_gpio - pfc->first_gpio + 1; + pmx->nr_pads = pfc->pdata->last_gpio - pfc->pdata->first_gpio + 1; pmx->pads = kmalloc(sizeof(struct pinctrl_pin_desc) * pmx->nr_pads, GFP_KERNEL); @@ -375,9 +375,9 @@ static int sh_pfc_map_gpios(struct sh_pfc *pfc, struct sh_pfc_pinctrl *pmx) */ for (i = 0; i < pmx->nr_pads; i++) { struct pinctrl_pin_desc *pin = pmx->pads + i; - struct pinmux_gpio *gpio = pfc->gpios + i; + struct pinmux_gpio *gpio = pfc->pdata->gpios + i; - pin->number = pfc->first_gpio + i; + pin->number = pfc->pdata->first_gpio + i; pin->name = gpio->name; /* XXX */ @@ -408,7 +408,7 @@ static int sh_pfc_map_functions(struct sh_pfc *pfc, struct sh_pfc_pinctrl *pmx) spin_lock_irqsave(&pmx->lock, flags); for (i = fn = 0; i < pmx->nr_pads; i++) { - struct pinmux_gpio *gpio = pfc->gpios + i; + struct pinmux_gpio *gpio = pfc->pdata->gpios + i; if ((gpio->flags & PINMUX_FLAG_TYPE) == PINMUX_TYPE_FUNCTION) pmx->functions[fn++] = gpio; @@ -444,9 +444,10 @@ static int sh_pfc_pinctrl_probe(struct platform_device *pdev) goto free_functions; } - sh_pfc_gpio_range.npins = pfc->last_gpio - pfc->first_gpio + 1; - sh_pfc_gpio_range.base = pfc->first_gpio; - sh_pfc_gpio_range.pin_base = pfc->first_gpio; + sh_pfc_gpio_range.npins = pfc->pdata->last_gpio + - pfc->pdata->first_gpio + 1; + sh_pfc_gpio_range.base = pfc->pdata->first_gpio; + sh_pfc_gpio_range.pin_base = pfc->pdata->first_gpio; pinctrl_add_gpio_range(sh_pfc_pmx->pctl, &sh_pfc_gpio_range); -- cgit v1.2.3 From f9165132c5ee681235068857e4f86c7ecc5a4617 Mon Sep 17 00:00:00 2001 From: Laurent Pinchart Date: Sat, 15 Dec 2012 23:50:44 +0100 Subject: sh-pfc: Move private definitions and declarations to private header Move all private structure definitions and function declarations from include/linux/sh_pfc.h to drivers/sh/pfc/core.h. Signed-off-by: Laurent Pinchart Acked-by: Paul Mundt Acked-by: Linus Walleij Signed-off-by: Simon Horman --- drivers/sh/pfc/core.c | 2 ++ drivers/sh/pfc/core.h | 44 ++++++++++++++++++++++++++++++++++++++++++++ drivers/sh/pfc/gpio.c | 2 ++ drivers/sh/pfc/pinctrl.c | 2 ++ 4 files changed, 50 insertions(+) create mode 100644 drivers/sh/pfc/core.h (limited to 'drivers/sh') diff --git a/drivers/sh/pfc/core.c b/drivers/sh/pfc/core.c index ecbe51d9f56..72421a4a883 100644 --- a/drivers/sh/pfc/core.c +++ b/drivers/sh/pfc/core.c @@ -21,6 +21,8 @@ #include #include +#include "core.h" + static struct sh_pfc sh_pfc __read_mostly; static void pfc_iounmap(struct sh_pfc *pfc) diff --git a/drivers/sh/pfc/core.h b/drivers/sh/pfc/core.h new file mode 100644 index 00000000000..b07ae259c0e --- /dev/null +++ b/drivers/sh/pfc/core.h @@ -0,0 +1,44 @@ +/* + * SuperH Pin Function Controller support. + * + * Copyright (C) 2012 Renesas Solutions Corp. + * + * This file is subject to the terms and conditions of the GNU General Public + * License. See the file "COPYING" in the main directory of this archive + * for more details. + */ +#ifndef __SH_PFC_CORE_H__ +#define __SH_PFC_CORE_H__ + +#include +#include +#include + +struct pfc_window { + phys_addr_t phys; + void __iomem *virt; + unsigned long size; +}; + +struct sh_pfc { + struct sh_pfc_platform_data *pdata; + spinlock_t lock; + + struct pfc_window *window; +}; + +int sh_pfc_register_gpiochip(struct sh_pfc *pfc); + +int sh_pfc_register_pinctrl(struct sh_pfc *pfc); + +int sh_pfc_read_bit(struct pinmux_data_reg *dr, unsigned long in_pos); +void sh_pfc_write_bit(struct pinmux_data_reg *dr, unsigned long in_pos, + unsigned long value); +int sh_pfc_get_data_reg(struct sh_pfc *pfc, unsigned gpio, + struct pinmux_data_reg **drp, int *bitp); +int sh_pfc_gpio_to_enum(struct sh_pfc *pfc, unsigned gpio, int pos, + pinmux_enum_t *enum_idp); +int sh_pfc_config_gpio(struct sh_pfc *pfc, unsigned gpio, int pinmux_type, + int cfg_mode); + +#endif /* __SH_PFC_CORE_H__ */ diff --git a/drivers/sh/pfc/gpio.c b/drivers/sh/pfc/gpio.c index 7597a024fac..565b366c909 100644 --- a/drivers/sh/pfc/gpio.c +++ b/drivers/sh/pfc/gpio.c @@ -19,6 +19,8 @@ #include #include +#include "core.h" + struct sh_pfc_chip { struct sh_pfc *pfc; struct gpio_chip gpio_chip; diff --git a/drivers/sh/pfc/pinctrl.c b/drivers/sh/pfc/pinctrl.c index 3a2c77d3248..5801a568614 100644 --- a/drivers/sh/pfc/pinctrl.c +++ b/drivers/sh/pfc/pinctrl.c @@ -24,6 +24,8 @@ #include #include +#include "core.h" + struct sh_pfc_pinctrl { struct pinctrl_dev *pctl; struct sh_pfc *pfc; -- cgit v1.2.3 From f9492fda70c87b410e61675095212dc806bdf615 Mon Sep 17 00:00:00 2001 From: Laurent Pinchart Date: Sat, 15 Dec 2012 23:50:45 +0100 Subject: sh-pfc: Merge PFC core and pinctrl The PFC core is only used by the pinctrl and gpio modules. As the gpio module depends on the pinctrl module, the pinctrl module will always be present if the core gets used. There is thus no point in keeping core and pinctrl in two seperate modules. Merge them. Signed-off-by: Laurent Pinchart Acked-by: Paul Mundt Acked-by: Linus Walleij Signed-off-by: Simon Horman --- drivers/sh/pfc/Kconfig | 10 +--------- drivers/sh/pfc/Makefile | 4 ++-- drivers/sh/pfc/core.c | 15 +++------------ drivers/sh/pfc/pinctrl.c | 3 +-- 4 files changed, 7 insertions(+), 25 deletions(-) (limited to 'drivers/sh') diff --git a/drivers/sh/pfc/Kconfig b/drivers/sh/pfc/Kconfig index 804f9ad1bf4..f33d82a38b4 100644 --- a/drivers/sh/pfc/Kconfig +++ b/drivers/sh/pfc/Kconfig @@ -5,18 +5,10 @@ config SH_PFC depends on GENERIC_GPIO select GPIO_SH_PFC if ARCH_REQUIRE_GPIOLIB select PINCTRL_SH_PFC - def_bool y - -# -# Placeholder for now, rehome to drivers/pinctrl once the PFC APIs -# have settled. -# -config PINCTRL_SH_PFC - tristate "SuperH PFC pin controller driver" - depends on SH_PFC select PINCTRL select PINMUX select PINCONF + def_bool y config GPIO_SH_PFC tristate "SuperH PFC GPIO support" diff --git a/drivers/sh/pfc/Makefile b/drivers/sh/pfc/Makefile index 7916027cce3..ce6fae35384 100644 --- a/drivers/sh/pfc/Makefile +++ b/drivers/sh/pfc/Makefile @@ -1,3 +1,3 @@ -obj-y += core.o -obj-$(CONFIG_PINCTRL_SH_PFC) += pinctrl.o +sh-pfc-objs = core.o pinctrl.o +obj-y += sh-pfc.o obj-$(CONFIG_GPIO_SH_PFC) += gpio.o diff --git a/drivers/sh/pfc/core.c b/drivers/sh/pfc/core.c index 72421a4a883..30e33db7a2d 100644 --- a/drivers/sh/pfc/core.c +++ b/drivers/sh/pfc/core.c @@ -8,7 +8,7 @@ * License. See the file "COPYING" in the main directory of this archive * for more details. */ -#define pr_fmt(fmt) "sh_pfc " KBUILD_MODNAME ": " fmt +#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt #include #include @@ -497,7 +497,6 @@ int sh_pfc_config_gpio(struct sh_pfc *pfc, unsigned gpio, int pinmux_type, out_err: return -1; } -EXPORT_SYMBOL_GPL(sh_pfc_config_gpio); int register_sh_pfc(struct sh_pfc_platform_data *pdata) { @@ -528,17 +527,9 @@ int register_sh_pfc(struct sh_pfc_platform_data *pdata) /* * Initialize pinctrl bindings first */ - initroutine = symbol_request(sh_pfc_register_pinctrl); - if (initroutine) { - ret = (*initroutine)(&sh_pfc); - symbol_put_addr(initroutine); - - if (unlikely(ret != 0)) - goto err; - } else { - pr_err("failed to initialize pinctrl bindings\n"); + ret = sh_pfc_register_pinctrl(&sh_pfc); + if (unlikely(ret != 0)) goto err; - } /* * Then the GPIO chip diff --git a/drivers/sh/pfc/pinctrl.c b/drivers/sh/pfc/pinctrl.c index 5801a568614..6f0f58bd3f8 100644 --- a/drivers/sh/pfc/pinctrl.c +++ b/drivers/sh/pfc/pinctrl.c @@ -9,7 +9,7 @@ */ #define DRV_NAME "pinctrl-sh_pfc" -#define pr_fmt(fmt) DRV_NAME " " KBUILD_MODNAME ": " fmt +#define pr_fmt(fmt) KBUILD_MODNAME " pinctrl: " fmt #include #include @@ -521,7 +521,6 @@ int sh_pfc_register_pinctrl(struct sh_pfc *pfc) return sh_pfc_pinctrl_init(); } -EXPORT_SYMBOL_GPL(sh_pfc_register_pinctrl); static void __exit sh_pfc_pinctrl_exit(void) { -- cgit v1.2.3 From 6f6a4a683be97837f3baae443aacd2b0e6162b10 Mon Sep 17 00:00:00 2001 From: Laurent Pinchart Date: Sat, 15 Dec 2012 23:50:46 +0100 Subject: sh-pfc: Merge PFC core and gpio The PFC core calls the gpio module gpiochip registration in its register_sh_pfc() function, itself called at arch initialization time. If the gpio module isn't present then the gpiochip will never be registered. As the gpio module can only be present at arch initialization time if it's builtin, there's no point in allowing to build it as a module. Make it a boolean option, and initialize it synchronously with the core if selected. Signed-off-by: Laurent Pinchart Acked-by: Paul Mundt Acked-by: Linus Walleij Signed-off-by: Simon Horman --- drivers/sh/pfc/Kconfig | 2 +- drivers/sh/pfc/Makefile | 4 ++- drivers/sh/pfc/core.c | 23 ++++++-------- drivers/sh/pfc/core.h | 4 +++ drivers/sh/pfc/gpio.c | 79 +++++-------------------------------------------- 5 files changed, 25 insertions(+), 87 deletions(-) (limited to 'drivers/sh') diff --git a/drivers/sh/pfc/Kconfig b/drivers/sh/pfc/Kconfig index f33d82a38b4..eaeabc58bb0 100644 --- a/drivers/sh/pfc/Kconfig +++ b/drivers/sh/pfc/Kconfig @@ -11,7 +11,7 @@ config SH_PFC def_bool y config GPIO_SH_PFC - tristate "SuperH PFC GPIO support" + bool "SuperH PFC GPIO support" depends on SH_PFC && GPIOLIB help This enables support for GPIOs within the SoC's pin function diff --git a/drivers/sh/pfc/Makefile b/drivers/sh/pfc/Makefile index ce6fae35384..6315cf35b34 100644 --- a/drivers/sh/pfc/Makefile +++ b/drivers/sh/pfc/Makefile @@ -1,3 +1,5 @@ sh-pfc-objs = core.o pinctrl.o +ifeq ($(CONFIG_GPIO_SH_PFC),y) +sh-pfc-objs += gpio.o +endif obj-y += sh-pfc.o -obj-$(CONFIG_GPIO_SH_PFC) += gpio.o diff --git a/drivers/sh/pfc/core.c b/drivers/sh/pfc/core.c index 30e33db7a2d..541099613a2 100644 --- a/drivers/sh/pfc/core.c +++ b/drivers/sh/pfc/core.c @@ -149,7 +149,6 @@ int sh_pfc_read_bit(struct pinmux_data_reg *dr, unsigned long in_pos) return (gpio_read_raw_reg(dr->mapped_reg, dr->reg_width) >> pos) & 1; } -EXPORT_SYMBOL_GPL(sh_pfc_read_bit); void sh_pfc_write_bit(struct pinmux_data_reg *dr, unsigned long in_pos, unsigned long value) @@ -169,7 +168,6 @@ void sh_pfc_write_bit(struct pinmux_data_reg *dr, unsigned long in_pos, gpio_write_raw_reg(dr->mapped_reg, dr->reg_width, dr->reg_shadow); } -EXPORT_SYMBOL_GPL(sh_pfc_write_bit); static void config_reg_helper(struct sh_pfc *pfc, struct pinmux_cfg_reg *crp, @@ -307,7 +305,6 @@ int sh_pfc_get_data_reg(struct sh_pfc *pfc, unsigned gpio, *bitp = n; return 0; } -EXPORT_SYMBOL_GPL(sh_pfc_get_data_reg); static int get_config_reg(struct sh_pfc *pfc, pinmux_enum_t enum_id, struct pinmux_cfg_reg **crp, @@ -384,7 +381,6 @@ int sh_pfc_gpio_to_enum(struct sh_pfc *pfc, unsigned gpio, int pos, pr_err("cannot locate data/mark enum_id for gpio %d\n", gpio); return -1; } -EXPORT_SYMBOL_GPL(sh_pfc_gpio_to_enum); int sh_pfc_config_gpio(struct sh_pfc *pfc, unsigned gpio, int pinmux_type, int cfg_mode) @@ -500,7 +496,6 @@ int sh_pfc_config_gpio(struct sh_pfc *pfc, unsigned gpio, int pinmux_type, int register_sh_pfc(struct sh_pfc_platform_data *pdata) { - int (*initroutine)(struct sh_pfc *) = NULL; int ret; /* @@ -531,24 +526,20 @@ int register_sh_pfc(struct sh_pfc_platform_data *pdata) if (unlikely(ret != 0)) goto err; +#ifdef CONFIG_GPIO_SH_PFC /* * Then the GPIO chip */ - initroutine = symbol_request(sh_pfc_register_gpiochip); - if (initroutine) { - ret = (*initroutine)(&sh_pfc); - symbol_put_addr(initroutine); - + ret = sh_pfc_register_gpiochip(&sh_pfc); + if (unlikely(ret != 0)) { /* * If the GPIO chip fails to come up we still leave the * PFC state as it is, given that there are already * extant users of it that have succeeded by this point. */ - if (unlikely(ret != 0)) { - pr_notice("failed to init GPIO chip, ignoring...\n"); - ret = 0; - } + pr_notice("failed to init GPIO chip, ignoring...\n"); } +#endif pr_info("%s support registered\n", sh_pfc.pdata->name); @@ -560,3 +551,7 @@ err: return ret; } + +MODULE_AUTHOR("Magnus Damm, Paul Mundt, Laurent Pinchart"); +MODULE_DESCRIPTION("Pin Control and GPIO driver for SuperH pin function controller"); +MODULE_LICENSE("GPL v2"); diff --git a/drivers/sh/pfc/core.h b/drivers/sh/pfc/core.h index b07ae259c0e..f3032b232fb 100644 --- a/drivers/sh/pfc/core.h +++ b/drivers/sh/pfc/core.h @@ -20,14 +20,18 @@ struct pfc_window { unsigned long size; }; +struct sh_pfc_chip; + struct sh_pfc { struct sh_pfc_platform_data *pdata; spinlock_t lock; struct pfc_window *window; + struct sh_pfc_chip *gpio; }; int sh_pfc_register_gpiochip(struct sh_pfc *pfc); +int sh_pfc_unregister_gpiochip(struct sh_pfc *pfc); int sh_pfc_register_pinctrl(struct sh_pfc *pfc); diff --git a/drivers/sh/pfc/gpio.c b/drivers/sh/pfc/gpio.c index 565b366c909..d8b0c74a950 100644 --- a/drivers/sh/pfc/gpio.c +++ b/drivers/sh/pfc/gpio.c @@ -15,7 +15,6 @@ #include #include #include -#include #include #include @@ -152,44 +151,23 @@ int sh_pfc_register_gpiochip(struct sh_pfc *pfc) sh_pfc_gpio_setup(chip); ret = gpiochip_add(&chip->gpio_chip); - if (unlikely(ret < 0)) + if (unlikely(ret < 0)) { kfree(chip); + return ret; + } + + pfc->gpio = chip; pr_info("%s handling gpio %d -> %d\n", pfc->pdata->name, pfc->pdata->first_gpio, pfc->pdata->last_gpio); - return ret; -} -EXPORT_SYMBOL_GPL(sh_pfc_register_gpiochip); - -static int sh_pfc_gpio_match(struct gpio_chip *gc, void *data) -{ - return !!strstr(gc->label, data); -} - -static int sh_pfc_gpio_probe(struct platform_device *pdev) -{ - struct sh_pfc_chip *chip; - struct gpio_chip *gc; - - gc = gpiochip_find("_pfc", sh_pfc_gpio_match); - if (unlikely(!gc)) { - pr_err("Cant find gpio chip\n"); - return -ENODEV; - } - - chip = gpio_to_pfc_chip(gc); - platform_set_drvdata(pdev, chip); - - pr_info("attaching to GPIO chip %s\n", chip->pfc->pdata->name); - return 0; } -static int sh_pfc_gpio_remove(struct platform_device *pdev) +int sh_pfc_unregister_gpiochip(struct sh_pfc *pfc) { - struct sh_pfc_chip *chip = platform_get_drvdata(pdev); + struct sh_pfc_chip *chip = pfc->gpio; int ret; ret = gpiochip_remove(&chip->gpio_chip); @@ -197,47 +175,6 @@ static int sh_pfc_gpio_remove(struct platform_device *pdev) return ret; kfree(chip); + pfc->gpio = NULL; return 0; } - -static struct platform_driver sh_pfc_gpio_driver = { - .probe = sh_pfc_gpio_probe, - .remove = sh_pfc_gpio_remove, - .driver = { - .name = KBUILD_MODNAME, - .owner = THIS_MODULE, - }, -}; - -static struct platform_device sh_pfc_gpio_device = { - .name = KBUILD_MODNAME, - .id = -1, -}; - -static int __init sh_pfc_gpio_init(void) -{ - int rc; - - rc = platform_driver_register(&sh_pfc_gpio_driver); - if (likely(!rc)) { - rc = platform_device_register(&sh_pfc_gpio_device); - if (unlikely(rc)) - platform_driver_unregister(&sh_pfc_gpio_driver); - } - - return rc; -} - -static void __exit sh_pfc_gpio_exit(void) -{ - platform_device_unregister(&sh_pfc_gpio_device); - platform_driver_unregister(&sh_pfc_gpio_driver); -} - -module_init(sh_pfc_gpio_init); -module_exit(sh_pfc_gpio_exit); - -MODULE_AUTHOR("Magnus Damm, Paul Mundt"); -MODULE_DESCRIPTION("GPIO driver for SuperH pin function controller"); -MODULE_LICENSE("GPL v2"); -MODULE_ALIAS("platform:pfc-gpio"); -- cgit v1.2.3 From c6193eacda6d50c405b0d484f5f2577ff9068a13 Mon Sep 17 00:00:00 2001 From: Laurent Pinchart Date: Sat, 15 Dec 2012 23:50:47 +0100 Subject: sh-pfc: Move platform device and driver to the core The pinctrl module registers both a platform device and a platform driver. The only purpose of this awkward construction is to have a device to pass to the pinctrl registration function. As a first step to get rid of this hack, move the platform device and driver from the pinctrl module to the core. The platform device will then be moved to arch code. Signed-off-by: Laurent Pinchart Acked-by: Paul Mundt Acked-by: Linus Walleij Signed-off-by: Simon Horman --- drivers/sh/pfc/core.c | 101 ++++++++++++++++++++++++++++++++++++++--------- drivers/sh/pfc/core.h | 4 ++ drivers/sh/pfc/gpio.c | 3 +- drivers/sh/pfc/pinctrl.c | 100 ++++++++++++---------------------------------- 4 files changed, 114 insertions(+), 94 deletions(-) (limited to 'drivers/sh') diff --git a/drivers/sh/pfc/core.c b/drivers/sh/pfc/core.c index 541099613a2..6d162e694e6 100644 --- a/drivers/sh/pfc/core.c +++ b/drivers/sh/pfc/core.c @@ -8,6 +8,8 @@ * License. See the file "COPYING" in the main directory of this archive * for more details. */ + +#define DRV_NAME "sh-pfc" #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt #include @@ -20,11 +22,10 @@ #include #include #include +#include #include "core.h" -static struct sh_pfc sh_pfc __read_mostly; - static void pfc_iounmap(struct sh_pfc *pfc) { int k; @@ -494,8 +495,10 @@ int sh_pfc_config_gpio(struct sh_pfc *pfc, unsigned gpio, int pinmux_type, return -1; } -int register_sh_pfc(struct sh_pfc_platform_data *pdata) +static int sh_pfc_probe(struct platform_device *pdev) { + struct sh_pfc_platform_data *pdata = pdev->dev.platform_data; + struct sh_pfc *pfc; int ret; /* @@ -503,26 +506,29 @@ int register_sh_pfc(struct sh_pfc_platform_data *pdata) */ BUILD_BUG_ON(PINMUX_FLAG_TYPE > ((1 << PINMUX_FLAG_DBIT_SHIFT) - 1)); - if (sh_pfc.pdata) - return -EBUSY; + if (pdata == NULL) + return -ENODEV; - sh_pfc.pdata = pdata; + pfc = devm_kzalloc(&pdev->dev, sizeof(pfc), GFP_KERNEL); + if (pfc == NULL) + return -ENOMEM; - ret = pfc_ioremap(&sh_pfc); - if (unlikely(ret < 0)) { - sh_pfc.pdata = NULL; + pfc->pdata = pdata; + pfc->dev = &pdev->dev; + + ret = pfc_ioremap(pfc); + if (unlikely(ret < 0)) return ret; - } - spin_lock_init(&sh_pfc.lock); + spin_lock_init(&pfc->lock); pinctrl_provide_dummies(); - setup_data_regs(&sh_pfc); + setup_data_regs(pfc); /* * Initialize pinctrl bindings first */ - ret = sh_pfc_register_pinctrl(&sh_pfc); + ret = sh_pfc_register_pinctrl(pfc); if (unlikely(ret != 0)) goto err; @@ -530,7 +536,7 @@ int register_sh_pfc(struct sh_pfc_platform_data *pdata) /* * Then the GPIO chip */ - ret = sh_pfc_register_gpiochip(&sh_pfc); + ret = sh_pfc_register_gpiochip(pfc); if (unlikely(ret != 0)) { /* * If the GPIO chip fails to come up we still leave the @@ -541,17 +547,76 @@ int register_sh_pfc(struct sh_pfc_platform_data *pdata) } #endif - pr_info("%s support registered\n", sh_pfc.pdata->name); + platform_set_drvdata(pdev, pfc); + + pr_info("%s support registered\n", pdata->name); return 0; err: - pfc_iounmap(&sh_pfc); - sh_pfc.pdata = NULL; - + pfc_iounmap(pfc); return ret; } +static int sh_pfc_remove(struct platform_device *pdev) +{ + struct sh_pfc *pfc = platform_get_drvdata(pdev); + +#ifdef CONFIG_GPIO_SH_PFC + sh_pfc_unregister_gpiochip(pfc); +#endif + sh_pfc_unregister_pinctrl(pfc); + + pfc_iounmap(pfc); + + platform_set_drvdata(pdev, NULL); + + return 0; +} + +static const struct platform_device_id sh_pfc_id_table[] = { + { "sh-pfc", 0 }, + { }, +}; +MODULE_DEVICE_TABLE(platform, sh_pfc_id_table); + +static struct platform_driver sh_pfc_driver = { + .probe = sh_pfc_probe, + .remove = sh_pfc_remove, + .id_table = sh_pfc_id_table, + .driver = { + .name = DRV_NAME, + .owner = THIS_MODULE, + }, +}; + +static struct platform_device sh_pfc_device = { + .name = DRV_NAME, + .id = -1, +}; + +int __init register_sh_pfc(struct sh_pfc_platform_data *pdata) +{ + int rc; + + sh_pfc_device.dev.platform_data = pdata; + + rc = platform_driver_register(&sh_pfc_driver); + if (likely(!rc)) { + rc = platform_device_register(&sh_pfc_device); + if (unlikely(rc)) + platform_driver_unregister(&sh_pfc_driver); + } + + return rc; +} + +static void __exit sh_pfc_exit(void) +{ + platform_driver_unregister(&sh_pfc_driver); +} +module_exit(sh_pfc_exit); + MODULE_AUTHOR("Magnus Damm, Paul Mundt, Laurent Pinchart"); MODULE_DESCRIPTION("Pin Control and GPIO driver for SuperH pin function controller"); MODULE_LICENSE("GPL v2"); diff --git a/drivers/sh/pfc/core.h b/drivers/sh/pfc/core.h index f3032b232fb..1287b3e6222 100644 --- a/drivers/sh/pfc/core.h +++ b/drivers/sh/pfc/core.h @@ -21,19 +21,23 @@ struct pfc_window { }; struct sh_pfc_chip; +struct sh_pfc_pinctrl; struct sh_pfc { + struct device *dev; struct sh_pfc_platform_data *pdata; spinlock_t lock; struct pfc_window *window; struct sh_pfc_chip *gpio; + struct sh_pfc_pinctrl *pinctrl; }; int sh_pfc_register_gpiochip(struct sh_pfc *pfc); int sh_pfc_unregister_gpiochip(struct sh_pfc *pfc); int sh_pfc_register_pinctrl(struct sh_pfc *pfc); +int sh_pfc_unregister_pinctrl(struct sh_pfc *pfc); int sh_pfc_read_bit(struct pinmux_data_reg *dr, unsigned long in_pos); void sh_pfc_write_bit(struct pinmux_data_reg *dr, unsigned long in_pos, diff --git a/drivers/sh/pfc/gpio.c b/drivers/sh/pfc/gpio.c index d8b0c74a950..a32ea8083b9 100644 --- a/drivers/sh/pfc/gpio.c +++ b/drivers/sh/pfc/gpio.c @@ -8,7 +8,8 @@ * License. See the file "COPYING" in the main directory of this archive * for more details. */ -#define pr_fmt(fmt) "sh_pfc " KBUILD_MODNAME ": " fmt + +#define pr_fmt(fmt) KBUILD_MODNAME " gpio: " fmt #include #include diff --git a/drivers/sh/pfc/pinctrl.c b/drivers/sh/pfc/pinctrl.c index 6f0f58bd3f8..2fc873137ce 100644 --- a/drivers/sh/pfc/pinctrl.c +++ b/drivers/sh/pfc/pinctrl.c @@ -7,8 +7,8 @@ * License. See the file "COPYING" in the main directory of this archive * for more details. */ -#define DRV_NAME "pinctrl-sh_pfc" +#define DRV_NAME "sh-pfc" #define pr_fmt(fmt) KBUILD_MODNAME " pinctrl: " fmt #include @@ -17,7 +17,6 @@ #include #include #include -#include #include #include #include @@ -39,8 +38,6 @@ struct sh_pfc_pinctrl { spinlock_t lock; }; -static struct sh_pfc_pinctrl *sh_pfc_pmx; - static int sh_pfc_get_groups_count(struct pinctrl_dev *pctldev) { struct sh_pfc_pinctrl *pmx = pinctrl_dev_get_drvdata(pctldev); @@ -421,28 +418,31 @@ static int sh_pfc_map_functions(struct sh_pfc *pfc, struct sh_pfc_pinctrl *pmx) return 0; } -static int sh_pfc_pinctrl_probe(struct platform_device *pdev) +int sh_pfc_register_pinctrl(struct sh_pfc *pfc) { - struct sh_pfc *pfc; + struct sh_pfc_pinctrl *pmx; int ret; - if (unlikely(!sh_pfc_pmx)) - return -ENODEV; + pmx = kzalloc(sizeof(struct sh_pfc_pinctrl), GFP_KERNEL); + if (unlikely(!pmx)) + return -ENOMEM; + + spin_lock_init(&pmx->lock); - pfc = sh_pfc_pmx->pfc; + pmx->pfc = pfc; + pfc->pinctrl = pmx; - ret = sh_pfc_map_gpios(pfc, sh_pfc_pmx); + ret = sh_pfc_map_gpios(pfc, pmx); if (unlikely(ret != 0)) return ret; - ret = sh_pfc_map_functions(pfc, sh_pfc_pmx); + ret = sh_pfc_map_functions(pfc, pmx); if (unlikely(ret != 0)) goto free_pads; - sh_pfc_pmx->pctl = pinctrl_register(&sh_pfc_pinctrl_desc, &pdev->dev, - sh_pfc_pmx); - if (IS_ERR(sh_pfc_pmx->pctl)) { - ret = PTR_ERR(sh_pfc_pmx->pctl); + pmx->pctl = pinctrl_register(&sh_pfc_pinctrl_desc, pfc->dev, pmx); + if (IS_ERR(pmx->pctl)) { + ret = PTR_ERR(pmx->pctl); goto free_functions; } @@ -451,79 +451,29 @@ static int sh_pfc_pinctrl_probe(struct platform_device *pdev) sh_pfc_gpio_range.base = pfc->pdata->first_gpio; sh_pfc_gpio_range.pin_base = pfc->pdata->first_gpio; - pinctrl_add_gpio_range(sh_pfc_pmx->pctl, &sh_pfc_gpio_range); - - platform_set_drvdata(pdev, sh_pfc_pmx); + pinctrl_add_gpio_range(pmx->pctl, &sh_pfc_gpio_range); return 0; free_functions: - kfree(sh_pfc_pmx->functions); + kfree(pmx->functions); free_pads: - kfree(sh_pfc_pmx->pads); - kfree(sh_pfc_pmx); + kfree(pmx->pads); + kfree(pmx); return ret; } -static int sh_pfc_pinctrl_remove(struct platform_device *pdev) +int sh_pfc_unregister_pinctrl(struct sh_pfc *pfc) { - struct sh_pfc_pinctrl *pmx = platform_get_drvdata(pdev); + struct sh_pfc_pinctrl *pmx = pfc->pinctrl; pinctrl_unregister(pmx->pctl); - platform_set_drvdata(pdev, NULL); - - kfree(sh_pfc_pmx->functions); - kfree(sh_pfc_pmx->pads); - kfree(sh_pfc_pmx); + kfree(pmx->functions); + kfree(pmx->pads); + kfree(pmx); + pfc->pinctrl = NULL; return 0; } - -static struct platform_driver sh_pfc_pinctrl_driver = { - .probe = sh_pfc_pinctrl_probe, - .remove = sh_pfc_pinctrl_remove, - .driver = { - .name = DRV_NAME, - .owner = THIS_MODULE, - }, -}; - -static struct platform_device sh_pfc_pinctrl_device = { - .name = DRV_NAME, - .id = -1, -}; - -static int sh_pfc_pinctrl_init(void) -{ - int rc; - - rc = platform_driver_register(&sh_pfc_pinctrl_driver); - if (likely(!rc)) { - rc = platform_device_register(&sh_pfc_pinctrl_device); - if (unlikely(rc)) - platform_driver_unregister(&sh_pfc_pinctrl_driver); - } - - return rc; -} - -int sh_pfc_register_pinctrl(struct sh_pfc *pfc) -{ - sh_pfc_pmx = kzalloc(sizeof(struct sh_pfc_pinctrl), GFP_KERNEL); - if (unlikely(!sh_pfc_pmx)) - return -ENOMEM; - - spin_lock_init(&sh_pfc_pmx->lock); - - sh_pfc_pmx->pfc = pfc; - - return sh_pfc_pinctrl_init(); -} - -static void __exit sh_pfc_pinctrl_exit(void) -{ - platform_driver_unregister(&sh_pfc_pinctrl_driver); -} -module_exit(sh_pfc_pinctrl_exit); -- cgit v1.2.3 From 1724acfd598bdf688218bdd26a5f02dd55b6ec62 Mon Sep 17 00:00:00 2001 From: Laurent Pinchart Date: Sat, 15 Dec 2012 23:50:48 +0100 Subject: sh-pfc: Use devm_kzalloc() Replace probe-time kmalloc()/kzalloc() calls with devm_kzalloc() and get rid of the corresponding kfree() calls. Signed-off-by: Laurent Pinchart Acked-by: Linus Walleij Signed-off-by: Simon Horman --- drivers/sh/pfc/core.c | 20 +++++++------------- drivers/sh/pfc/gpio.c | 8 +++----- drivers/sh/pfc/pinctrl.c | 31 +++++++++---------------------- 3 files changed, 19 insertions(+), 40 deletions(-) (limited to 'drivers/sh') diff --git a/drivers/sh/pfc/core.c b/drivers/sh/pfc/core.c index 6d162e694e6..54919026ac1 100644 --- a/drivers/sh/pfc/core.c +++ b/drivers/sh/pfc/core.c @@ -33,9 +33,6 @@ static void pfc_iounmap(struct sh_pfc *pfc) for (k = 0; k < pfc->pdata->num_resources; k++) if (pfc->window[k].virt) iounmap(pfc->window[k].virt); - - kfree(pfc->window); - pfc->window = NULL; } static int pfc_ioremap(struct sh_pfc *pfc) @@ -46,10 +43,10 @@ static int pfc_ioremap(struct sh_pfc *pfc) if (!pfc->pdata->num_resources) return 0; - pfc->window = kzalloc(pfc->pdata->num_resources * sizeof(*pfc->window), - GFP_NOWAIT); + pfc->window = devm_kzalloc(pfc->dev, pfc->pdata->num_resources * + sizeof(*pfc->window), GFP_NOWAIT); if (!pfc->window) - goto err1; + return -ENOMEM; for (k = 0; k < pfc->pdata->num_resources; k++) { res = pfc->pdata->resource + k; @@ -58,16 +55,13 @@ static int pfc_ioremap(struct sh_pfc *pfc) pfc->window[k].size = resource_size(res); pfc->window[k].virt = ioremap_nocache(res->start, resource_size(res)); - if (!pfc->window[k].virt) - goto err2; + if (!pfc->window[k].virt) { + pfc_iounmap(pfc); + return -ENOMEM; + } } return 0; - -err2: - pfc_iounmap(pfc); -err1: - return -1; } static void __iomem *pfc_phys_to_virt(struct sh_pfc *pfc, diff --git a/drivers/sh/pfc/gpio.c b/drivers/sh/pfc/gpio.c index a32ea8083b9..37493e5fe2e 100644 --- a/drivers/sh/pfc/gpio.c +++ b/drivers/sh/pfc/gpio.c @@ -11,6 +11,7 @@ #define pr_fmt(fmt) KBUILD_MODNAME " gpio: " fmt +#include #include #include #include @@ -143,7 +144,7 @@ int sh_pfc_register_gpiochip(struct sh_pfc *pfc) struct sh_pfc_chip *chip; int ret; - chip = kzalloc(sizeof(struct sh_pfc_chip), GFP_KERNEL); + chip = devm_kzalloc(pfc->dev, sizeof(*chip), GFP_KERNEL); if (unlikely(!chip)) return -ENOMEM; @@ -152,10 +153,8 @@ int sh_pfc_register_gpiochip(struct sh_pfc *pfc) sh_pfc_gpio_setup(chip); ret = gpiochip_add(&chip->gpio_chip); - if (unlikely(ret < 0)) { - kfree(chip); + if (unlikely(ret < 0)) return ret; - } pfc->gpio = chip; @@ -175,7 +174,6 @@ int sh_pfc_unregister_gpiochip(struct sh_pfc *pfc) if (unlikely(ret < 0)) return ret; - kfree(chip); pfc->gpio = NULL; return 0; } diff --git a/drivers/sh/pfc/pinctrl.c b/drivers/sh/pfc/pinctrl.c index 2fc873137ce..b3dbefd5658 100644 --- a/drivers/sh/pfc/pinctrl.c +++ b/drivers/sh/pfc/pinctrl.c @@ -11,6 +11,7 @@ #define DRV_NAME "sh-pfc" #define pr_fmt(fmt) KBUILD_MODNAME " pinctrl: " fmt +#include #include #include #include @@ -357,8 +358,8 @@ static int sh_pfc_map_gpios(struct sh_pfc *pfc, struct sh_pfc_pinctrl *pmx) pmx->nr_pads = pfc->pdata->last_gpio - pfc->pdata->first_gpio + 1; - pmx->pads = kmalloc(sizeof(struct pinctrl_pin_desc) * pmx->nr_pads, - GFP_KERNEL); + pmx->pads = devm_kzalloc(pfc->dev, sizeof(*pmx->pads) * pmx->nr_pads, + GFP_KERNEL); if (unlikely(!pmx->pads)) { pmx->nr_pads = 0; return -ENOMEM; @@ -399,8 +400,8 @@ static int sh_pfc_map_functions(struct sh_pfc *pfc, struct sh_pfc_pinctrl *pmx) unsigned long flags; int i, fn; - pmx->functions = kzalloc(pmx->nr_functions * sizeof(void *), - GFP_KERNEL); + pmx->functions = devm_kzalloc(pfc->dev, pmx->nr_functions * + sizeof(*pmx->functions), GFP_KERNEL); if (unlikely(!pmx->functions)) return -ENOMEM; @@ -423,7 +424,7 @@ int sh_pfc_register_pinctrl(struct sh_pfc *pfc) struct sh_pfc_pinctrl *pmx; int ret; - pmx = kzalloc(sizeof(struct sh_pfc_pinctrl), GFP_KERNEL); + pmx = devm_kzalloc(pfc->dev, sizeof(*pmx), GFP_KERNEL); if (unlikely(!pmx)) return -ENOMEM; @@ -438,13 +439,11 @@ int sh_pfc_register_pinctrl(struct sh_pfc *pfc) ret = sh_pfc_map_functions(pfc, pmx); if (unlikely(ret != 0)) - goto free_pads; + return ret; pmx->pctl = pinctrl_register(&sh_pfc_pinctrl_desc, pfc->dev, pmx); - if (IS_ERR(pmx->pctl)) { - ret = PTR_ERR(pmx->pctl); - goto free_functions; - } + if (IS_ERR(pmx->pctl)) + return PTR_ERR(pmx->pctl); sh_pfc_gpio_range.npins = pfc->pdata->last_gpio - pfc->pdata->first_gpio + 1; @@ -454,14 +453,6 @@ int sh_pfc_register_pinctrl(struct sh_pfc *pfc) pinctrl_add_gpio_range(pmx->pctl, &sh_pfc_gpio_range); return 0; - -free_functions: - kfree(pmx->functions); -free_pads: - kfree(pmx->pads); - kfree(pmx); - - return ret; } int sh_pfc_unregister_pinctrl(struct sh_pfc *pfc) @@ -470,10 +461,6 @@ int sh_pfc_unregister_pinctrl(struct sh_pfc *pfc) pinctrl_unregister(pmx->pctl); - kfree(pmx->functions); - kfree(pmx->pads); - kfree(pmx); - pfc->pinctrl = NULL; return 0; } -- cgit v1.2.3 From c9fa88e23a8c6d1a72ba37c7d4df3d05051e8e8e Mon Sep 17 00:00:00 2001 From: Laurent Pinchart Date: Sat, 15 Dec 2012 23:50:49 +0100 Subject: sh-pfc: Use devm_ioremap_nocache() Replace probe-time ioremap_nocache() call with devm_ioremap_nocache() and get rid of the corresponding iounmap() call. Signed-off-by: Laurent Pinchart Acked-by: Linus Walleij Signed-off-by: Simon Horman --- drivers/sh/pfc/core.c | 25 ++++--------------------- 1 file changed, 4 insertions(+), 21 deletions(-) (limited to 'drivers/sh') diff --git a/drivers/sh/pfc/core.c b/drivers/sh/pfc/core.c index 54919026ac1..8ec57bd5b1f 100644 --- a/drivers/sh/pfc/core.c +++ b/drivers/sh/pfc/core.c @@ -26,15 +26,6 @@ #include "core.h" -static void pfc_iounmap(struct sh_pfc *pfc) -{ - int k; - - for (k = 0; k < pfc->pdata->num_resources; k++) - if (pfc->window[k].virt) - iounmap(pfc->window[k].virt); -} - static int pfc_ioremap(struct sh_pfc *pfc) { struct resource *res; @@ -53,12 +44,10 @@ static int pfc_ioremap(struct sh_pfc *pfc) WARN_ON(resource_type(res) != IORESOURCE_MEM); pfc->window[k].phys = res->start; pfc->window[k].size = resource_size(res); - pfc->window[k].virt = ioremap_nocache(res->start, - resource_size(res)); - if (!pfc->window[k].virt) { - pfc_iounmap(pfc); + pfc->window[k].virt = devm_ioremap_nocache(pfc->dev, res->start, + resource_size(res)); + if (!pfc->window[k].virt) return -ENOMEM; - } } return 0; @@ -524,7 +513,7 @@ static int sh_pfc_probe(struct platform_device *pdev) */ ret = sh_pfc_register_pinctrl(pfc); if (unlikely(ret != 0)) - goto err; + return ret; #ifdef CONFIG_GPIO_SH_PFC /* @@ -546,10 +535,6 @@ static int sh_pfc_probe(struct platform_device *pdev) pr_info("%s support registered\n", pdata->name); return 0; - -err: - pfc_iounmap(pfc); - return ret; } static int sh_pfc_remove(struct platform_device *pdev) @@ -561,8 +546,6 @@ static int sh_pfc_remove(struct platform_device *pdev) #endif sh_pfc_unregister_pinctrl(pfc); - pfc_iounmap(pfc); - platform_set_drvdata(pdev, NULL); return 0; -- cgit v1.2.3 From 4a2e0d18f95e1ec2b264f66e7cedec7f3dc54b44 Mon Sep 17 00:00:00 2001 From: Laurent Pinchart Date: Sat, 15 Dec 2012 23:50:50 +0100 Subject: sh-pfc: Let the compiler decide whether to inline functions The compiler should be smart enough to automatically inline static functions that are called from a single location. Signed-off-by: Laurent Pinchart Acked-by: Paul Mundt Acked-by: Linus Walleij Signed-off-by: Simon Horman --- drivers/sh/pfc/pinctrl.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'drivers/sh') diff --git a/drivers/sh/pfc/pinctrl.c b/drivers/sh/pfc/pinctrl.c index b3dbefd5658..47dbd023109 100644 --- a/drivers/sh/pfc/pinctrl.c +++ b/drivers/sh/pfc/pinctrl.c @@ -116,7 +116,7 @@ static void sh_pfc_noop_disable(struct pinctrl_dev *pctldev, unsigned func, { } -static inline int sh_pfc_config_function(struct sh_pfc *pfc, unsigned offset) +static int sh_pfc_config_function(struct sh_pfc *pfc, unsigned offset) { if (sh_pfc_config_gpio(pfc, offset, PINMUX_TYPE_FUNCTION, @@ -328,10 +328,8 @@ static struct pinctrl_desc sh_pfc_pinctrl_desc = { .confops = &sh_pfc_pinconf_ops, }; -static inline void sh_pfc_map_one_gpio(struct sh_pfc *pfc, - struct sh_pfc_pinctrl *pmx, - struct pinmux_gpio *gpio, - unsigned offset) +static void sh_pfc_map_one_gpio(struct sh_pfc *pfc, struct sh_pfc_pinctrl *pmx, + struct pinmux_gpio *gpio, unsigned offset) { struct pinmux_data_reg *dummy; unsigned long flags; -- cgit v1.2.3 From a99ebec16c0586ec0838558fd1a050801037ebc9 Mon Sep 17 00:00:00 2001 From: Laurent Pinchart Date: Sat, 15 Dec 2012 23:50:51 +0100 Subject: sh-pfc: Remove check for impossible error condition The pfc pointer can't be NULL in the get and set value functions, remove the error check. Signed-off-by: Laurent Pinchart Acked-by: Paul Mundt Acked-by: Linus Walleij Signed-off-by: Simon Horman --- drivers/sh/pfc/gpio.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'drivers/sh') diff --git a/drivers/sh/pfc/gpio.c b/drivers/sh/pfc/gpio.c index 37493e5fe2e..c11c1bb97c7 100644 --- a/drivers/sh/pfc/gpio.c +++ b/drivers/sh/pfc/gpio.c @@ -52,7 +52,7 @@ static void sh_gpio_set_value(struct sh_pfc *pfc, unsigned gpio, int value) struct pinmux_data_reg *dr = NULL; int bit = 0; - if (!pfc || sh_pfc_get_data_reg(pfc, gpio, &dr, &bit) != 0) + if (sh_pfc_get_data_reg(pfc, gpio, &dr, &bit) != 0) BUG(); else sh_pfc_write_bit(dr, bit, value); @@ -63,7 +63,7 @@ static int sh_gpio_get_value(struct sh_pfc *pfc, unsigned gpio) struct pinmux_data_reg *dr = NULL; int bit = 0; - if (!pfc || sh_pfc_get_data_reg(pfc, gpio, &dr, &bit) != 0) + if (sh_pfc_get_data_reg(pfc, gpio, &dr, &bit) != 0) return -EINVAL; return sh_pfc_read_bit(dr, bit); -- cgit v1.2.3 From 90efde223d2ab5ab84008986d97df0f01a49f15f Mon Sep 17 00:00:00 2001 From: Laurent Pinchart Date: Sat, 15 Dec 2012 23:50:52 +0100 Subject: sh-pfc: Sort headers alphabetically Signed-off-by: Laurent Pinchart Acked-by: Paul Mundt Acked-by: Linus Walleij Signed-off-by: Simon Horman --- drivers/sh/pfc/core.c | 12 ++++++------ drivers/sh/pfc/gpio.c | 6 +++--- drivers/sh/pfc/pinctrl.c | 12 ++++++------ 3 files changed, 15 insertions(+), 15 deletions(-) (limited to 'drivers/sh') diff --git a/drivers/sh/pfc/core.c b/drivers/sh/pfc/core.c index 8ec57bd5b1f..ccf4b7a7cef 100644 --- a/drivers/sh/pfc/core.c +++ b/drivers/sh/pfc/core.c @@ -12,17 +12,17 @@ #define DRV_NAME "sh-pfc" #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt -#include -#include -#include -#include +#include #include +#include #include -#include -#include #include +#include +#include #include #include +#include +#include #include "core.h" diff --git a/drivers/sh/pfc/gpio.c b/drivers/sh/pfc/gpio.c index c11c1bb97c7..a0454f32171 100644 --- a/drivers/sh/pfc/gpio.c +++ b/drivers/sh/pfc/gpio.c @@ -12,13 +12,13 @@ #define pr_fmt(fmt) KBUILD_MODNAME " gpio: " fmt #include -#include #include -#include -#include +#include #include #include #include +#include +#include #include "core.h" diff --git a/drivers/sh/pfc/pinctrl.c b/drivers/sh/pfc/pinctrl.c index 47dbd023109..221bde03913 100644 --- a/drivers/sh/pfc/pinctrl.c +++ b/drivers/sh/pfc/pinctrl.c @@ -12,17 +12,17 @@ #define pr_fmt(fmt) KBUILD_MODNAME " pinctrl: " fmt #include +#include #include #include -#include -#include -#include -#include #include -#include #include -#include #include +#include +#include +#include +#include +#include #include "core.h" -- cgit v1.2.3 From 4aeacd5bd5c354c1b36bfe3d5d72806ecd9605a0 Mon Sep 17 00:00:00 2001 From: Laurent Pinchart Date: Sat, 15 Dec 2012 23:50:53 +0100 Subject: sh-pfc: Use sh_pfc_ namespace prefix through the whole driver Most of the function and structure names are prefixed by sh_pfc_. Fix the ones that are not to avoid namespace clashes (especially for functions that start with gpio_). Not included in this patch are the platform data structures, those will be reworked later. Signed-off-by: Laurent Pinchart Acked-by: Linus Walleij Signed-off-by: Simon Horman --- drivers/sh/pfc/core.c | 107 +++++++++++++++++++++++++------------------------- drivers/sh/pfc/core.h | 4 +- 2 files changed, 55 insertions(+), 56 deletions(-) (limited to 'drivers/sh') diff --git a/drivers/sh/pfc/core.c b/drivers/sh/pfc/core.c index ccf4b7a7cef..1bb38e8b36a 100644 --- a/drivers/sh/pfc/core.c +++ b/drivers/sh/pfc/core.c @@ -26,7 +26,7 @@ #include "core.h" -static int pfc_ioremap(struct sh_pfc *pfc) +static int sh_pfc_ioremap(struct sh_pfc *pfc) { struct resource *res; int k; @@ -53,10 +53,10 @@ static int pfc_ioremap(struct sh_pfc *pfc) return 0; } -static void __iomem *pfc_phys_to_virt(struct sh_pfc *pfc, - unsigned long address) +static void __iomem *sh_pfc_phys_to_virt(struct sh_pfc *pfc, + unsigned long address) { - struct pfc_window *window; + struct sh_pfc_window *window; int k; /* scan through physical windows and convert address */ @@ -76,7 +76,7 @@ static void __iomem *pfc_phys_to_virt(struct sh_pfc *pfc, return (void __iomem *)address; } -static int enum_in_range(pinmux_enum_t enum_id, struct pinmux_range *r) +static int sh_pfc_enum_in_range(pinmux_enum_t enum_id, struct pinmux_range *r) { if (enum_id < r->begin) return 0; @@ -87,8 +87,8 @@ static int enum_in_range(pinmux_enum_t enum_id, struct pinmux_range *r) return 1; } -static unsigned long gpio_read_raw_reg(void __iomem *mapped_reg, - unsigned long reg_width) +static unsigned long sh_pfc_read_raw_reg(void __iomem *mapped_reg, + unsigned long reg_width) { switch (reg_width) { case 8: @@ -103,9 +103,8 @@ static unsigned long gpio_read_raw_reg(void __iomem *mapped_reg, return 0; } -static void gpio_write_raw_reg(void __iomem *mapped_reg, - unsigned long reg_width, - unsigned long data) +static void sh_pfc_write_raw_reg(void __iomem *mapped_reg, + unsigned long reg_width, unsigned long data) { switch (reg_width) { case 8: @@ -131,7 +130,7 @@ int sh_pfc_read_bit(struct pinmux_data_reg *dr, unsigned long in_pos) pr_debug("read_bit: addr = %lx, pos = %ld, " "r_width = %ld\n", dr->reg, pos, dr->reg_width); - return (gpio_read_raw_reg(dr->mapped_reg, dr->reg_width) >> pos) & 1; + return (sh_pfc_read_raw_reg(dr->mapped_reg, dr->reg_width) >> pos) & 1; } void sh_pfc_write_bit(struct pinmux_data_reg *dr, unsigned long in_pos, @@ -150,19 +149,19 @@ void sh_pfc_write_bit(struct pinmux_data_reg *dr, unsigned long in_pos, else clear_bit(pos, &dr->reg_shadow); - gpio_write_raw_reg(dr->mapped_reg, dr->reg_width, dr->reg_shadow); + sh_pfc_write_raw_reg(dr->mapped_reg, dr->reg_width, dr->reg_shadow); } -static void config_reg_helper(struct sh_pfc *pfc, - struct pinmux_cfg_reg *crp, - unsigned long in_pos, - void __iomem **mapped_regp, - unsigned long *maskp, - unsigned long *posp) +static void sh_pfc_config_reg_helper(struct sh_pfc *pfc, + struct pinmux_cfg_reg *crp, + unsigned long in_pos, + void __iomem **mapped_regp, + unsigned long *maskp, + unsigned long *posp) { int k; - *mapped_regp = pfc_phys_to_virt(pfc, crp->reg); + *mapped_regp = sh_pfc_phys_to_virt(pfc, crp->reg); if (crp->field_width) { *maskp = (1 << crp->field_width) - 1; @@ -175,30 +174,30 @@ static void config_reg_helper(struct sh_pfc *pfc, } } -static int read_config_reg(struct sh_pfc *pfc, - struct pinmux_cfg_reg *crp, - unsigned long field) +static int sh_pfc_read_config_reg(struct sh_pfc *pfc, + struct pinmux_cfg_reg *crp, + unsigned long field) { void __iomem *mapped_reg; unsigned long mask, pos; - config_reg_helper(pfc, crp, field, &mapped_reg, &mask, &pos); + sh_pfc_config_reg_helper(pfc, crp, field, &mapped_reg, &mask, &pos); pr_debug("read_reg: addr = %lx, field = %ld, " "r_width = %ld, f_width = %ld\n", crp->reg, field, crp->reg_width, crp->field_width); - return (gpio_read_raw_reg(mapped_reg, crp->reg_width) >> pos) & mask; + return (sh_pfc_read_raw_reg(mapped_reg, crp->reg_width) >> pos) & mask; } -static void write_config_reg(struct sh_pfc *pfc, - struct pinmux_cfg_reg *crp, - unsigned long field, unsigned long value) +static void sh_pfc_write_config_reg(struct sh_pfc *pfc, + struct pinmux_cfg_reg *crp, + unsigned long field, unsigned long value) { void __iomem *mapped_reg; unsigned long mask, pos, data; - config_reg_helper(pfc, crp, field, &mapped_reg, &mask, &pos); + sh_pfc_config_reg_helper(pfc, crp, field, &mapped_reg, &mask, &pos); pr_debug("write_reg addr = %lx, value = %ld, field = %ld, " "r_width = %ld, f_width = %ld\n", @@ -207,24 +206,25 @@ static void write_config_reg(struct sh_pfc *pfc, mask = ~(mask << pos); value = value << pos; - data = gpio_read_raw_reg(mapped_reg, crp->reg_width); + data = sh_pfc_read_raw_reg(mapped_reg, crp->reg_width); data &= mask; data |= value; if (pfc->pdata->unlock_reg) - gpio_write_raw_reg(pfc_phys_to_virt(pfc, pfc->pdata->unlock_reg), - 32, ~data); + sh_pfc_write_raw_reg( + sh_pfc_phys_to_virt(pfc, pfc->pdata->unlock_reg), 32, + ~data); - gpio_write_raw_reg(mapped_reg, crp->reg_width, data); + sh_pfc_write_raw_reg(mapped_reg, crp->reg_width, data); } -static int setup_data_reg(struct sh_pfc *pfc, unsigned gpio) +static int sh_pfc_setup_data_reg(struct sh_pfc *pfc, unsigned gpio) { struct pinmux_gpio *gpiop = &pfc->pdata->gpios[gpio]; struct pinmux_data_reg *data_reg; int k, n; - if (!enum_in_range(gpiop->enum_id, &pfc->pdata->data)) + if (!sh_pfc_enum_in_range(gpiop->enum_id, &pfc->pdata->data)) return -1; k = 0; @@ -234,7 +234,7 @@ static int setup_data_reg(struct sh_pfc *pfc, unsigned gpio) if (!data_reg->reg_width) break; - data_reg->mapped_reg = pfc_phys_to_virt(pfc, data_reg->reg); + data_reg->mapped_reg = sh_pfc_phys_to_virt(pfc, data_reg->reg); for (n = 0; n < data_reg->reg_width; n++) { if (data_reg->enum_ids[n] == gpiop->enum_id) { @@ -253,13 +253,13 @@ static int setup_data_reg(struct sh_pfc *pfc, unsigned gpio) return -1; } -static void setup_data_regs(struct sh_pfc *pfc) +static void sh_pfc_setup_data_regs(struct sh_pfc *pfc) { struct pinmux_data_reg *drp; int k; for (k = pfc->pdata->first_gpio; k <= pfc->pdata->last_gpio; k++) - setup_data_reg(pfc, k); + sh_pfc_setup_data_reg(pfc, k); k = 0; while (1) { @@ -268,8 +268,8 @@ static void setup_data_regs(struct sh_pfc *pfc) if (!drp->reg_width) break; - drp->reg_shadow = gpio_read_raw_reg(drp->mapped_reg, - drp->reg_width); + drp->reg_shadow = sh_pfc_read_raw_reg(drp->mapped_reg, + drp->reg_width); k++; } } @@ -280,7 +280,7 @@ int sh_pfc_get_data_reg(struct sh_pfc *pfc, unsigned gpio, struct pinmux_gpio *gpiop = &pfc->pdata->gpios[gpio]; int k, n; - if (!enum_in_range(gpiop->enum_id, &pfc->pdata->data)) + if (!sh_pfc_enum_in_range(gpiop->enum_id, &pfc->pdata->data)) return -1; k = (gpiop->flags & PINMUX_FLAG_DREG) >> PINMUX_FLAG_DREG_SHIFT; @@ -290,10 +290,9 @@ int sh_pfc_get_data_reg(struct sh_pfc *pfc, unsigned gpio, return 0; } -static int get_config_reg(struct sh_pfc *pfc, pinmux_enum_t enum_id, - struct pinmux_cfg_reg **crp, - int *fieldp, int *valuep, - unsigned long **cntp) +static int sh_pfc_get_config_reg(struct sh_pfc *pfc, pinmux_enum_t enum_id, + struct pinmux_cfg_reg **crp, int *fieldp, + int *valuep, unsigned long **cntp) { struct pinmux_cfg_reg *config_reg; unsigned long r_width, f_width, curr_width, ncomb; @@ -343,8 +342,8 @@ int sh_pfc_gpio_to_enum(struct sh_pfc *pfc, unsigned gpio, int pos, pinmux_enum_t *data = pfc->pdata->gpio_data; int k; - if (!enum_in_range(enum_id, &pfc->pdata->data)) { - if (!enum_in_range(enum_id, &pfc->pdata->mark)) { + if (!sh_pfc_enum_in_range(enum_id, &pfc->pdata->data)) { + if (!sh_pfc_enum_in_range(enum_id, &pfc->pdata->mark)) { pr_err("non data/mark enum_id for gpio %d\n", gpio); return -1; } @@ -414,7 +413,7 @@ int sh_pfc_config_gpio(struct sh_pfc *pfc, unsigned gpio, int pinmux_type, break; /* first check if this is a function enum */ - in_range = enum_in_range(enum_id, &pfc->pdata->function); + in_range = sh_pfc_enum_in_range(enum_id, &pfc->pdata->function); if (!in_range) { /* not a function enum */ if (range) { @@ -426,7 +425,7 @@ int sh_pfc_config_gpio(struct sh_pfc *pfc, unsigned gpio, int pinmux_type, * for this case we only allow function enums * and the enums that match the other range. */ - in_range = enum_in_range(enum_id, range); + in_range = sh_pfc_enum_in_range(enum_id, range); /* * special case pass through for fixed @@ -451,19 +450,19 @@ int sh_pfc_config_gpio(struct sh_pfc *pfc, unsigned gpio, int pinmux_type, if (!in_range) continue; - if (get_config_reg(pfc, enum_id, &cr, - &field, &value, &cntp) != 0) + if (sh_pfc_get_config_reg(pfc, enum_id, &cr, + &field, &value, &cntp) != 0) goto out_err; switch (cfg_mode) { case GPIO_CFG_DRYRUN: if (!*cntp || - (read_config_reg(pfc, cr, field) != value)) + (sh_pfc_read_config_reg(pfc, cr, field) != value)) continue; break; case GPIO_CFG_REQ: - write_config_reg(pfc, cr, field, value); + sh_pfc_write_config_reg(pfc, cr, field, value); *cntp = *cntp + 1; break; @@ -499,14 +498,14 @@ static int sh_pfc_probe(struct platform_device *pdev) pfc->pdata = pdata; pfc->dev = &pdev->dev; - ret = pfc_ioremap(pfc); + ret = sh_pfc_ioremap(pfc); if (unlikely(ret < 0)) return ret; spin_lock_init(&pfc->lock); pinctrl_provide_dummies(); - setup_data_regs(pfc); + sh_pfc_setup_data_regs(pfc); /* * Initialize pinctrl bindings first diff --git a/drivers/sh/pfc/core.h b/drivers/sh/pfc/core.h index 1287b3e6222..d6a40bc592f 100644 --- a/drivers/sh/pfc/core.h +++ b/drivers/sh/pfc/core.h @@ -14,7 +14,7 @@ #include #include -struct pfc_window { +struct sh_pfc_window { phys_addr_t phys; void __iomem *virt; unsigned long size; @@ -28,7 +28,7 @@ struct sh_pfc { struct sh_pfc_platform_data *pdata; spinlock_t lock; - struct pfc_window *window; + struct sh_pfc_window *window; struct sh_pfc_chip *gpio; struct sh_pfc_pinctrl *pinctrl; }; -- cgit v1.2.3 From 40ee6fce7a0d3a2b2a1f2a14900af98a49a9ff40 Mon Sep 17 00:00:00 2001 From: Laurent Pinchart Date: Sat, 15 Dec 2012 23:50:54 +0100 Subject: sh-pfc: Split platform device and platform driver registration Move platform driver registration to a static postcore initcall. This prepares the move of platform device registration to arch code. Signed-off-by: Laurent Pinchart Acked-by: Paul Mundt Acked-by: Linus Walleij Signed-off-by: Simon Horman --- drivers/sh/pfc/core.c | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) (limited to 'drivers/sh') diff --git a/drivers/sh/pfc/core.c b/drivers/sh/pfc/core.c index 1bb38e8b36a..cd8f09dcea9 100644 --- a/drivers/sh/pfc/core.c +++ b/drivers/sh/pfc/core.c @@ -573,19 +573,16 @@ static struct platform_device sh_pfc_device = { int __init register_sh_pfc(struct sh_pfc_platform_data *pdata) { - int rc; - sh_pfc_device.dev.platform_data = pdata; - rc = platform_driver_register(&sh_pfc_driver); - if (likely(!rc)) { - rc = platform_device_register(&sh_pfc_device); - if (unlikely(rc)) - platform_driver_unregister(&sh_pfc_driver); - } + return platform_device_register(&sh_pfc_device); +} - return rc; +static int __init sh_pfc_init(void) +{ + return platform_driver_register(&sh_pfc_driver); } +postcore_initcall(sh_pfc_init); static void __exit sh_pfc_exit(void) { -- cgit v1.2.3 From 973931ae0a2dad57e23ce0ca2fab5abed9cf0d9a Mon Sep 17 00:00:00 2001 From: Laurent Pinchart Date: Sat, 15 Dec 2012 23:50:55 +0100 Subject: sh-pfc: Support passing resources through platform device Resources should be passed through the platform device, not through platform data. Default to platform device resources and fall back to platform data resources if not available. Support for platform data resources will be removed when arch code will be converted. Signed-off-by: Laurent Pinchart Acked-by: Paul Mundt Acked-by: Linus Walleij Signed-off-by: Simon Horman --- drivers/sh/pfc/core.c | 26 +++++++++++++++++++------- drivers/sh/pfc/core.h | 2 ++ 2 files changed, 21 insertions(+), 7 deletions(-) (limited to 'drivers/sh') diff --git a/drivers/sh/pfc/core.c b/drivers/sh/pfc/core.c index cd8f09dcea9..b2e121d927a 100644 --- a/drivers/sh/pfc/core.c +++ b/drivers/sh/pfc/core.c @@ -26,21 +26,33 @@ #include "core.h" -static int sh_pfc_ioremap(struct sh_pfc *pfc) +static int sh_pfc_ioremap(struct sh_pfc *pfc, struct platform_device *pdev) { + unsigned int num_resources; struct resource *res; int k; - if (!pfc->pdata->num_resources) + if (pdev->num_resources) { + num_resources = pdev->num_resources; + res = pdev->resource; + } else { + num_resources = pfc->pdata->num_resources; + res = pfc->pdata->resource; + } + + if (num_resources == 0) { + pfc->num_windows = 0; return 0; + } - pfc->window = devm_kzalloc(pfc->dev, pfc->pdata->num_resources * + pfc->window = devm_kzalloc(pfc->dev, num_resources * sizeof(*pfc->window), GFP_NOWAIT); if (!pfc->window) return -ENOMEM; - for (k = 0; k < pfc->pdata->num_resources; k++) { - res = pfc->pdata->resource + k; + pfc->num_windows = num_resources; + + for (k = 0; k < num_resources; k++, res++) { WARN_ON(resource_type(res) != IORESOURCE_MEM); pfc->window[k].phys = res->start; pfc->window[k].size = resource_size(res); @@ -60,7 +72,7 @@ static void __iomem *sh_pfc_phys_to_virt(struct sh_pfc *pfc, int k; /* scan through physical windows and convert address */ - for (k = 0; k < pfc->pdata->num_resources; k++) { + for (k = 0; k < pfc->num_windows; k++) { window = pfc->window + k; if (address < window->phys) @@ -498,7 +510,7 @@ static int sh_pfc_probe(struct platform_device *pdev) pfc->pdata = pdata; pfc->dev = &pdev->dev; - ret = sh_pfc_ioremap(pfc); + ret = sh_pfc_ioremap(pfc, pdev); if (unlikely(ret < 0)) return ret; diff --git a/drivers/sh/pfc/core.h b/drivers/sh/pfc/core.h index d6a40bc592f..87ae5fd2a20 100644 --- a/drivers/sh/pfc/core.h +++ b/drivers/sh/pfc/core.h @@ -28,7 +28,9 @@ struct sh_pfc { struct sh_pfc_platform_data *pdata; spinlock_t lock; + unsigned int num_windows; struct sh_pfc_window *window; + struct sh_pfc_chip *gpio; struct sh_pfc_pinctrl *pinctrl; }; -- cgit v1.2.3 From 8682b3c522c639f3a0de31c86bb91f2f9a6c76cb Mon Sep 17 00:00:00 2001 From: Laurent Pinchart Date: Sat, 15 Dec 2012 23:51:17 +0100 Subject: sh-pfc: Remove platform device registration The PFC platform device is now registered by arch code, remove the legacy registration mechanism. Signed-off-by: Laurent Pinchart Acked-by: Paul Mundt Acked-by: Linus Walleij Signed-off-by: Simon Horman --- drivers/sh/pfc/core.c | 12 ------------ 1 file changed, 12 deletions(-) (limited to 'drivers/sh') diff --git a/drivers/sh/pfc/core.c b/drivers/sh/pfc/core.c index b2e121d927a..9456c70a2da 100644 --- a/drivers/sh/pfc/core.c +++ b/drivers/sh/pfc/core.c @@ -578,18 +578,6 @@ static struct platform_driver sh_pfc_driver = { }, }; -static struct platform_device sh_pfc_device = { - .name = DRV_NAME, - .id = -1, -}; - -int __init register_sh_pfc(struct sh_pfc_platform_data *pdata) -{ - sh_pfc_device.dev.platform_data = pdata; - - return platform_device_register(&sh_pfc_device); -} - static int __init sh_pfc_init(void) { return platform_driver_register(&sh_pfc_driver); -- cgit v1.2.3 From 56dc04af3b5e54be330e18630301d2bda5d365eb Mon Sep 17 00:00:00 2001 From: Laurent Pinchart Date: Sat, 15 Dec 2012 23:51:18 +0100 Subject: sh-pfc: Remove unused resource and num_resources platform data fields The fields are now unused, remove them. Signed-off-by: Laurent Pinchart Acked-by: Paul Mundt Acked-by: Linus Walleij Signed-off-by: Simon Horman --- drivers/sh/pfc/core.c | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) (limited to 'drivers/sh') diff --git a/drivers/sh/pfc/core.c b/drivers/sh/pfc/core.c index 9456c70a2da..8e7818bccb2 100644 --- a/drivers/sh/pfc/core.c +++ b/drivers/sh/pfc/core.c @@ -28,31 +28,22 @@ static int sh_pfc_ioremap(struct sh_pfc *pfc, struct platform_device *pdev) { - unsigned int num_resources; struct resource *res; int k; - if (pdev->num_resources) { - num_resources = pdev->num_resources; - res = pdev->resource; - } else { - num_resources = pfc->pdata->num_resources; - res = pfc->pdata->resource; - } - - if (num_resources == 0) { + if (pdev->num_resources == 0) { pfc->num_windows = 0; return 0; } - pfc->window = devm_kzalloc(pfc->dev, num_resources * + pfc->window = devm_kzalloc(pfc->dev, pdev->num_resources * sizeof(*pfc->window), GFP_NOWAIT); if (!pfc->window) return -ENOMEM; - pfc->num_windows = num_resources; + pfc->num_windows = pdev->num_resources; - for (k = 0; k < num_resources; k++, res++) { + for (k = 0, res = pdev->resource; k < pdev->num_resources; k++, res++) { WARN_ON(resource_type(res) != IORESOURCE_MEM); pfc->window[k].phys = res->start; pfc->window[k].size = resource_size(res); -- cgit v1.2.3 From 6e54d8d252ed09ae148af6565971974af9a96e10 Mon Sep 17 00:00:00 2001 From: Laurent Pinchart Date: Sat, 15 Dec 2012 23:51:19 +0100 Subject: sh-pfc: Move driver from drivers/sh/ to drivers/pinctrl/ Signed-off-by: Laurent Pinchart Acked-by: Paul Mundt Acked-by: Linus Walleij Signed-off-by: Simon Horman --- drivers/sh/Kconfig | 1 - drivers/sh/Makefile | 1 - drivers/sh/pfc/Kconfig | 18 -- drivers/sh/pfc/Makefile | 5 - drivers/sh/pfc/core.c | 586 ----------------------------------------------- drivers/sh/pfc/core.h | 54 ----- drivers/sh/pfc/gpio.c | 179 --------------- drivers/sh/pfc/pinctrl.c | 464 ------------------------------------- 8 files changed, 1308 deletions(-) delete mode 100644 drivers/sh/pfc/Kconfig delete mode 100644 drivers/sh/pfc/Makefile delete mode 100644 drivers/sh/pfc/core.c delete mode 100644 drivers/sh/pfc/core.h delete mode 100644 drivers/sh/pfc/gpio.c delete mode 100644 drivers/sh/pfc/pinctrl.c (limited to 'drivers/sh') diff --git a/drivers/sh/Kconfig b/drivers/sh/Kconfig index d860ef74356..f168a615996 100644 --- a/drivers/sh/Kconfig +++ b/drivers/sh/Kconfig @@ -1,6 +1,5 @@ menu "SuperH / SH-Mobile Driver Options" source "drivers/sh/intc/Kconfig" -source "drivers/sh/pfc/Kconfig" endmenu diff --git a/drivers/sh/Makefile b/drivers/sh/Makefile index e57895b1a42..fc67f564f02 100644 --- a/drivers/sh/Makefile +++ b/drivers/sh/Makefile @@ -5,7 +5,6 @@ obj-y := intc/ obj-$(CONFIG_HAVE_CLK) += clk/ obj-$(CONFIG_MAPLE) += maple/ -obj-$(CONFIG_SH_PFC) += pfc/ obj-$(CONFIG_SUPERHYWAY) += superhyway/ obj-y += pm_runtime.o diff --git a/drivers/sh/pfc/Kconfig b/drivers/sh/pfc/Kconfig deleted file mode 100644 index eaeabc58bb0..00000000000 --- a/drivers/sh/pfc/Kconfig +++ /dev/null @@ -1,18 +0,0 @@ -comment "Pin function controller options" - -config SH_PFC - # XXX move off the gpio dependency - depends on GENERIC_GPIO - select GPIO_SH_PFC if ARCH_REQUIRE_GPIOLIB - select PINCTRL_SH_PFC - select PINCTRL - select PINMUX - select PINCONF - def_bool y - -config GPIO_SH_PFC - bool "SuperH PFC GPIO support" - depends on SH_PFC && GPIOLIB - help - This enables support for GPIOs within the SoC's pin function - controller. diff --git a/drivers/sh/pfc/Makefile b/drivers/sh/pfc/Makefile deleted file mode 100644 index 6315cf35b34..00000000000 --- a/drivers/sh/pfc/Makefile +++ /dev/null @@ -1,5 +0,0 @@ -sh-pfc-objs = core.o pinctrl.o -ifeq ($(CONFIG_GPIO_SH_PFC),y) -sh-pfc-objs += gpio.o -endif -obj-y += sh-pfc.o diff --git a/drivers/sh/pfc/core.c b/drivers/sh/pfc/core.c deleted file mode 100644 index 8e7818bccb2..00000000000 --- a/drivers/sh/pfc/core.c +++ /dev/null @@ -1,586 +0,0 @@ -/* - * SuperH Pin Function Controller support. - * - * Copyright (C) 2008 Magnus Damm - * Copyright (C) 2009 - 2012 Paul Mundt - * - * This file is subject to the terms and conditions of the GNU General Public - * License. See the file "COPYING" in the main directory of this archive - * for more details. - */ - -#define DRV_NAME "sh-pfc" -#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "core.h" - -static int sh_pfc_ioremap(struct sh_pfc *pfc, struct platform_device *pdev) -{ - struct resource *res; - int k; - - if (pdev->num_resources == 0) { - pfc->num_windows = 0; - return 0; - } - - pfc->window = devm_kzalloc(pfc->dev, pdev->num_resources * - sizeof(*pfc->window), GFP_NOWAIT); - if (!pfc->window) - return -ENOMEM; - - pfc->num_windows = pdev->num_resources; - - for (k = 0, res = pdev->resource; k < pdev->num_resources; k++, res++) { - WARN_ON(resource_type(res) != IORESOURCE_MEM); - pfc->window[k].phys = res->start; - pfc->window[k].size = resource_size(res); - pfc->window[k].virt = devm_ioremap_nocache(pfc->dev, res->start, - resource_size(res)); - if (!pfc->window[k].virt) - return -ENOMEM; - } - - return 0; -} - -static void __iomem *sh_pfc_phys_to_virt(struct sh_pfc *pfc, - unsigned long address) -{ - struct sh_pfc_window *window; - int k; - - /* scan through physical windows and convert address */ - for (k = 0; k < pfc->num_windows; k++) { - window = pfc->window + k; - - if (address < window->phys) - continue; - - if (address >= (window->phys + window->size)) - continue; - - return window->virt + (address - window->phys); - } - - /* no windows defined, register must be 1:1 mapped virt:phys */ - return (void __iomem *)address; -} - -static int sh_pfc_enum_in_range(pinmux_enum_t enum_id, struct pinmux_range *r) -{ - if (enum_id < r->begin) - return 0; - - if (enum_id > r->end) - return 0; - - return 1; -} - -static unsigned long sh_pfc_read_raw_reg(void __iomem *mapped_reg, - unsigned long reg_width) -{ - switch (reg_width) { - case 8: - return ioread8(mapped_reg); - case 16: - return ioread16(mapped_reg); - case 32: - return ioread32(mapped_reg); - } - - BUG(); - return 0; -} - -static void sh_pfc_write_raw_reg(void __iomem *mapped_reg, - unsigned long reg_width, unsigned long data) -{ - switch (reg_width) { - case 8: - iowrite8(data, mapped_reg); - return; - case 16: - iowrite16(data, mapped_reg); - return; - case 32: - iowrite32(data, mapped_reg); - return; - } - - BUG(); -} - -int sh_pfc_read_bit(struct pinmux_data_reg *dr, unsigned long in_pos) -{ - unsigned long pos; - - pos = dr->reg_width - (in_pos + 1); - - pr_debug("read_bit: addr = %lx, pos = %ld, " - "r_width = %ld\n", dr->reg, pos, dr->reg_width); - - return (sh_pfc_read_raw_reg(dr->mapped_reg, dr->reg_width) >> pos) & 1; -} - -void sh_pfc_write_bit(struct pinmux_data_reg *dr, unsigned long in_pos, - unsigned long value) -{ - unsigned long pos; - - pos = dr->reg_width - (in_pos + 1); - - pr_debug("write_bit addr = %lx, value = %d, pos = %ld, " - "r_width = %ld\n", - dr->reg, !!value, pos, dr->reg_width); - - if (value) - set_bit(pos, &dr->reg_shadow); - else - clear_bit(pos, &dr->reg_shadow); - - sh_pfc_write_raw_reg(dr->mapped_reg, dr->reg_width, dr->reg_shadow); -} - -static void sh_pfc_config_reg_helper(struct sh_pfc *pfc, - struct pinmux_cfg_reg *crp, - unsigned long in_pos, - void __iomem **mapped_regp, - unsigned long *maskp, - unsigned long *posp) -{ - int k; - - *mapped_regp = sh_pfc_phys_to_virt(pfc, crp->reg); - - if (crp->field_width) { - *maskp = (1 << crp->field_width) - 1; - *posp = crp->reg_width - ((in_pos + 1) * crp->field_width); - } else { - *maskp = (1 << crp->var_field_width[in_pos]) - 1; - *posp = crp->reg_width; - for (k = 0; k <= in_pos; k++) - *posp -= crp->var_field_width[k]; - } -} - -static int sh_pfc_read_config_reg(struct sh_pfc *pfc, - struct pinmux_cfg_reg *crp, - unsigned long field) -{ - void __iomem *mapped_reg; - unsigned long mask, pos; - - sh_pfc_config_reg_helper(pfc, crp, field, &mapped_reg, &mask, &pos); - - pr_debug("read_reg: addr = %lx, field = %ld, " - "r_width = %ld, f_width = %ld\n", - crp->reg, field, crp->reg_width, crp->field_width); - - return (sh_pfc_read_raw_reg(mapped_reg, crp->reg_width) >> pos) & mask; -} - -static void sh_pfc_write_config_reg(struct sh_pfc *pfc, - struct pinmux_cfg_reg *crp, - unsigned long field, unsigned long value) -{ - void __iomem *mapped_reg; - unsigned long mask, pos, data; - - sh_pfc_config_reg_helper(pfc, crp, field, &mapped_reg, &mask, &pos); - - pr_debug("write_reg addr = %lx, value = %ld, field = %ld, " - "r_width = %ld, f_width = %ld\n", - crp->reg, value, field, crp->reg_width, crp->field_width); - - mask = ~(mask << pos); - value = value << pos; - - data = sh_pfc_read_raw_reg(mapped_reg, crp->reg_width); - data &= mask; - data |= value; - - if (pfc->pdata->unlock_reg) - sh_pfc_write_raw_reg( - sh_pfc_phys_to_virt(pfc, pfc->pdata->unlock_reg), 32, - ~data); - - sh_pfc_write_raw_reg(mapped_reg, crp->reg_width, data); -} - -static int sh_pfc_setup_data_reg(struct sh_pfc *pfc, unsigned gpio) -{ - struct pinmux_gpio *gpiop = &pfc->pdata->gpios[gpio]; - struct pinmux_data_reg *data_reg; - int k, n; - - if (!sh_pfc_enum_in_range(gpiop->enum_id, &pfc->pdata->data)) - return -1; - - k = 0; - while (1) { - data_reg = pfc->pdata->data_regs + k; - - if (!data_reg->reg_width) - break; - - data_reg->mapped_reg = sh_pfc_phys_to_virt(pfc, data_reg->reg); - - for (n = 0; n < data_reg->reg_width; n++) { - if (data_reg->enum_ids[n] == gpiop->enum_id) { - gpiop->flags &= ~PINMUX_FLAG_DREG; - gpiop->flags |= (k << PINMUX_FLAG_DREG_SHIFT); - gpiop->flags &= ~PINMUX_FLAG_DBIT; - gpiop->flags |= (n << PINMUX_FLAG_DBIT_SHIFT); - return 0; - } - } - k++; - } - - BUG(); - - return -1; -} - -static void sh_pfc_setup_data_regs(struct sh_pfc *pfc) -{ - struct pinmux_data_reg *drp; - int k; - - for (k = pfc->pdata->first_gpio; k <= pfc->pdata->last_gpio; k++) - sh_pfc_setup_data_reg(pfc, k); - - k = 0; - while (1) { - drp = pfc->pdata->data_regs + k; - - if (!drp->reg_width) - break; - - drp->reg_shadow = sh_pfc_read_raw_reg(drp->mapped_reg, - drp->reg_width); - k++; - } -} - -int sh_pfc_get_data_reg(struct sh_pfc *pfc, unsigned gpio, - struct pinmux_data_reg **drp, int *bitp) -{ - struct pinmux_gpio *gpiop = &pfc->pdata->gpios[gpio]; - int k, n; - - if (!sh_pfc_enum_in_range(gpiop->enum_id, &pfc->pdata->data)) - return -1; - - k = (gpiop->flags & PINMUX_FLAG_DREG) >> PINMUX_FLAG_DREG_SHIFT; - n = (gpiop->flags & PINMUX_FLAG_DBIT) >> PINMUX_FLAG_DBIT_SHIFT; - *drp = pfc->pdata->data_regs + k; - *bitp = n; - return 0; -} - -static int sh_pfc_get_config_reg(struct sh_pfc *pfc, pinmux_enum_t enum_id, - struct pinmux_cfg_reg **crp, int *fieldp, - int *valuep, unsigned long **cntp) -{ - struct pinmux_cfg_reg *config_reg; - unsigned long r_width, f_width, curr_width, ncomb; - int k, m, n, pos, bit_pos; - - k = 0; - while (1) { - config_reg = pfc->pdata->cfg_regs + k; - - r_width = config_reg->reg_width; - f_width = config_reg->field_width; - - if (!r_width) - break; - - pos = 0; - m = 0; - for (bit_pos = 0; bit_pos < r_width; bit_pos += curr_width) { - if (f_width) - curr_width = f_width; - else - curr_width = config_reg->var_field_width[m]; - - ncomb = 1 << curr_width; - for (n = 0; n < ncomb; n++) { - if (config_reg->enum_ids[pos + n] == enum_id) { - *crp = config_reg; - *fieldp = m; - *valuep = n; - *cntp = &config_reg->cnt[m]; - return 0; - } - } - pos += ncomb; - m++; - } - k++; - } - - return -1; -} - -int sh_pfc_gpio_to_enum(struct sh_pfc *pfc, unsigned gpio, int pos, - pinmux_enum_t *enum_idp) -{ - pinmux_enum_t enum_id = pfc->pdata->gpios[gpio].enum_id; - pinmux_enum_t *data = pfc->pdata->gpio_data; - int k; - - if (!sh_pfc_enum_in_range(enum_id, &pfc->pdata->data)) { - if (!sh_pfc_enum_in_range(enum_id, &pfc->pdata->mark)) { - pr_err("non data/mark enum_id for gpio %d\n", gpio); - return -1; - } - } - - if (pos) { - *enum_idp = data[pos + 1]; - return pos + 1; - } - - for (k = 0; k < pfc->pdata->gpio_data_size; k++) { - if (data[k] == enum_id) { - *enum_idp = data[k + 1]; - return k + 1; - } - } - - pr_err("cannot locate data/mark enum_id for gpio %d\n", gpio); - return -1; -} - -int sh_pfc_config_gpio(struct sh_pfc *pfc, unsigned gpio, int pinmux_type, - int cfg_mode) -{ - struct pinmux_cfg_reg *cr = NULL; - pinmux_enum_t enum_id; - struct pinmux_range *range; - int in_range, pos, field, value; - unsigned long *cntp; - - switch (pinmux_type) { - - case PINMUX_TYPE_FUNCTION: - range = NULL; - break; - - case PINMUX_TYPE_OUTPUT: - range = &pfc->pdata->output; - break; - - case PINMUX_TYPE_INPUT: - range = &pfc->pdata->input; - break; - - case PINMUX_TYPE_INPUT_PULLUP: - range = &pfc->pdata->input_pu; - break; - - case PINMUX_TYPE_INPUT_PULLDOWN: - range = &pfc->pdata->input_pd; - break; - - default: - goto out_err; - } - - pos = 0; - enum_id = 0; - field = 0; - value = 0; - while (1) { - pos = sh_pfc_gpio_to_enum(pfc, gpio, pos, &enum_id); - if (pos <= 0) - goto out_err; - - if (!enum_id) - break; - - /* first check if this is a function enum */ - in_range = sh_pfc_enum_in_range(enum_id, &pfc->pdata->function); - if (!in_range) { - /* not a function enum */ - if (range) { - /* - * other range exists, so this pin is - * a regular GPIO pin that now is being - * bound to a specific direction. - * - * for this case we only allow function enums - * and the enums that match the other range. - */ - in_range = sh_pfc_enum_in_range(enum_id, range); - - /* - * special case pass through for fixed - * input-only or output-only pins without - * function enum register association. - */ - if (in_range && enum_id == range->force) - continue; - } else { - /* - * no other range exists, so this pin - * must then be of the function type. - * - * allow function type pins to select - * any combination of function/in/out - * in their MARK lists. - */ - in_range = 1; - } - } - - if (!in_range) - continue; - - if (sh_pfc_get_config_reg(pfc, enum_id, &cr, - &field, &value, &cntp) != 0) - goto out_err; - - switch (cfg_mode) { - case GPIO_CFG_DRYRUN: - if (!*cntp || - (sh_pfc_read_config_reg(pfc, cr, field) != value)) - continue; - break; - - case GPIO_CFG_REQ: - sh_pfc_write_config_reg(pfc, cr, field, value); - *cntp = *cntp + 1; - break; - - case GPIO_CFG_FREE: - *cntp = *cntp - 1; - break; - } - } - - return 0; - out_err: - return -1; -} - -static int sh_pfc_probe(struct platform_device *pdev) -{ - struct sh_pfc_platform_data *pdata = pdev->dev.platform_data; - struct sh_pfc *pfc; - int ret; - - /* - * Ensure that the type encoding fits - */ - BUILD_BUG_ON(PINMUX_FLAG_TYPE > ((1 << PINMUX_FLAG_DBIT_SHIFT) - 1)); - - if (pdata == NULL) - return -ENODEV; - - pfc = devm_kzalloc(&pdev->dev, sizeof(pfc), GFP_KERNEL); - if (pfc == NULL) - return -ENOMEM; - - pfc->pdata = pdata; - pfc->dev = &pdev->dev; - - ret = sh_pfc_ioremap(pfc, pdev); - if (unlikely(ret < 0)) - return ret; - - spin_lock_init(&pfc->lock); - - pinctrl_provide_dummies(); - sh_pfc_setup_data_regs(pfc); - - /* - * Initialize pinctrl bindings first - */ - ret = sh_pfc_register_pinctrl(pfc); - if (unlikely(ret != 0)) - return ret; - -#ifdef CONFIG_GPIO_SH_PFC - /* - * Then the GPIO chip - */ - ret = sh_pfc_register_gpiochip(pfc); - if (unlikely(ret != 0)) { - /* - * If the GPIO chip fails to come up we still leave the - * PFC state as it is, given that there are already - * extant users of it that have succeeded by this point. - */ - pr_notice("failed to init GPIO chip, ignoring...\n"); - } -#endif - - platform_set_drvdata(pdev, pfc); - - pr_info("%s support registered\n", pdata->name); - - return 0; -} - -static int sh_pfc_remove(struct platform_device *pdev) -{ - struct sh_pfc *pfc = platform_get_drvdata(pdev); - -#ifdef CONFIG_GPIO_SH_PFC - sh_pfc_unregister_gpiochip(pfc); -#endif - sh_pfc_unregister_pinctrl(pfc); - - platform_set_drvdata(pdev, NULL); - - return 0; -} - -static const struct platform_device_id sh_pfc_id_table[] = { - { "sh-pfc", 0 }, - { }, -}; -MODULE_DEVICE_TABLE(platform, sh_pfc_id_table); - -static struct platform_driver sh_pfc_driver = { - .probe = sh_pfc_probe, - .remove = sh_pfc_remove, - .id_table = sh_pfc_id_table, - .driver = { - .name = DRV_NAME, - .owner = THIS_MODULE, - }, -}; - -static int __init sh_pfc_init(void) -{ - return platform_driver_register(&sh_pfc_driver); -} -postcore_initcall(sh_pfc_init); - -static void __exit sh_pfc_exit(void) -{ - platform_driver_unregister(&sh_pfc_driver); -} -module_exit(sh_pfc_exit); - -MODULE_AUTHOR("Magnus Damm, Paul Mundt, Laurent Pinchart"); -MODULE_DESCRIPTION("Pin Control and GPIO driver for SuperH pin function controller"); -MODULE_LICENSE("GPL v2"); diff --git a/drivers/sh/pfc/core.h b/drivers/sh/pfc/core.h deleted file mode 100644 index 87ae5fd2a20..00000000000 --- a/drivers/sh/pfc/core.h +++ /dev/null @@ -1,54 +0,0 @@ -/* - * SuperH Pin Function Controller support. - * - * Copyright (C) 2012 Renesas Solutions Corp. - * - * This file is subject to the terms and conditions of the GNU General Public - * License. See the file "COPYING" in the main directory of this archive - * for more details. - */ -#ifndef __SH_PFC_CORE_H__ -#define __SH_PFC_CORE_H__ - -#include -#include -#include - -struct sh_pfc_window { - phys_addr_t phys; - void __iomem *virt; - unsigned long size; -}; - -struct sh_pfc_chip; -struct sh_pfc_pinctrl; - -struct sh_pfc { - struct device *dev; - struct sh_pfc_platform_data *pdata; - spinlock_t lock; - - unsigned int num_windows; - struct sh_pfc_window *window; - - struct sh_pfc_chip *gpio; - struct sh_pfc_pinctrl *pinctrl; -}; - -int sh_pfc_register_gpiochip(struct sh_pfc *pfc); -int sh_pfc_unregister_gpiochip(struct sh_pfc *pfc); - -int sh_pfc_register_pinctrl(struct sh_pfc *pfc); -int sh_pfc_unregister_pinctrl(struct sh_pfc *pfc); - -int sh_pfc_read_bit(struct pinmux_data_reg *dr, unsigned long in_pos); -void sh_pfc_write_bit(struct pinmux_data_reg *dr, unsigned long in_pos, - unsigned long value); -int sh_pfc_get_data_reg(struct sh_pfc *pfc, unsigned gpio, - struct pinmux_data_reg **drp, int *bitp); -int sh_pfc_gpio_to_enum(struct sh_pfc *pfc, unsigned gpio, int pos, - pinmux_enum_t *enum_idp); -int sh_pfc_config_gpio(struct sh_pfc *pfc, unsigned gpio, int pinmux_type, - int cfg_mode); - -#endif /* __SH_PFC_CORE_H__ */ diff --git a/drivers/sh/pfc/gpio.c b/drivers/sh/pfc/gpio.c deleted file mode 100644 index a0454f32171..00000000000 --- a/drivers/sh/pfc/gpio.c +++ /dev/null @@ -1,179 +0,0 @@ -/* - * SuperH Pin Function Controller GPIO driver. - * - * Copyright (C) 2008 Magnus Damm - * Copyright (C) 2009 - 2012 Paul Mundt - * - * This file is subject to the terms and conditions of the GNU General Public - * License. See the file "COPYING" in the main directory of this archive - * for more details. - */ - -#define pr_fmt(fmt) KBUILD_MODNAME " gpio: " fmt - -#include -#include -#include -#include -#include -#include -#include -#include - -#include "core.h" - -struct sh_pfc_chip { - struct sh_pfc *pfc; - struct gpio_chip gpio_chip; -}; - -static struct sh_pfc_chip *gpio_to_pfc_chip(struct gpio_chip *gc) -{ - return container_of(gc, struct sh_pfc_chip, gpio_chip); -} - -static struct sh_pfc *gpio_to_pfc(struct gpio_chip *gc) -{ - return gpio_to_pfc_chip(gc)->pfc; -} - -static int sh_gpio_request(struct gpio_chip *gc, unsigned offset) -{ - return pinctrl_request_gpio(offset); -} - -static void sh_gpio_free(struct gpio_chip *gc, unsigned offset) -{ - pinctrl_free_gpio(offset); -} - -static void sh_gpio_set_value(struct sh_pfc *pfc, unsigned gpio, int value) -{ - struct pinmux_data_reg *dr = NULL; - int bit = 0; - - if (sh_pfc_get_data_reg(pfc, gpio, &dr, &bit) != 0) - BUG(); - else - sh_pfc_write_bit(dr, bit, value); -} - -static int sh_gpio_get_value(struct sh_pfc *pfc, unsigned gpio) -{ - struct pinmux_data_reg *dr = NULL; - int bit = 0; - - if (sh_pfc_get_data_reg(pfc, gpio, &dr, &bit) != 0) - return -EINVAL; - - return sh_pfc_read_bit(dr, bit); -} - -static int sh_gpio_direction_input(struct gpio_chip *gc, unsigned offset) -{ - return pinctrl_gpio_direction_input(offset); -} - -static int sh_gpio_direction_output(struct gpio_chip *gc, unsigned offset, - int value) -{ - sh_gpio_set_value(gpio_to_pfc(gc), offset, value); - - return pinctrl_gpio_direction_output(offset); -} - -static int sh_gpio_get(struct gpio_chip *gc, unsigned offset) -{ - return sh_gpio_get_value(gpio_to_pfc(gc), offset); -} - -static void sh_gpio_set(struct gpio_chip *gc, unsigned offset, int value) -{ - sh_gpio_set_value(gpio_to_pfc(gc), offset, value); -} - -static int sh_gpio_to_irq(struct gpio_chip *gc, unsigned offset) -{ - struct sh_pfc *pfc = gpio_to_pfc(gc); - pinmux_enum_t enum_id; - pinmux_enum_t *enum_ids; - int i, k, pos; - - pos = 0; - enum_id = 0; - while (1) { - pos = sh_pfc_gpio_to_enum(pfc, offset, pos, &enum_id); - if (pos <= 0 || !enum_id) - break; - - for (i = 0; i < pfc->pdata->gpio_irq_size; i++) { - enum_ids = pfc->pdata->gpio_irq[i].enum_ids; - for (k = 0; enum_ids[k]; k++) { - if (enum_ids[k] == enum_id) - return pfc->pdata->gpio_irq[i].irq; - } - } - } - - return -ENOSYS; -} - -static void sh_pfc_gpio_setup(struct sh_pfc_chip *chip) -{ - struct sh_pfc *pfc = chip->pfc; - struct gpio_chip *gc = &chip->gpio_chip; - - gc->request = sh_gpio_request; - gc->free = sh_gpio_free; - gc->direction_input = sh_gpio_direction_input; - gc->get = sh_gpio_get; - gc->direction_output = sh_gpio_direction_output; - gc->set = sh_gpio_set; - gc->to_irq = sh_gpio_to_irq; - - WARN_ON(pfc->pdata->first_gpio != 0); /* needs testing */ - - gc->label = pfc->pdata->name; - gc->owner = THIS_MODULE; - gc->base = pfc->pdata->first_gpio; - gc->ngpio = (pfc->pdata->last_gpio - pfc->pdata->first_gpio) + 1; -} - -int sh_pfc_register_gpiochip(struct sh_pfc *pfc) -{ - struct sh_pfc_chip *chip; - int ret; - - chip = devm_kzalloc(pfc->dev, sizeof(*chip), GFP_KERNEL); - if (unlikely(!chip)) - return -ENOMEM; - - chip->pfc = pfc; - - sh_pfc_gpio_setup(chip); - - ret = gpiochip_add(&chip->gpio_chip); - if (unlikely(ret < 0)) - return ret; - - pfc->gpio = chip; - - pr_info("%s handling gpio %d -> %d\n", - pfc->pdata->name, pfc->pdata->first_gpio, - pfc->pdata->last_gpio); - - return 0; -} - -int sh_pfc_unregister_gpiochip(struct sh_pfc *pfc) -{ - struct sh_pfc_chip *chip = pfc->gpio; - int ret; - - ret = gpiochip_remove(&chip->gpio_chip); - if (unlikely(ret < 0)) - return ret; - - pfc->gpio = NULL; - return 0; -} diff --git a/drivers/sh/pfc/pinctrl.c b/drivers/sh/pfc/pinctrl.c deleted file mode 100644 index 221bde03913..00000000000 --- a/drivers/sh/pfc/pinctrl.c +++ /dev/null @@ -1,464 +0,0 @@ -/* - * SuperH Pin Function Controller pinmux support. - * - * Copyright (C) 2012 Paul Mundt - * - * This file is subject to the terms and conditions of the GNU General Public - * License. See the file "COPYING" in the main directory of this archive - * for more details. - */ - -#define DRV_NAME "sh-pfc" -#define pr_fmt(fmt) KBUILD_MODNAME " pinctrl: " fmt - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "core.h" - -struct sh_pfc_pinctrl { - struct pinctrl_dev *pctl; - struct sh_pfc *pfc; - - struct pinmux_gpio **functions; - unsigned int nr_functions; - - struct pinctrl_pin_desc *pads; - unsigned int nr_pads; - - spinlock_t lock; -}; - -static int sh_pfc_get_groups_count(struct pinctrl_dev *pctldev) -{ - struct sh_pfc_pinctrl *pmx = pinctrl_dev_get_drvdata(pctldev); - - return pmx->nr_pads; -} - -static const char *sh_pfc_get_group_name(struct pinctrl_dev *pctldev, - unsigned selector) -{ - struct sh_pfc_pinctrl *pmx = pinctrl_dev_get_drvdata(pctldev); - - return pmx->pads[selector].name; -} - -static int sh_pfc_get_group_pins(struct pinctrl_dev *pctldev, unsigned group, - const unsigned **pins, unsigned *num_pins) -{ - struct sh_pfc_pinctrl *pmx = pinctrl_dev_get_drvdata(pctldev); - - *pins = &pmx->pads[group].number; - *num_pins = 1; - - return 0; -} - -static void sh_pfc_pin_dbg_show(struct pinctrl_dev *pctldev, struct seq_file *s, - unsigned offset) -{ - seq_printf(s, "%s", DRV_NAME); -} - -static struct pinctrl_ops sh_pfc_pinctrl_ops = { - .get_groups_count = sh_pfc_get_groups_count, - .get_group_name = sh_pfc_get_group_name, - .get_group_pins = sh_pfc_get_group_pins, - .pin_dbg_show = sh_pfc_pin_dbg_show, -}; - -static int sh_pfc_get_functions_count(struct pinctrl_dev *pctldev) -{ - struct sh_pfc_pinctrl *pmx = pinctrl_dev_get_drvdata(pctldev); - - return pmx->nr_functions; -} - -static const char *sh_pfc_get_function_name(struct pinctrl_dev *pctldev, - unsigned selector) -{ - struct sh_pfc_pinctrl *pmx = pinctrl_dev_get_drvdata(pctldev); - - return pmx->functions[selector]->name; -} - -static int sh_pfc_get_function_groups(struct pinctrl_dev *pctldev, unsigned func, - const char * const **groups, - unsigned * const num_groups) -{ - struct sh_pfc_pinctrl *pmx = pinctrl_dev_get_drvdata(pctldev); - - *groups = &pmx->functions[func]->name; - *num_groups = 1; - - return 0; -} - -static int sh_pfc_noop_enable(struct pinctrl_dev *pctldev, unsigned func, - unsigned group) -{ - return 0; -} - -static void sh_pfc_noop_disable(struct pinctrl_dev *pctldev, unsigned func, - unsigned group) -{ -} - -static int sh_pfc_config_function(struct sh_pfc *pfc, unsigned offset) -{ - if (sh_pfc_config_gpio(pfc, offset, - PINMUX_TYPE_FUNCTION, - GPIO_CFG_DRYRUN) != 0) - return -EINVAL; - - if (sh_pfc_config_gpio(pfc, offset, - PINMUX_TYPE_FUNCTION, - GPIO_CFG_REQ) != 0) - return -EINVAL; - - return 0; -} - -static int sh_pfc_reconfig_pin(struct sh_pfc *pfc, unsigned offset, - int new_type) -{ - unsigned long flags; - int pinmux_type; - int ret = -EINVAL; - - spin_lock_irqsave(&pfc->lock, flags); - - pinmux_type = pfc->pdata->gpios[offset].flags & PINMUX_FLAG_TYPE; - - /* - * See if the present config needs to first be de-configured. - */ - switch (pinmux_type) { - case PINMUX_TYPE_GPIO: - break; - case PINMUX_TYPE_OUTPUT: - case PINMUX_TYPE_INPUT: - case PINMUX_TYPE_INPUT_PULLUP: - case PINMUX_TYPE_INPUT_PULLDOWN: - sh_pfc_config_gpio(pfc, offset, pinmux_type, GPIO_CFG_FREE); - break; - default: - goto err; - } - - /* - * Dry run - */ - if (sh_pfc_config_gpio(pfc, offset, new_type, - GPIO_CFG_DRYRUN) != 0) - goto err; - - /* - * Request - */ - if (sh_pfc_config_gpio(pfc, offset, new_type, - GPIO_CFG_REQ) != 0) - goto err; - - pfc->pdata->gpios[offset].flags &= ~PINMUX_FLAG_TYPE; - pfc->pdata->gpios[offset].flags |= new_type; - - ret = 0; - -err: - spin_unlock_irqrestore(&pfc->lock, flags); - - return ret; -} - - -static int sh_pfc_gpio_request_enable(struct pinctrl_dev *pctldev, - struct pinctrl_gpio_range *range, - unsigned offset) -{ - struct sh_pfc_pinctrl *pmx = pinctrl_dev_get_drvdata(pctldev); - struct sh_pfc *pfc = pmx->pfc; - unsigned long flags; - int ret, pinmux_type; - - spin_lock_irqsave(&pfc->lock, flags); - - pinmux_type = pfc->pdata->gpios[offset].flags & PINMUX_FLAG_TYPE; - - switch (pinmux_type) { - case PINMUX_TYPE_FUNCTION: - pr_notice_once("Use of GPIO API for function requests is " - "deprecated, convert to pinctrl\n"); - /* handle for now */ - ret = sh_pfc_config_function(pfc, offset); - if (unlikely(ret < 0)) - goto err; - - break; - case PINMUX_TYPE_GPIO: - case PINMUX_TYPE_INPUT: - case PINMUX_TYPE_OUTPUT: - break; - default: - pr_err("Unsupported mux type (%d), bailing...\n", pinmux_type); - ret = -ENOTSUPP; - goto err; - } - - ret = 0; - -err: - spin_unlock_irqrestore(&pfc->lock, flags); - - return ret; -} - -static void sh_pfc_gpio_disable_free(struct pinctrl_dev *pctldev, - struct pinctrl_gpio_range *range, - unsigned offset) -{ - struct sh_pfc_pinctrl *pmx = pinctrl_dev_get_drvdata(pctldev); - struct sh_pfc *pfc = pmx->pfc; - unsigned long flags; - int pinmux_type; - - spin_lock_irqsave(&pfc->lock, flags); - - pinmux_type = pfc->pdata->gpios[offset].flags & PINMUX_FLAG_TYPE; - - sh_pfc_config_gpio(pfc, offset, pinmux_type, GPIO_CFG_FREE); - - spin_unlock_irqrestore(&pfc->lock, flags); -} - -static int sh_pfc_gpio_set_direction(struct pinctrl_dev *pctldev, - struct pinctrl_gpio_range *range, - unsigned offset, bool input) -{ - struct sh_pfc_pinctrl *pmx = pinctrl_dev_get_drvdata(pctldev); - int type = input ? PINMUX_TYPE_INPUT : PINMUX_TYPE_OUTPUT; - - return sh_pfc_reconfig_pin(pmx->pfc, offset, type); -} - -static struct pinmux_ops sh_pfc_pinmux_ops = { - .get_functions_count = sh_pfc_get_functions_count, - .get_function_name = sh_pfc_get_function_name, - .get_function_groups = sh_pfc_get_function_groups, - .enable = sh_pfc_noop_enable, - .disable = sh_pfc_noop_disable, - .gpio_request_enable = sh_pfc_gpio_request_enable, - .gpio_disable_free = sh_pfc_gpio_disable_free, - .gpio_set_direction = sh_pfc_gpio_set_direction, -}; - -static int sh_pfc_pinconf_get(struct pinctrl_dev *pctldev, unsigned pin, - unsigned long *config) -{ - struct sh_pfc_pinctrl *pmx = pinctrl_dev_get_drvdata(pctldev); - struct sh_pfc *pfc = pmx->pfc; - - *config = pfc->pdata->gpios[pin].flags & PINMUX_FLAG_TYPE; - - return 0; -} - -static int sh_pfc_pinconf_set(struct pinctrl_dev *pctldev, unsigned pin, - unsigned long config) -{ - struct sh_pfc_pinctrl *pmx = pinctrl_dev_get_drvdata(pctldev); - - /* Validate the new type */ - if (config >= PINMUX_FLAG_TYPE) - return -EINVAL; - - return sh_pfc_reconfig_pin(pmx->pfc, pin, config); -} - -static void sh_pfc_pinconf_dbg_show(struct pinctrl_dev *pctldev, - struct seq_file *s, unsigned pin) -{ - const char *pinmux_type_str[] = { - [PINMUX_TYPE_NONE] = "none", - [PINMUX_TYPE_FUNCTION] = "function", - [PINMUX_TYPE_GPIO] = "gpio", - [PINMUX_TYPE_OUTPUT] = "output", - [PINMUX_TYPE_INPUT] = "input", - [PINMUX_TYPE_INPUT_PULLUP] = "input bias pull up", - [PINMUX_TYPE_INPUT_PULLDOWN] = "input bias pull down", - }; - unsigned long config; - int rc; - - rc = sh_pfc_pinconf_get(pctldev, pin, &config); - if (unlikely(rc != 0)) - return; - - seq_printf(s, " %s", pinmux_type_str[config]); -} - -static struct pinconf_ops sh_pfc_pinconf_ops = { - .pin_config_get = sh_pfc_pinconf_get, - .pin_config_set = sh_pfc_pinconf_set, - .pin_config_dbg_show = sh_pfc_pinconf_dbg_show, -}; - -static struct pinctrl_gpio_range sh_pfc_gpio_range = { - .name = DRV_NAME, - .id = 0, -}; - -static struct pinctrl_desc sh_pfc_pinctrl_desc = { - .name = DRV_NAME, - .owner = THIS_MODULE, - .pctlops = &sh_pfc_pinctrl_ops, - .pmxops = &sh_pfc_pinmux_ops, - .confops = &sh_pfc_pinconf_ops, -}; - -static void sh_pfc_map_one_gpio(struct sh_pfc *pfc, struct sh_pfc_pinctrl *pmx, - struct pinmux_gpio *gpio, unsigned offset) -{ - struct pinmux_data_reg *dummy; - unsigned long flags; - int bit; - - gpio->flags &= ~PINMUX_FLAG_TYPE; - - if (sh_pfc_get_data_reg(pfc, offset, &dummy, &bit) == 0) - gpio->flags |= PINMUX_TYPE_GPIO; - else { - gpio->flags |= PINMUX_TYPE_FUNCTION; - - spin_lock_irqsave(&pmx->lock, flags); - pmx->nr_functions++; - spin_unlock_irqrestore(&pmx->lock, flags); - } -} - -/* pinmux ranges -> pinctrl pin descs */ -static int sh_pfc_map_gpios(struct sh_pfc *pfc, struct sh_pfc_pinctrl *pmx) -{ - unsigned long flags; - int i; - - pmx->nr_pads = pfc->pdata->last_gpio - pfc->pdata->first_gpio + 1; - - pmx->pads = devm_kzalloc(pfc->dev, sizeof(*pmx->pads) * pmx->nr_pads, - GFP_KERNEL); - if (unlikely(!pmx->pads)) { - pmx->nr_pads = 0; - return -ENOMEM; - } - - spin_lock_irqsave(&pfc->lock, flags); - - /* - * We don't necessarily have a 1:1 mapping between pin and linux - * GPIO number, as the latter maps to the associated enum_id. - * Care needs to be taken to translate back to pin space when - * dealing with any pin configurations. - */ - for (i = 0; i < pmx->nr_pads; i++) { - struct pinctrl_pin_desc *pin = pmx->pads + i; - struct pinmux_gpio *gpio = pfc->pdata->gpios + i; - - pin->number = pfc->pdata->first_gpio + i; - pin->name = gpio->name; - - /* XXX */ - if (unlikely(!gpio->enum_id)) - continue; - - sh_pfc_map_one_gpio(pfc, pmx, gpio, i); - } - - spin_unlock_irqrestore(&pfc->lock, flags); - - sh_pfc_pinctrl_desc.pins = pmx->pads; - sh_pfc_pinctrl_desc.npins = pmx->nr_pads; - - return 0; -} - -static int sh_pfc_map_functions(struct sh_pfc *pfc, struct sh_pfc_pinctrl *pmx) -{ - unsigned long flags; - int i, fn; - - pmx->functions = devm_kzalloc(pfc->dev, pmx->nr_functions * - sizeof(*pmx->functions), GFP_KERNEL); - if (unlikely(!pmx->functions)) - return -ENOMEM; - - spin_lock_irqsave(&pmx->lock, flags); - - for (i = fn = 0; i < pmx->nr_pads; i++) { - struct pinmux_gpio *gpio = pfc->pdata->gpios + i; - - if ((gpio->flags & PINMUX_FLAG_TYPE) == PINMUX_TYPE_FUNCTION) - pmx->functions[fn++] = gpio; - } - - spin_unlock_irqrestore(&pmx->lock, flags); - - return 0; -} - -int sh_pfc_register_pinctrl(struct sh_pfc *pfc) -{ - struct sh_pfc_pinctrl *pmx; - int ret; - - pmx = devm_kzalloc(pfc->dev, sizeof(*pmx), GFP_KERNEL); - if (unlikely(!pmx)) - return -ENOMEM; - - spin_lock_init(&pmx->lock); - - pmx->pfc = pfc; - pfc->pinctrl = pmx; - - ret = sh_pfc_map_gpios(pfc, pmx); - if (unlikely(ret != 0)) - return ret; - - ret = sh_pfc_map_functions(pfc, pmx); - if (unlikely(ret != 0)) - return ret; - - pmx->pctl = pinctrl_register(&sh_pfc_pinctrl_desc, pfc->dev, pmx); - if (IS_ERR(pmx->pctl)) - return PTR_ERR(pmx->pctl); - - sh_pfc_gpio_range.npins = pfc->pdata->last_gpio - - pfc->pdata->first_gpio + 1; - sh_pfc_gpio_range.base = pfc->pdata->first_gpio; - sh_pfc_gpio_range.pin_base = pfc->pdata->first_gpio; - - pinctrl_add_gpio_range(pmx->pctl, &sh_pfc_gpio_range); - - return 0; -} - -int sh_pfc_unregister_pinctrl(struct sh_pfc *pfc) -{ - struct sh_pfc_pinctrl *pmx = pfc->pinctrl; - - pinctrl_unregister(pmx->pctl); - - pfc->pinctrl = NULL; - return 0; -} -- cgit v1.2.3