Lines Matching full:pfc
11 #define DRV_NAME "sh-pfc"
30 static int sh_pfc_map_resources(struct sh_pfc *pfc, in sh_pfc_map_resources() argument
54 windows = devm_kcalloc(pfc->dev, num_windows, sizeof(*windows), in sh_pfc_map_resources()
59 pfc->num_windows = num_windows; in sh_pfc_map_resources()
60 pfc->windows = windows; in sh_pfc_map_resources()
63 irqs = devm_kcalloc(pfc->dev, num_irqs, sizeof(*irqs), in sh_pfc_map_resources()
68 pfc->num_irqs = num_irqs; in sh_pfc_map_resources()
69 pfc->irqs = irqs; in sh_pfc_map_resources()
87 static void __iomem *sh_pfc_phys_to_virt(struct sh_pfc *pfc, u32 reg) in sh_pfc_phys_to_virt() argument
94 for (i = 0; i < pfc->num_windows; i++) { in sh_pfc_phys_to_virt()
95 window = pfc->windows + i; in sh_pfc_phys_to_virt()
110 int sh_pfc_get_pin_index(struct sh_pfc *pfc, unsigned int pin) in sh_pfc_get_pin_index() argument
115 for (i = 0, offset = 0; i < pfc->nr_ranges; ++i) { in sh_pfc_get_pin_index()
116 const struct sh_pfc_pin_range *range = &pfc->ranges[i]; in sh_pfc_get_pin_index()
172 u32 sh_pfc_read(struct sh_pfc *pfc, u32 reg) in sh_pfc_read() argument
174 return sh_pfc_read_raw_reg(sh_pfc_phys_to_virt(pfc, reg), 32); in sh_pfc_read()
177 static void sh_pfc_unlock_reg(struct sh_pfc *pfc, u32 reg, u32 data) in sh_pfc_unlock_reg() argument
181 if (!pfc->info->unlock_reg) in sh_pfc_unlock_reg()
184 if (pfc->info->unlock_reg >= 0x80000000UL) in sh_pfc_unlock_reg()
185 unlock = pfc->info->unlock_reg; in sh_pfc_unlock_reg()
188 unlock = reg & ~pfc->info->unlock_reg; in sh_pfc_unlock_reg()
190 sh_pfc_write_raw_reg(sh_pfc_phys_to_virt(pfc, unlock), 32, ~data); in sh_pfc_unlock_reg()
193 void sh_pfc_write(struct sh_pfc *pfc, u32 reg, u32 data) in sh_pfc_write() argument
195 sh_pfc_unlock_reg(pfc, reg, data); in sh_pfc_write()
196 sh_pfc_write_raw_reg(sh_pfc_phys_to_virt(pfc, reg), 32, data); in sh_pfc_write()
199 static void sh_pfc_config_reg_helper(struct sh_pfc *pfc, in sh_pfc_config_reg_helper() argument
207 *mapped_regp = sh_pfc_phys_to_virt(pfc, crp->reg); in sh_pfc_config_reg_helper()
220 static void sh_pfc_write_config_reg(struct sh_pfc *pfc, in sh_pfc_write_config_reg() argument
228 sh_pfc_config_reg_helper(pfc, crp, field, &mapped_reg, &mask, &pos); in sh_pfc_write_config_reg()
230 dev_dbg(pfc->dev, "write_reg addr = %x, value = 0x%x, field = %u, " in sh_pfc_write_config_reg()
241 sh_pfc_unlock_reg(pfc, crp->reg, data); in sh_pfc_write_config_reg()
245 static int sh_pfc_get_config_reg(struct sh_pfc *pfc, u16 enum_id, in sh_pfc_get_config_reg() argument
253 pfc->info->cfg_regs + k; in sh_pfc_get_config_reg()
293 static int sh_pfc_mark_to_enum(struct sh_pfc *pfc, u16 mark, int pos, in sh_pfc_mark_to_enum() argument
296 const u16 *data = pfc->info->pinmux_data; in sh_pfc_mark_to_enum()
304 for (k = 0; k < pfc->info->pinmux_data_size; k++) { in sh_pfc_mark_to_enum()
311 dev_err(pfc->dev, "cannot locate data/mark enum_id for mark %d\n", in sh_pfc_mark_to_enum()
316 int sh_pfc_config_mux(struct sh_pfc *pfc, unsigned mark, int pinmux_type) in sh_pfc_config_mux() argument
329 range = &pfc->info->output; in sh_pfc_config_mux()
333 range = &pfc->info->input; in sh_pfc_config_mux()
350 pos = sh_pfc_mark_to_enum(pfc, mark, pos, &enum_id); in sh_pfc_config_mux()
361 in_range = sh_pfc_enum_in_range(enum_id, &pfc->info->function); in sh_pfc_config_mux()
388 ret = sh_pfc_get_config_reg(pfc, enum_id, &cr, &field, &value); in sh_pfc_config_mux()
392 sh_pfc_write_config_reg(pfc, cr, field, value); in sh_pfc_config_mux()
398 static int sh_pfc_init_ranges(struct sh_pfc *pfc) in sh_pfc_init_ranges() argument
404 if (pfc->info->pins[0].pin == (u16)-1) { in sh_pfc_init_ranges()
409 pfc->nr_ranges = 1; in sh_pfc_init_ranges()
410 pfc->ranges = devm_kzalloc(pfc->dev, sizeof(*pfc->ranges), in sh_pfc_init_ranges()
412 if (pfc->ranges == NULL) in sh_pfc_init_ranges()
415 pfc->ranges->start = 0; in sh_pfc_init_ranges()
416 pfc->ranges->end = pfc->info->nr_pins - 1; in sh_pfc_init_ranges()
417 pfc->nr_gpio_pins = pfc->info->nr_pins; in sh_pfc_init_ranges()
422 /* Count, allocate and fill the ranges. The PFC SoC data pins array must in sh_pfc_init_ranges()
426 for (i = 1, nr_ranges = 1; i < pfc->info->nr_pins; ++i) { in sh_pfc_init_ranges()
427 if (pfc->info->pins[i-1].pin != pfc->info->pins[i].pin - 1) in sh_pfc_init_ranges()
431 pfc->nr_ranges = nr_ranges; in sh_pfc_init_ranges()
432 pfc->ranges = devm_kcalloc(pfc->dev, nr_ranges, sizeof(*pfc->ranges), in sh_pfc_init_ranges()
434 if (pfc->ranges == NULL) in sh_pfc_init_ranges()
437 range = pfc->ranges; in sh_pfc_init_ranges()
438 range->start = pfc->info->pins[0].pin; in sh_pfc_init_ranges()
440 for (i = 1; i < pfc->info->nr_pins; ++i) { in sh_pfc_init_ranges()
441 if (pfc->info->pins[i-1].pin == pfc->info->pins[i].pin - 1) in sh_pfc_init_ranges()
444 range->end = pfc->info->pins[i-1].pin; in sh_pfc_init_ranges()
445 if (!(pfc->info->pins[i-1].configs & SH_PFC_PIN_CFG_NO_GPIO)) in sh_pfc_init_ranges()
446 pfc->nr_gpio_pins = range->end + 1; in sh_pfc_init_ranges()
449 range->start = pfc->info->pins[i].pin; in sh_pfc_init_ranges()
452 range->end = pfc->info->pins[i-1].pin; in sh_pfc_init_ranges()
453 if (!(pfc->info->pins[i-1].configs & SH_PFC_PIN_CFG_NO_GPIO)) in sh_pfc_init_ranges()
454 pfc->nr_gpio_pins = range->end + 1; in sh_pfc_init_ranges()
463 .compatible = "renesas,pfc-emev2",
469 .compatible = "renesas,pfc-r8a73a4",
475 .compatible = "renesas,pfc-r8a7740",
481 .compatible = "renesas,pfc-r8a7742",
487 .compatible = "renesas,pfc-r8a7743",
493 .compatible = "renesas,pfc-r8a7744",
499 .compatible = "renesas,pfc-r8a7745",
505 .compatible = "renesas,pfc-r8a77470",
511 .compatible = "renesas,pfc-r8a774a1",
517 .compatible = "renesas,pfc-r8a774b1",
523 .compatible = "renesas,pfc-r8a774c0",
529 .compatible = "renesas,pfc-r8a774e1",
535 .compatible = "renesas,pfc-r8a7778",
541 .compatible = "renesas,pfc-r8a7779",
547 .compatible = "renesas,pfc-r8a7790",
553 .compatible = "renesas,pfc-r8a7791",
559 .compatible = "renesas,pfc-r8a7792",
565 .compatible = "renesas,pfc-r8a7793",
571 .compatible = "renesas,pfc-r8a7794",
577 .compatible = "renesas,pfc-r8a7795",
583 .compatible = "renesas,pfc-r8a7796",
589 .compatible = "renesas,pfc-r8a77961",
595 .compatible = "renesas,pfc-r8a77965",
601 .compatible = "renesas,pfc-r8a77970",
607 .compatible = "renesas,pfc-r8a77980",
613 .compatible = "renesas,pfc-r8a77990",
619 .compatible = "renesas,pfc-r8a77995",
625 .compatible = "renesas,pfc-r8a779a0",
631 .compatible = "renesas,pfc-r8a779f0",
637 .compatible = "renesas,pfc-r8a779g0",
643 .compatible = "renesas,pfc-r8a779h0",
649 .compatible = "renesas,pfc-sh73a0",
658 static void sh_pfc_nop_reg(struct sh_pfc *pfc, u32 reg, unsigned int idx) in sh_pfc_nop_reg() argument
662 static void sh_pfc_save_reg(struct sh_pfc *pfc, u32 reg, unsigned int idx) in sh_pfc_save_reg() argument
664 pfc->saved_regs[idx] = sh_pfc_read(pfc, reg); in sh_pfc_save_reg()
667 static void sh_pfc_restore_reg(struct sh_pfc *pfc, u32 reg, unsigned int idx) in sh_pfc_restore_reg() argument
669 sh_pfc_write(pfc, reg, pfc->saved_regs[idx]); in sh_pfc_restore_reg()
672 static unsigned int sh_pfc_walk_regs(struct sh_pfc *pfc, in sh_pfc_walk_regs() argument
673 void (*do_reg)(struct sh_pfc *pfc, u32 reg, unsigned int idx)) in sh_pfc_walk_regs() argument
677 if (pfc->info->cfg_regs) in sh_pfc_walk_regs()
678 for (i = 0; pfc->info->cfg_regs[i].reg; i++) in sh_pfc_walk_regs()
679 do_reg(pfc, pfc->info->cfg_regs[i].reg, n++); in sh_pfc_walk_regs()
681 if (pfc->info->drive_regs) in sh_pfc_walk_regs()
682 for (i = 0; pfc->info->drive_regs[i].reg; i++) in sh_pfc_walk_regs()
683 do_reg(pfc, pfc->info->drive_regs[i].reg, n++); in sh_pfc_walk_regs()
685 if (pfc->info->bias_regs) in sh_pfc_walk_regs()
686 for (i = 0; pfc->info->bias_regs[i].puen || in sh_pfc_walk_regs()
687 pfc->info->bias_regs[i].pud; i++) { in sh_pfc_walk_regs()
688 if (pfc->info->bias_regs[i].puen) in sh_pfc_walk_regs()
689 do_reg(pfc, pfc->info->bias_regs[i].puen, n++); in sh_pfc_walk_regs()
690 if (pfc->info->bias_regs[i].pud) in sh_pfc_walk_regs()
691 do_reg(pfc, pfc->info->bias_regs[i].pud, n++); in sh_pfc_walk_regs()
694 if (pfc->info->ioctrl_regs) in sh_pfc_walk_regs()
695 for (i = 0; pfc->info->ioctrl_regs[i].reg; i++) in sh_pfc_walk_regs()
696 do_reg(pfc, pfc->info->ioctrl_regs[i].reg, n++); in sh_pfc_walk_regs()
701 static int sh_pfc_suspend_init(struct sh_pfc *pfc) in sh_pfc_suspend_init() argument
709 n = sh_pfc_walk_regs(pfc, sh_pfc_nop_reg); in sh_pfc_suspend_init()
713 pfc->saved_regs = devm_kmalloc_array(pfc->dev, n, in sh_pfc_suspend_init()
714 sizeof(*pfc->saved_regs), in sh_pfc_suspend_init()
716 if (!pfc->saved_regs) in sh_pfc_suspend_init()
719 dev_dbg(pfc->dev, "Allocated space to save %u regs\n", n); in sh_pfc_suspend_init()
725 struct sh_pfc *pfc = dev_get_drvdata(dev); in sh_pfc_suspend_noirq() local
727 if (pfc->saved_regs) in sh_pfc_suspend_noirq()
728 sh_pfc_walk_regs(pfc, sh_pfc_save_reg); in sh_pfc_suspend_noirq()
734 struct sh_pfc *pfc = dev_get_drvdata(dev); in sh_pfc_resume_noirq() local
736 if (pfc->saved_regs) in sh_pfc_resume_noirq()
737 sh_pfc_walk_regs(pfc, sh_pfc_restore_reg); in sh_pfc_resume_noirq()
742 static int sh_pfc_suspend_init(struct sh_pfc *pfc) { return 0; } in sh_pfc_suspend_init() argument
1311 struct sh_pfc *pfc; in sh_pfc_probe() local
1319 pfc = devm_kzalloc(&pdev->dev, sizeof(*pfc), GFP_KERNEL); in sh_pfc_probe()
1320 if (pfc == NULL) in sh_pfc_probe()
1323 pfc->info = info; in sh_pfc_probe()
1324 pfc->dev = &pdev->dev; in sh_pfc_probe()
1326 ret = sh_pfc_map_resources(pfc, pdev); in sh_pfc_probe()
1330 spin_lock_init(&pfc->lock); in sh_pfc_probe()
1333 ret = info->ops->init(pfc); in sh_pfc_probe()
1337 /* .init() may have overridden pfc->info */ in sh_pfc_probe()
1338 info = pfc->info; in sh_pfc_probe()
1341 ret = sh_pfc_suspend_init(pfc); in sh_pfc_probe()
1349 ret = sh_pfc_init_ranges(pfc); in sh_pfc_probe()
1356 ret = sh_pfc_register_pinctrl(pfc); in sh_pfc_probe()
1364 ret = sh_pfc_register_gpiochip(pfc); in sh_pfc_probe()
1368 * PFC state as it is, given that there are already in sh_pfc_probe()
1371 dev_notice(pfc->dev, "failed to init GPIO chip, ignoring...\n"); in sh_pfc_probe()
1375 platform_set_drvdata(pdev, pfc); in sh_pfc_probe()
1377 dev_info(pfc->dev, "%s support registered\n", info->name); in sh_pfc_probe()
1384 { "pfc-sh7203", (kernel_ulong_t)&sh7203_pinmux_info },
1387 { "pfc-sh7264", (kernel_ulong_t)&sh7264_pinmux_info },
1390 { "pfc-sh7269", (kernel_ulong_t)&sh7269_pinmux_info },
1393 { "pfc-sh7720", (kernel_ulong_t)&sh7720_pinmux_info },
1396 { "pfc-sh7722", (kernel_ulong_t)&sh7722_pinmux_info },
1399 { "pfc-sh7723", (kernel_ulong_t)&sh7723_pinmux_info },
1402 { "pfc-sh7724", (kernel_ulong_t)&sh7724_pinmux_info },
1405 { "pfc-sh7734", (kernel_ulong_t)&sh7734_pinmux_info },
1408 { "pfc-sh7757", (kernel_ulong_t)&sh7757_pinmux_info },
1411 { "pfc-sh7785", (kernel_ulong_t)&sh7785_pinmux_info },
1414 { "pfc-sh7786", (kernel_ulong_t)&sh7786_pinmux_info },
1417 { "pfc-shx3", (kernel_ulong_t)&shx3_pinmux_info },