Lines Matching full:pfc

11 #define DRV_NAME "sh-pfc"
31 static int sh_pfc_map_resources(struct sh_pfc *pfc, in sh_pfc_map_resources() argument
55 windows = devm_kcalloc(pfc->dev, num_windows, sizeof(*windows), in sh_pfc_map_resources()
60 pfc->num_windows = num_windows; in sh_pfc_map_resources()
61 pfc->windows = windows; in sh_pfc_map_resources()
64 irqs = devm_kcalloc(pfc->dev, num_irqs, sizeof(*irqs), in sh_pfc_map_resources()
69 pfc->num_irqs = num_irqs; in sh_pfc_map_resources()
70 pfc->irqs = irqs; in sh_pfc_map_resources()
88 static void __iomem *sh_pfc_phys_to_virt(struct sh_pfc *pfc, u32 reg) in sh_pfc_phys_to_virt() argument
95 for (i = 0; i < pfc->num_windows; i++) { in sh_pfc_phys_to_virt()
96 window = pfc->windows + i; in sh_pfc_phys_to_virt()
111 int sh_pfc_get_pin_index(struct sh_pfc *pfc, unsigned int pin) in sh_pfc_get_pin_index() argument
116 for (i = 0, offset = 0; i < pfc->nr_ranges; ++i) { in sh_pfc_get_pin_index()
117 const struct sh_pfc_pin_range *range = &pfc->ranges[i]; in sh_pfc_get_pin_index()
173 u32 sh_pfc_read(struct sh_pfc *pfc, u32 reg) in sh_pfc_read() argument
175 return sh_pfc_read_raw_reg(sh_pfc_phys_to_virt(pfc, reg), 32); in sh_pfc_read()
178 static void sh_pfc_unlock_reg(struct sh_pfc *pfc, u32 reg, u32 data) in sh_pfc_unlock_reg() argument
182 if (!pfc->info->unlock_reg) in sh_pfc_unlock_reg()
185 if (pfc->info->unlock_reg >= 0x80000000UL) in sh_pfc_unlock_reg()
186 unlock = pfc->info->unlock_reg; in sh_pfc_unlock_reg()
189 unlock = reg & ~pfc->info->unlock_reg; in sh_pfc_unlock_reg()
191 sh_pfc_write_raw_reg(sh_pfc_phys_to_virt(pfc, unlock), 32, ~data); in sh_pfc_unlock_reg()
194 void sh_pfc_write(struct sh_pfc *pfc, u32 reg, u32 data) in sh_pfc_write() argument
196 sh_pfc_unlock_reg(pfc, reg, data); in sh_pfc_write()
197 sh_pfc_write_raw_reg(sh_pfc_phys_to_virt(pfc, reg), 32, data); in sh_pfc_write()
200 static void sh_pfc_config_reg_helper(struct sh_pfc *pfc, in sh_pfc_config_reg_helper() argument
208 *mapped_regp = sh_pfc_phys_to_virt(pfc, crp->reg); in sh_pfc_config_reg_helper()
221 static void sh_pfc_write_config_reg(struct sh_pfc *pfc, in sh_pfc_write_config_reg() argument
229 sh_pfc_config_reg_helper(pfc, crp, field, &mapped_reg, &mask, &pos); in sh_pfc_write_config_reg()
231 dev_dbg(pfc->dev, "write_reg addr = %x, value = 0x%x, field = %u, " in sh_pfc_write_config_reg()
242 sh_pfc_unlock_reg(pfc, crp->reg, data); in sh_pfc_write_config_reg()
246 static int sh_pfc_get_config_reg(struct sh_pfc *pfc, u16 enum_id, in sh_pfc_get_config_reg() argument
254 pfc->info->cfg_regs + k; in sh_pfc_get_config_reg()
294 static int sh_pfc_mark_to_enum(struct sh_pfc *pfc, u16 mark, int pos, in sh_pfc_mark_to_enum() argument
297 const u16 *data = pfc->info->pinmux_data; in sh_pfc_mark_to_enum()
305 for (k = 0; k < pfc->info->pinmux_data_size; k++) { in sh_pfc_mark_to_enum()
312 dev_err(pfc->dev, "cannot locate data/mark enum_id for mark %d\n", in sh_pfc_mark_to_enum()
317 int sh_pfc_config_mux(struct sh_pfc *pfc, unsigned mark, int pinmux_type) in sh_pfc_config_mux() argument
330 range = &pfc->info->output; in sh_pfc_config_mux()
334 range = &pfc->info->input; in sh_pfc_config_mux()
351 pos = sh_pfc_mark_to_enum(pfc, mark, pos, &enum_id); in sh_pfc_config_mux()
362 in_range = sh_pfc_enum_in_range(enum_id, &pfc->info->function); in sh_pfc_config_mux()
389 ret = sh_pfc_get_config_reg(pfc, enum_id, &cr, &field, &value); in sh_pfc_config_mux()
393 sh_pfc_write_config_reg(pfc, cr, field, value); in sh_pfc_config_mux()
399 static int sh_pfc_init_ranges(struct sh_pfc *pfc) in sh_pfc_init_ranges() argument
405 if (pfc->info->pins[0].pin == (u16)-1) { in sh_pfc_init_ranges()
410 pfc->nr_ranges = 1; in sh_pfc_init_ranges()
411 pfc->ranges = devm_kzalloc(pfc->dev, sizeof(*pfc->ranges), in sh_pfc_init_ranges()
413 if (pfc->ranges == NULL) in sh_pfc_init_ranges()
416 pfc->ranges->start = 0; in sh_pfc_init_ranges()
417 pfc->ranges->end = pfc->info->nr_pins - 1; in sh_pfc_init_ranges()
418 pfc->nr_gpio_pins = pfc->info->nr_pins; in sh_pfc_init_ranges()
423 /* Count, allocate and fill the ranges. The PFC SoC data pins array must in sh_pfc_init_ranges()
427 for (i = 1, nr_ranges = 1; i < pfc->info->nr_pins; ++i) { in sh_pfc_init_ranges()
428 if (pfc->info->pins[i-1].pin != pfc->info->pins[i].pin - 1) in sh_pfc_init_ranges()
432 pfc->nr_ranges = nr_ranges; in sh_pfc_init_ranges()
433 pfc->ranges = devm_kcalloc(pfc->dev, nr_ranges, sizeof(*pfc->ranges), in sh_pfc_init_ranges()
435 if (pfc->ranges == NULL) in sh_pfc_init_ranges()
438 range = pfc->ranges; in sh_pfc_init_ranges()
439 range->start = pfc->info->pins[0].pin; in sh_pfc_init_ranges()
441 for (i = 1; i < pfc->info->nr_pins; ++i) { in sh_pfc_init_ranges()
442 if (pfc->info->pins[i-1].pin == pfc->info->pins[i].pin - 1) in sh_pfc_init_ranges()
445 range->end = pfc->info->pins[i-1].pin; in sh_pfc_init_ranges()
446 if (!(pfc->info->pins[i-1].configs & SH_PFC_PIN_CFG_NO_GPIO)) in sh_pfc_init_ranges()
447 pfc->nr_gpio_pins = range->end + 1; in sh_pfc_init_ranges()
450 range->start = pfc->info->pins[i].pin; in sh_pfc_init_ranges()
453 range->end = pfc->info->pins[i-1].pin; in sh_pfc_init_ranges()
454 if (!(pfc->info->pins[i-1].configs & SH_PFC_PIN_CFG_NO_GPIO)) in sh_pfc_init_ranges()
455 pfc->nr_gpio_pins = range->end + 1; in sh_pfc_init_ranges()
464 .compatible = "renesas,pfc-emev2",
470 .compatible = "renesas,pfc-r8a73a4",
476 .compatible = "renesas,pfc-r8a7740",
482 .compatible = "renesas,pfc-r8a7742",
488 .compatible = "renesas,pfc-r8a7743",
494 .compatible = "renesas,pfc-r8a7744",
500 .compatible = "renesas,pfc-r8a7745",
506 .compatible = "renesas,pfc-r8a77470",
512 .compatible = "renesas,pfc-r8a774a1",
518 .compatible = "renesas,pfc-r8a774b1",
524 .compatible = "renesas,pfc-r8a774c0",
530 .compatible = "renesas,pfc-r8a774e1",
536 .compatible = "renesas,pfc-r8a7778",
542 .compatible = "renesas,pfc-r8a7779",
548 .compatible = "renesas,pfc-r8a7790",
554 .compatible = "renesas,pfc-r8a7791",
560 .compatible = "renesas,pfc-r8a7792",
566 .compatible = "renesas,pfc-r8a7793",
572 .compatible = "renesas,pfc-r8a7794",
583 .compatible = "renesas,pfc-r8a7795",
589 .compatible = "renesas,pfc-r8a7795",
595 .compatible = "renesas,pfc-r8a7796",
601 .compatible = "renesas,pfc-r8a77961",
607 .compatible = "renesas,pfc-r8a77965",
613 .compatible = "renesas,pfc-r8a77970",
619 .compatible = "renesas,pfc-r8a77980",
625 .compatible = "renesas,pfc-r8a77990",
631 .compatible = "renesas,pfc-r8a77995",
637 .compatible = "renesas,pfc-r8a779a0",
643 .compatible = "renesas,pfc-r8a779f0",
649 .compatible = "renesas,pfc-r8a779g0",
655 .compatible = "renesas,pfc-sh73a0",
664 static void sh_pfc_nop_reg(struct sh_pfc *pfc, u32 reg, unsigned int idx) in sh_pfc_nop_reg() argument
668 static void sh_pfc_save_reg(struct sh_pfc *pfc, u32 reg, unsigned int idx) in sh_pfc_save_reg() argument
670 pfc->saved_regs[idx] = sh_pfc_read(pfc, reg); in sh_pfc_save_reg()
673 static void sh_pfc_restore_reg(struct sh_pfc *pfc, u32 reg, unsigned int idx) in sh_pfc_restore_reg() argument
675 sh_pfc_write(pfc, reg, pfc->saved_regs[idx]); in sh_pfc_restore_reg()
678 static unsigned int sh_pfc_walk_regs(struct sh_pfc *pfc, in sh_pfc_walk_regs() argument
679 void (*do_reg)(struct sh_pfc *pfc, u32 reg, unsigned int idx)) in sh_pfc_walk_regs() argument
683 if (pfc->info->cfg_regs) in sh_pfc_walk_regs()
684 for (i = 0; pfc->info->cfg_regs[i].reg; i++) in sh_pfc_walk_regs()
685 do_reg(pfc, pfc->info->cfg_regs[i].reg, n++); in sh_pfc_walk_regs()
687 if (pfc->info->drive_regs) in sh_pfc_walk_regs()
688 for (i = 0; pfc->info->drive_regs[i].reg; i++) in sh_pfc_walk_regs()
689 do_reg(pfc, pfc->info->drive_regs[i].reg, n++); in sh_pfc_walk_regs()
691 if (pfc->info->bias_regs) in sh_pfc_walk_regs()
692 for (i = 0; pfc->info->bias_regs[i].puen || in sh_pfc_walk_regs()
693 pfc->info->bias_regs[i].pud; i++) { in sh_pfc_walk_regs()
694 if (pfc->info->bias_regs[i].puen) in sh_pfc_walk_regs()
695 do_reg(pfc, pfc->info->bias_regs[i].puen, n++); in sh_pfc_walk_regs()
696 if (pfc->info->bias_regs[i].pud) in sh_pfc_walk_regs()
697 do_reg(pfc, pfc->info->bias_regs[i].pud, n++); in sh_pfc_walk_regs()
700 if (pfc->info->ioctrl_regs) in sh_pfc_walk_regs()
701 for (i = 0; pfc->info->ioctrl_regs[i].reg; i++) in sh_pfc_walk_regs()
702 do_reg(pfc, pfc->info->ioctrl_regs[i].reg, n++); in sh_pfc_walk_regs()
707 static int sh_pfc_suspend_init(struct sh_pfc *pfc) in sh_pfc_suspend_init() argument
715 n = sh_pfc_walk_regs(pfc, sh_pfc_nop_reg); in sh_pfc_suspend_init()
719 pfc->saved_regs = devm_kmalloc_array(pfc->dev, n, in sh_pfc_suspend_init()
720 sizeof(*pfc->saved_regs), in sh_pfc_suspend_init()
722 if (!pfc->saved_regs) in sh_pfc_suspend_init()
725 dev_dbg(pfc->dev, "Allocated space to save %u regs\n", n); in sh_pfc_suspend_init()
731 struct sh_pfc *pfc = dev_get_drvdata(dev); in sh_pfc_suspend_noirq() local
733 if (pfc->saved_regs) in sh_pfc_suspend_noirq()
734 sh_pfc_walk_regs(pfc, sh_pfc_save_reg); in sh_pfc_suspend_noirq()
740 struct sh_pfc *pfc = dev_get_drvdata(dev); in sh_pfc_resume_noirq() local
742 if (pfc->saved_regs) in sh_pfc_resume_noirq()
743 sh_pfc_walk_regs(pfc, sh_pfc_restore_reg); in sh_pfc_resume_noirq()
752 static int sh_pfc_suspend_init(struct sh_pfc *pfc) { return 0; } in sh_pfc_suspend_init() argument
1337 struct sh_pfc *pfc; in sh_pfc_probe() local
1349 pfc = devm_kzalloc(&pdev->dev, sizeof(*pfc), GFP_KERNEL); in sh_pfc_probe()
1350 if (pfc == NULL) in sh_pfc_probe()
1353 pfc->info = info; in sh_pfc_probe()
1354 pfc->dev = &pdev->dev; in sh_pfc_probe()
1356 ret = sh_pfc_map_resources(pfc, pdev); in sh_pfc_probe()
1360 spin_lock_init(&pfc->lock); in sh_pfc_probe()
1363 ret = info->ops->init(pfc); in sh_pfc_probe()
1367 /* .init() may have overridden pfc->info */ in sh_pfc_probe()
1368 info = pfc->info; in sh_pfc_probe()
1371 ret = sh_pfc_suspend_init(pfc); in sh_pfc_probe()
1379 ret = sh_pfc_init_ranges(pfc); in sh_pfc_probe()
1386 ret = sh_pfc_register_pinctrl(pfc); in sh_pfc_probe()
1394 ret = sh_pfc_register_gpiochip(pfc); in sh_pfc_probe()
1398 * PFC state as it is, given that there are already in sh_pfc_probe()
1401 dev_notice(pfc->dev, "failed to init GPIO chip, ignoring...\n"); in sh_pfc_probe()
1405 platform_set_drvdata(pdev, pfc); in sh_pfc_probe()
1407 dev_info(pfc->dev, "%s support registered\n", info->name); in sh_pfc_probe()
1414 { "pfc-sh7203", (kernel_ulong_t)&sh7203_pinmux_info },
1417 { "pfc-sh7264", (kernel_ulong_t)&sh7264_pinmux_info },
1420 { "pfc-sh7269", (kernel_ulong_t)&sh7269_pinmux_info },
1423 { "pfc-sh7720", (kernel_ulong_t)&sh7720_pinmux_info },
1426 { "pfc-sh7722", (kernel_ulong_t)&sh7722_pinmux_info },
1429 { "pfc-sh7723", (kernel_ulong_t)&sh7723_pinmux_info },
1432 { "pfc-sh7724", (kernel_ulong_t)&sh7724_pinmux_info },
1435 { "pfc-sh7734", (kernel_ulong_t)&sh7734_pinmux_info },
1438 { "pfc-sh7757", (kernel_ulong_t)&sh7757_pinmux_info },
1441 { "pfc-sh7785", (kernel_ulong_t)&sh7785_pinmux_info },
1444 { "pfc-sh7786", (kernel_ulong_t)&sh7786_pinmux_info },
1447 { "pfc-shx3", (kernel_ulong_t)&shx3_pinmux_info },