Lines Matching refs: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()
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()
652 static void sh_pfc_nop_reg(struct sh_pfc *pfc, u32 reg, unsigned int idx) in sh_pfc_nop_reg() argument
656 static void sh_pfc_save_reg(struct sh_pfc *pfc, u32 reg, unsigned int idx) in sh_pfc_save_reg() argument
658 pfc->saved_regs[idx] = sh_pfc_read(pfc, reg); in sh_pfc_save_reg()
661 static void sh_pfc_restore_reg(struct sh_pfc *pfc, u32 reg, unsigned int idx) in sh_pfc_restore_reg() argument
663 sh_pfc_write(pfc, reg, pfc->saved_regs[idx]); in sh_pfc_restore_reg()
666 static unsigned int sh_pfc_walk_regs(struct sh_pfc *pfc, in sh_pfc_walk_regs() argument
667 void (*do_reg)(struct sh_pfc *pfc, u32 reg, unsigned int idx)) in sh_pfc_walk_regs() argument
671 if (pfc->info->cfg_regs) in sh_pfc_walk_regs()
672 for (i = 0; pfc->info->cfg_regs[i].reg; i++) in sh_pfc_walk_regs()
673 do_reg(pfc, pfc->info->cfg_regs[i].reg, n++); in sh_pfc_walk_regs()
675 if (pfc->info->drive_regs) in sh_pfc_walk_regs()
676 for (i = 0; pfc->info->drive_regs[i].reg; i++) in sh_pfc_walk_regs()
677 do_reg(pfc, pfc->info->drive_regs[i].reg, n++); in sh_pfc_walk_regs()
679 if (pfc->info->bias_regs) in sh_pfc_walk_regs()
680 for (i = 0; pfc->info->bias_regs[i].puen || in sh_pfc_walk_regs()
681 pfc->info->bias_regs[i].pud; i++) { in sh_pfc_walk_regs()
682 if (pfc->info->bias_regs[i].puen) in sh_pfc_walk_regs()
683 do_reg(pfc, pfc->info->bias_regs[i].puen, n++); in sh_pfc_walk_regs()
684 if (pfc->info->bias_regs[i].pud) in sh_pfc_walk_regs()
685 do_reg(pfc, pfc->info->bias_regs[i].pud, n++); in sh_pfc_walk_regs()
688 if (pfc->info->ioctrl_regs) in sh_pfc_walk_regs()
689 for (i = 0; pfc->info->ioctrl_regs[i].reg; i++) in sh_pfc_walk_regs()
690 do_reg(pfc, pfc->info->ioctrl_regs[i].reg, n++); in sh_pfc_walk_regs()
695 static int sh_pfc_suspend_init(struct sh_pfc *pfc) in sh_pfc_suspend_init() argument
703 n = sh_pfc_walk_regs(pfc, sh_pfc_nop_reg); in sh_pfc_suspend_init()
707 pfc->saved_regs = devm_kmalloc_array(pfc->dev, n, in sh_pfc_suspend_init()
708 sizeof(*pfc->saved_regs), in sh_pfc_suspend_init()
710 if (!pfc->saved_regs) in sh_pfc_suspend_init()
713 dev_dbg(pfc->dev, "Allocated space to save %u regs\n", n); in sh_pfc_suspend_init()
719 struct sh_pfc *pfc = dev_get_drvdata(dev); in sh_pfc_suspend_noirq() local
721 if (pfc->saved_regs) in sh_pfc_suspend_noirq()
722 sh_pfc_walk_regs(pfc, sh_pfc_save_reg); in sh_pfc_suspend_noirq()
728 struct sh_pfc *pfc = dev_get_drvdata(dev); in sh_pfc_resume_noirq() local
730 if (pfc->saved_regs) in sh_pfc_resume_noirq()
731 sh_pfc_walk_regs(pfc, sh_pfc_restore_reg); in sh_pfc_resume_noirq()
736 static int sh_pfc_suspend_init(struct sh_pfc *pfc) { return 0; } in sh_pfc_suspend_init() argument
1305 struct sh_pfc *pfc; in sh_pfc_probe() local
1313 pfc = devm_kzalloc(&pdev->dev, sizeof(*pfc), GFP_KERNEL); in sh_pfc_probe()
1314 if (pfc == NULL) in sh_pfc_probe()
1317 pfc->info = info; in sh_pfc_probe()
1318 pfc->dev = &pdev->dev; in sh_pfc_probe()
1320 ret = sh_pfc_map_resources(pfc, pdev); in sh_pfc_probe()
1324 spin_lock_init(&pfc->lock); in sh_pfc_probe()
1327 ret = info->ops->init(pfc); in sh_pfc_probe()
1332 info = pfc->info; in sh_pfc_probe()
1335 ret = sh_pfc_suspend_init(pfc); in sh_pfc_probe()
1343 ret = sh_pfc_init_ranges(pfc); in sh_pfc_probe()
1350 ret = sh_pfc_register_pinctrl(pfc); in sh_pfc_probe()
1358 ret = sh_pfc_register_gpiochip(pfc); in sh_pfc_probe()
1365 dev_notice(pfc->dev, "failed to init GPIO chip, ignoring...\n"); in sh_pfc_probe()
1369 platform_set_drvdata(pdev, pfc); in sh_pfc_probe()
1371 dev_info(pfc->dev, "%s support registered\n", info->name); in sh_pfc_probe()