aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/sh/pfc/core.c
diff options
context:
space:
mode:
authorLaurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>2012-12-15 17:50:43 -0500
committerSimon Horman <horms+renesas@verge.net.au>2013-01-24 19:24:20 -0500
commitd4e62d0094e1b0f69946c3f16ce8ec882302a461 (patch)
treefd39f7a3ee241d0c8af31220143caebdafe45c7c /drivers/sh/pfc/core.c
parente62ebcdbce9eff4dc48168e86960c0dfcba086ea (diff)
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 <laurent.pinchart+renesas@ideasonboard.com> Acked-by: Paul Mundt <lethal@linux-sh.org> Acked-by: Linus Walleij <linus.walleij@linaro.org> Signed-off-by: Simon Horman <horms+renesas@verge.net.au>
Diffstat (limited to 'drivers/sh/pfc/core.c')
-rw-r--r--drivers/sh/pfc/core.c89
1 files changed, 43 insertions, 46 deletions
diff --git a/drivers/sh/pfc/core.c b/drivers/sh/pfc/core.c
index 68169373c98b..ecbe51d9f563 100644
--- a/drivers/sh/pfc/core.c
+++ b/drivers/sh/pfc/core.c
@@ -21,18 +21,13 @@
21#include <linux/ioport.h> 21#include <linux/ioport.h>
22#include <linux/pinctrl/machine.h> 22#include <linux/pinctrl/machine.h>
23 23
24static struct sh_pfc *sh_pfc __read_mostly; 24static struct sh_pfc sh_pfc __read_mostly;
25
26static inline bool sh_pfc_initialized(void)
27{
28 return !!sh_pfc;
29}
30 25
31static void pfc_iounmap(struct sh_pfc *pfc) 26static void pfc_iounmap(struct sh_pfc *pfc)
32{ 27{
33 int k; 28 int k;
34 29
35 for (k = 0; k < pfc->num_resources; k++) 30 for (k = 0; k < pfc->pdata->num_resources; k++)
36 if (pfc->window[k].virt) 31 if (pfc->window[k].virt)
37 iounmap(pfc->window[k].virt); 32 iounmap(pfc->window[k].virt);
38 33
@@ -45,16 +40,16 @@ static int pfc_ioremap(struct sh_pfc *pfc)
45 struct resource *res; 40 struct resource *res;
46 int k; 41 int k;
47 42
48 if (!pfc->num_resources) 43 if (!pfc->pdata->num_resources)
49 return 0; 44 return 0;
50 45
51 pfc->window = kzalloc(pfc->num_resources * sizeof(*pfc->window), 46 pfc->window = kzalloc(pfc->pdata->num_resources * sizeof(*pfc->window),
52 GFP_NOWAIT); 47 GFP_NOWAIT);
53 if (!pfc->window) 48 if (!pfc->window)
54 goto err1; 49 goto err1;
55 50
56 for (k = 0; k < pfc->num_resources; k++) { 51 for (k = 0; k < pfc->pdata->num_resources; k++) {
57 res = pfc->resource + k; 52 res = pfc->pdata->resource + k;
58 WARN_ON(resource_type(res) != IORESOURCE_MEM); 53 WARN_ON(resource_type(res) != IORESOURCE_MEM);
59 pfc->window[k].phys = res->start; 54 pfc->window[k].phys = res->start;
60 pfc->window[k].size = resource_size(res); 55 pfc->window[k].size = resource_size(res);
@@ -79,7 +74,7 @@ static void __iomem *pfc_phys_to_virt(struct sh_pfc *pfc,
79 int k; 74 int k;
80 75
81 /* scan through physical windows and convert address */ 76 /* scan through physical windows and convert address */
82 for (k = 0; k < pfc->num_resources; k++) { 77 for (k = 0; k < pfc->pdata->num_resources; k++) {
83 window = pfc->window + k; 78 window = pfc->window + k;
84 79
85 if (address < window->phys) 80 if (address < window->phys)
@@ -232,8 +227,8 @@ static void write_config_reg(struct sh_pfc *pfc,
232 data &= mask; 227 data &= mask;
233 data |= value; 228 data |= value;
234 229
235 if (pfc->unlock_reg) 230 if (pfc->pdata->unlock_reg)
236 gpio_write_raw_reg(pfc_phys_to_virt(pfc, pfc->unlock_reg), 231 gpio_write_raw_reg(pfc_phys_to_virt(pfc, pfc->pdata->unlock_reg),
237 32, ~data); 232 32, ~data);
238 233
239 gpio_write_raw_reg(mapped_reg, crp->reg_width, data); 234 gpio_write_raw_reg(mapped_reg, crp->reg_width, data);
@@ -241,16 +236,16 @@ static void write_config_reg(struct sh_pfc *pfc,
241 236
242static int setup_data_reg(struct sh_pfc *pfc, unsigned gpio) 237static int setup_data_reg(struct sh_pfc *pfc, unsigned gpio)
243{ 238{
244 struct pinmux_gpio *gpiop = &pfc->gpios[gpio]; 239 struct pinmux_gpio *gpiop = &pfc->pdata->gpios[gpio];
245 struct pinmux_data_reg *data_reg; 240 struct pinmux_data_reg *data_reg;
246 int k, n; 241 int k, n;
247 242
248 if (!enum_in_range(gpiop->enum_id, &pfc->data)) 243 if (!enum_in_range(gpiop->enum_id, &pfc->pdata->data))
249 return -1; 244 return -1;
250 245
251 k = 0; 246 k = 0;
252 while (1) { 247 while (1) {
253 data_reg = pfc->data_regs + k; 248 data_reg = pfc->pdata->data_regs + k;
254 249
255 if (!data_reg->reg_width) 250 if (!data_reg->reg_width)
256 break; 251 break;
@@ -279,12 +274,12 @@ static void setup_data_regs(struct sh_pfc *pfc)
279 struct pinmux_data_reg *drp; 274 struct pinmux_data_reg *drp;
280 int k; 275 int k;
281 276
282 for (k = pfc->first_gpio; k <= pfc->last_gpio; k++) 277 for (k = pfc->pdata->first_gpio; k <= pfc->pdata->last_gpio; k++)
283 setup_data_reg(pfc, k); 278 setup_data_reg(pfc, k);
284 279
285 k = 0; 280 k = 0;
286 while (1) { 281 while (1) {
287 drp = pfc->data_regs + k; 282 drp = pfc->pdata->data_regs + k;
288 283
289 if (!drp->reg_width) 284 if (!drp->reg_width)
290 break; 285 break;
@@ -298,15 +293,15 @@ static void setup_data_regs(struct sh_pfc *pfc)
298int sh_pfc_get_data_reg(struct sh_pfc *pfc, unsigned gpio, 293int sh_pfc_get_data_reg(struct sh_pfc *pfc, unsigned gpio,
299 struct pinmux_data_reg **drp, int *bitp) 294 struct pinmux_data_reg **drp, int *bitp)
300{ 295{
301 struct pinmux_gpio *gpiop = &pfc->gpios[gpio]; 296 struct pinmux_gpio *gpiop = &pfc->pdata->gpios[gpio];
302 int k, n; 297 int k, n;
303 298
304 if (!enum_in_range(gpiop->enum_id, &pfc->data)) 299 if (!enum_in_range(gpiop->enum_id, &pfc->pdata->data))
305 return -1; 300 return -1;
306 301
307 k = (gpiop->flags & PINMUX_FLAG_DREG) >> PINMUX_FLAG_DREG_SHIFT; 302 k = (gpiop->flags & PINMUX_FLAG_DREG) >> PINMUX_FLAG_DREG_SHIFT;
308 n = (gpiop->flags & PINMUX_FLAG_DBIT) >> PINMUX_FLAG_DBIT_SHIFT; 303 n = (gpiop->flags & PINMUX_FLAG_DBIT) >> PINMUX_FLAG_DBIT_SHIFT;
309 *drp = pfc->data_regs + k; 304 *drp = pfc->pdata->data_regs + k;
310 *bitp = n; 305 *bitp = n;
311 return 0; 306 return 0;
312} 307}
@@ -323,7 +318,7 @@ static int get_config_reg(struct sh_pfc *pfc, pinmux_enum_t enum_id,
323 318
324 k = 0; 319 k = 0;
325 while (1) { 320 while (1) {
326 config_reg = pfc->cfg_regs + k; 321 config_reg = pfc->pdata->cfg_regs + k;
327 322
328 r_width = config_reg->reg_width; 323 r_width = config_reg->reg_width;
329 f_width = config_reg->field_width; 324 f_width = config_reg->field_width;
@@ -361,12 +356,12 @@ static int get_config_reg(struct sh_pfc *pfc, pinmux_enum_t enum_id,
361int sh_pfc_gpio_to_enum(struct sh_pfc *pfc, unsigned gpio, int pos, 356int sh_pfc_gpio_to_enum(struct sh_pfc *pfc, unsigned gpio, int pos,
362 pinmux_enum_t *enum_idp) 357 pinmux_enum_t *enum_idp)
363{ 358{
364 pinmux_enum_t enum_id = pfc->gpios[gpio].enum_id; 359 pinmux_enum_t enum_id = pfc->pdata->gpios[gpio].enum_id;
365 pinmux_enum_t *data = pfc->gpio_data; 360 pinmux_enum_t *data = pfc->pdata->gpio_data;
366 int k; 361 int k;
367 362
368 if (!enum_in_range(enum_id, &pfc->data)) { 363 if (!enum_in_range(enum_id, &pfc->pdata->data)) {
369 if (!enum_in_range(enum_id, &pfc->mark)) { 364 if (!enum_in_range(enum_id, &pfc->pdata->mark)) {
370 pr_err("non data/mark enum_id for gpio %d\n", gpio); 365 pr_err("non data/mark enum_id for gpio %d\n", gpio);
371 return -1; 366 return -1;
372 } 367 }
@@ -377,7 +372,7 @@ int sh_pfc_gpio_to_enum(struct sh_pfc *pfc, unsigned gpio, int pos,
377 return pos + 1; 372 return pos + 1;
378 } 373 }
379 374
380 for (k = 0; k < pfc->gpio_data_size; k++) { 375 for (k = 0; k < pfc->pdata->gpio_data_size; k++) {
381 if (data[k] == enum_id) { 376 if (data[k] == enum_id) {
382 *enum_idp = data[k + 1]; 377 *enum_idp = data[k + 1];
383 return k + 1; 378 return k + 1;
@@ -405,19 +400,19 @@ int sh_pfc_config_gpio(struct sh_pfc *pfc, unsigned gpio, int pinmux_type,
405 break; 400 break;
406 401
407 case PINMUX_TYPE_OUTPUT: 402 case PINMUX_TYPE_OUTPUT:
408 range = &pfc->output; 403 range = &pfc->pdata->output;
409 break; 404 break;
410 405
411 case PINMUX_TYPE_INPUT: 406 case PINMUX_TYPE_INPUT:
412 range = &pfc->input; 407 range = &pfc->pdata->input;
413 break; 408 break;
414 409
415 case PINMUX_TYPE_INPUT_PULLUP: 410 case PINMUX_TYPE_INPUT_PULLUP:
416 range = &pfc->input_pu; 411 range = &pfc->pdata->input_pu;
417 break; 412 break;
418 413
419 case PINMUX_TYPE_INPUT_PULLDOWN: 414 case PINMUX_TYPE_INPUT_PULLDOWN:
420 range = &pfc->input_pd; 415 range = &pfc->pdata->input_pd;
421 break; 416 break;
422 417
423 default: 418 default:
@@ -437,7 +432,7 @@ int sh_pfc_config_gpio(struct sh_pfc *pfc, unsigned gpio, int pinmux_type,
437 break; 432 break;
438 433
439 /* first check if this is a function enum */ 434 /* first check if this is a function enum */
440 in_range = enum_in_range(enum_id, &pfc->function); 435 in_range = enum_in_range(enum_id, &pfc->pdata->function);
441 if (!in_range) { 436 if (!in_range) {
442 /* not a function enum */ 437 /* not a function enum */
443 if (range) { 438 if (range) {
@@ -502,7 +497,7 @@ int sh_pfc_config_gpio(struct sh_pfc *pfc, unsigned gpio, int pinmux_type,
502} 497}
503EXPORT_SYMBOL_GPL(sh_pfc_config_gpio); 498EXPORT_SYMBOL_GPL(sh_pfc_config_gpio);
504 499
505int register_sh_pfc(struct sh_pfc *pfc) 500int register_sh_pfc(struct sh_pfc_platform_data *pdata)
506{ 501{
507 int (*initroutine)(struct sh_pfc *) = NULL; 502 int (*initroutine)(struct sh_pfc *) = NULL;
508 int ret; 503 int ret;
@@ -512,26 +507,28 @@ int register_sh_pfc(struct sh_pfc *pfc)
512 */ 507 */
513 BUILD_BUG_ON(PINMUX_FLAG_TYPE > ((1 << PINMUX_FLAG_DBIT_SHIFT) - 1)); 508 BUILD_BUG_ON(PINMUX_FLAG_TYPE > ((1 << PINMUX_FLAG_DBIT_SHIFT) - 1));
514 509
515 if (sh_pfc) 510 if (sh_pfc.pdata)
516 return -EBUSY; 511 return -EBUSY;
517 512
518 ret = pfc_ioremap(pfc); 513 sh_pfc.pdata = pdata;
519 if (unlikely(ret < 0)) 514
515 ret = pfc_ioremap(&sh_pfc);
516 if (unlikely(ret < 0)) {
517 sh_pfc.pdata = NULL;
520 return ret; 518 return ret;
519 }
521 520
522 spin_lock_init(&pfc->lock); 521 spin_lock_init(&sh_pfc.lock);
523 522
524 pinctrl_provide_dummies(); 523 pinctrl_provide_dummies();
525 setup_data_regs(pfc); 524 setup_data_regs(&sh_pfc);
526
527 sh_pfc = pfc;
528 525
529 /* 526 /*
530 * Initialize pinctrl bindings first 527 * Initialize pinctrl bindings first
531 */ 528 */
532 initroutine = symbol_request(sh_pfc_register_pinctrl); 529 initroutine = symbol_request(sh_pfc_register_pinctrl);
533 if (initroutine) { 530 if (initroutine) {
534 ret = (*initroutine)(pfc); 531 ret = (*initroutine)(&sh_pfc);
535 symbol_put_addr(initroutine); 532 symbol_put_addr(initroutine);
536 533
537 if (unlikely(ret != 0)) 534 if (unlikely(ret != 0))
@@ -546,7 +543,7 @@ int register_sh_pfc(struct sh_pfc *pfc)
546 */ 543 */
547 initroutine = symbol_request(sh_pfc_register_gpiochip); 544 initroutine = symbol_request(sh_pfc_register_gpiochip);
548 if (initroutine) { 545 if (initroutine) {
549 ret = (*initroutine)(pfc); 546 ret = (*initroutine)(&sh_pfc);
550 symbol_put_addr(initroutine); 547 symbol_put_addr(initroutine);
551 548
552 /* 549 /*
@@ -560,13 +557,13 @@ int register_sh_pfc(struct sh_pfc *pfc)
560 } 557 }
561 } 558 }
562 559
563 pr_info("%s support registered\n", pfc->name); 560 pr_info("%s support registered\n", sh_pfc.pdata->name);
564 561
565 return 0; 562 return 0;
566 563
567err: 564err:
568 pfc_iounmap(pfc); 565 pfc_iounmap(&sh_pfc);
569 sh_pfc = NULL; 566 sh_pfc.pdata = NULL;
570 567
571 return ret; 568 return ret;
572} 569}