提交 d4e62d00 编写于 作者: L Laurent Pinchart 提交者: Simon Horman

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: NLaurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>
Acked-by: NPaul Mundt <lethal@linux-sh.org>
Acked-by: NLinus Walleij <linus.walleij@linaro.org>
Signed-off-by: NSimon Horman <horms+renesas@verge.net.au>
上级 e62ebcdb
......@@ -21,18 +21,13 @@
#include <linux/ioport.h>
#include <linux/pinctrl/machine.h>
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;
}
......@@ -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;
}
......
......@@ -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);
......
......@@ -94,7 +94,7 @@ struct pfc_window {
unsigned long size;
};
struct sh_pfc {
struct sh_pfc_platform_data {
char *name;
pinmux_enum_t reserved_id;
struct pinmux_range data;
......@@ -117,17 +117,21 @@ struct sh_pfc {
struct pinmux_irq *gpio_irq;
unsigned int gpio_irq_size;
spinlock_t lock;
struct resource *resource;
unsigned int num_resources;
struct pfc_window *window;
unsigned long unlock_reg;
};
struct sh_pfc {
struct sh_pfc_platform_data *pdata;
spinlock_t lock;
struct pfc_window *window;
};
/* XXX compat for now */
#define pinmux_info sh_pfc
#define pinmux_info sh_pfc_platform_data
/* drivers/sh/pfc/gpio.c */
int sh_pfc_register_gpiochip(struct sh_pfc *pfc);
......@@ -136,7 +140,7 @@ int sh_pfc_register_gpiochip(struct sh_pfc *pfc);
int sh_pfc_register_pinctrl(struct sh_pfc *pfc);
/* drivers/sh/pfc/core.c */
int register_sh_pfc(struct sh_pfc *pfc);
int register_sh_pfc(struct sh_pfc_platform_data *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,
......@@ -151,8 +155,8 @@ int sh_pfc_config_gpio(struct sh_pfc *pfc, unsigned gpio, int pinmux_type,
/* xxx */
static inline int register_pinmux(struct pinmux_info *pip)
{
struct sh_pfc *pfc = pip;
return register_sh_pfc(pfc);
struct sh_pfc_platform_data *pdata = pip;
return register_sh_pfc(pdata);
}
enum { GPIO_CFG_DRYRUN, GPIO_CFG_REQ, GPIO_CFG_FREE };
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册