Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 355337
b: refs/heads/master
c: d4e62d0
h: refs/heads/master
i:
  355335: e96be38
v: v3
  • Loading branch information
Laurent Pinchart authored and Simon Horman committed Jan 25, 2013
1 parent 102a525 commit 5d1c98d
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 77 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: e62ebcdbce9eff4dc48168e86960c0dfcba086ea
refs/heads/master: d4e62d0094e1b0f69946c3f16ce8ec882302a461
89 changes: 43 additions & 46 deletions trunk/drivers/sh/pfc/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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);
Expand All @@ -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)
Expand Down Expand Up @@ -232,25 +227,25 @@ 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);
}

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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
}
Expand All @@ -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;
Expand Down Expand Up @@ -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;
}
Expand All @@ -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;
Expand Down Expand Up @@ -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:
Expand All @@ -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) {
Expand Down Expand Up @@ -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;
Expand All @@ -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))
Expand All @@ -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);

/*
Expand All @@ -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;
}
19 changes: 10 additions & 9 deletions trunk/drivers/sh/pfc/gpio.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}
Expand All @@ -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)
Expand All @@ -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;
}
Expand All @@ -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;
}
Expand Down
Loading

0 comments on commit 5d1c98d

Please sign in to comment.