Home | History | Annotate | Download | only in renesas

Lines Matching defs:pfc

12 #define DRV_NAME "sh-pfc"
41 struct sh_pfc *pfc;
56 struct sh_pfc pfc;
60 int sh_pfc_get_pin_index(struct sh_pfc *pfc, unsigned int pin)
65 for (i = 0, offset = 0; i < pfc->nr_ranges; ++i) {
66 const struct sh_pfc_pin_range *range = &pfc->ranges[i];
122 u32 sh_pfc_read(struct sh_pfc *pfc, u32 reg)
127 void sh_pfc_write(struct sh_pfc *pfc, u32 reg, u32 data)
130 (void __iomem *)(uintptr_t)pfc->info->unlock_reg;
132 if (pfc->info->unlock_reg)
138 static void sh_pfc_config_reg_helper(struct sh_pfc *pfc,
159 static void sh_pfc_write_config_reg(struct sh_pfc *pfc,
165 (void __iomem *)(uintptr_t)pfc->info->unlock_reg;
169 sh_pfc_config_reg_helper(pfc, crp, field, &mapped_reg, &mask, &pos);
171 dev_dbg(pfc->dev, "write_reg addr = %x, value = 0x%x, field = %u, "
182 if (pfc->info->unlock_reg)
188 static int sh_pfc_get_config_reg(struct sh_pfc *pfc, u16 enum_id,
196 pfc->info->cfg_regs + k;
234 static int sh_pfc_mark_to_enum(struct sh_pfc *pfc, u16 mark, int pos,
237 const u16 *data = pfc->info->pinmux_data;
245 for (k = 0; k < pfc->info->pinmux_data_size; k++) {
252 dev_err(pfc->dev, "cannot locate data/mark enum_id for mark %d\n",
257 int sh_pfc_config_mux(struct sh_pfc *pfc, unsigned mark, int pinmux_type)
269 range = &pfc->info->output;
273 range = &pfc->info->input;
289 pos = sh_pfc_mark_to_enum(pfc, mark, pos, &enum_id);
300 in_range = sh_pfc_enum_in_range(enum_id, &pfc->info->function);
327 ret = sh_pfc_get_config_reg(pfc, enum_id, &cr, &field, &value);
331 sh_pfc_write_config_reg(pfc, cr, field, value);
338 sh_pfc_pin_to_bias_reg(const struct sh_pfc *pfc, unsigned int pin,
343 for (i = 0; pfc->info->bias_regs[i].puen; i++) {
344 for (j = 0; j < ARRAY_SIZE(pfc->info->bias_regs[i].pins); j++) {
345 if (pfc->info->bias_regs[i].pins[j] == pin) {
347 return &pfc->info->bias_regs[i];
357 static int sh_pfc_init_ranges(struct sh_pfc *pfc)
363 if (pfc->info->pins[0].pin == (u16)-1) {
368 pfc->nr_ranges = 1;
369 pfc->ranges = kzalloc(sizeof(*pfc->ranges), GFP_KERNEL);
370 if (pfc->ranges == NULL)
373 pfc->ranges->start = 0;
374 pfc->ranges->end = pfc->info->nr_pins - 1;
375 pfc->nr_gpio_pins = pfc->info->nr_pins;
380 /* Count, allocate and fill the ranges. The PFC SoC data pins array must
384 for (i = 1, nr_ranges = 1; i < pfc->info->nr_pins; ++i) {
385 if (pfc->info->pins[i-1].pin != pfc->info->pins[i].pin - 1)
389 pfc->nr_ranges = nr_ranges;
390 pfc->ranges = kzalloc(sizeof(*pfc->ranges) * nr_ranges, GFP_KERNEL);
391 if (pfc->ranges == NULL)
394 range = pfc->ranges;
395 range->start = pfc->info->pins[0].pin;
397 for (i = 1; i < pfc->info->nr_pins; ++i) {
398 if (pfc->info->pins[i-1].pin == pfc->info->pins[i].pin - 1)
401 range->end = pfc->info->pins[i-1].pin;
402 if (!(pfc->info->pins[i-1].configs & SH_PFC_PIN_CFG_NO_GPIO))
403 pfc->nr_gpio_pins = range->end + 1;
406 range->start = pfc->info->pins[i].pin;
409 range->end = pfc->info->pins[i-1].pin;
410 if (!(pfc->info->pins[i-1].configs & SH_PFC_PIN_CFG_NO_GPIO))
411 pfc->nr_gpio_pins = range->end + 1;
420 return priv->pfc.info->nr_pins;
428 return priv->pfc.info->pins[selector].name;
435 return priv->pfc.info->nr_groups;
443 return priv->pfc.info->groups[selector].name;
450 return priv->pfc.info->nr_functions;
458 return priv->pfc.info->functions[selector].name;
465 struct sh_pfc *pfc = &priv->pfc;
470 for (i = 1; i < pfc->info->nr_pins; i++) {
471 if (priv->pfc.info->pins[i].pin != pin_selector)
474 pin = &priv->pfc.info->pins[i];
481 idx = sh_pfc_get_pin_index(pfc, pin->pin);
487 return sh_pfc_config_mux(pfc, pin->enum_id, PINMUX_TYPE_GPIO);
495 struct sh_pfc *pfc = &priv->pfc;
496 const struct sh_pfc_pin *pin = &priv->pfc.info->pins[pin_selector];
497 int idx = sh_pfc_get_pin_index(pfc, pin->pin);
503 return sh_pfc_config_mux(pfc, pin->enum_id, PINMUX_TYPE_FUNCTION);
511 struct sh_pfc *pfc = &priv->pfc;
512 const struct sh_pfc_pin_group *grp = &priv->pfc.info->groups[group_selector];
517 int idx = sh_pfc_get_pin_index(pfc, grp->pins[i]);
527 ret = sh_pfc_config_mux(pfc, grp->mux[i], PINMUX_TYPE_FUNCTION);
545 sh_pfc_pinconf_find_drive_strength_reg(struct sh_pfc *pfc, unsigned int pin,
552 for (reg = pfc->info->drive_regs; reg->reg; ++reg) {
568 static int sh_pfc_pinconf_set_drive_strength(struct sh_pfc *pfc,
576 (void __iomem *)(uintptr_t)pfc->info->unlock_reg;
579 reg = sh_pfc_pinconf_find_drive_strength_reg(pfc, pin, &offset, &size);
606 static bool sh_pfc_pinconf_validate(struct sh_pfc *pfc, unsigned int _pin,
609 int idx = sh_pfc_get_pin_index(pfc, _pin);
610 const struct sh_pfc_pin *pin = &pfc->info->pins[idx];
637 struct sh_pfc *pfc = pmx->pfc;
640 (void __iomem *)(uintptr_t)pfc->info->unlock_reg;
644 if (!sh_pfc_pinconf_validate(pfc, _pin, param))
651 if (!pfc->info->ops || !pfc->info->ops->set_bias)
654 pfc->info->ops->set_bias(pfc, _pin, param);
659 ret = sh_pfc_pinconf_set_drive_strength(pfc, _pin, arg);
666 if (!pfc->info->ops || !pfc->info->ops->pin_to_pocctrl)
669 bit = pfc->info->ops->pin_to_pocctrl(pfc, _pin, &addr);
706 struct sh_pfc *pfc = &priv->pfc;
707 const struct sh_pfc_pin *pin = &pfc->info->pins[pin_selector];
720 struct sh_pfc *pfc = &priv->pfc;
721 const struct sh_pfc_pin_group *grp = &pfc->info->groups[group_selector];
750 static int sh_pfc_map_pins(struct sh_pfc *pfc, struct sh_pfc_pinctrl *pmx)
755 pmx->configs = kzalloc(sizeof(*pmx->configs) * pfc->info->nr_pins,
760 for (i = 0; i < pfc->info->nr_pins; ++i) {
779 priv->pfc.regs = devm_ioremap(dev, base, SZ_2K);
780 if (!priv->pfc.regs)
785 priv->pfc.info = &r8a7790_pinmux_info;
789 priv->pfc.info = &r8a7791_pinmux_info;
793 priv->pfc.info = &r8a7792_pinmux_info;
797 priv->pfc.info = &r8a7793_pinmux_info;
801 priv->pfc.info = &r8a7794_pinmux_info;
805 priv->pfc.info = &r8a7795_pinmux_info;
809 priv->pfc.info = &r8a7796_pinmux_info;
813 priv->pfc.info = &r8a77970_pinmux_info;
817 priv->pfc.info = &r8a77990_pinmux_info;
821 priv->pfc.info = &r8a77995_pinmux_info;
824 priv->pmx.pfc = &priv->pfc;
825 sh_pfc_init_ranges(&priv->pfc);
826 sh_pfc_map_pins(&priv->pfc, &priv->pmx);
834 .compatible = "renesas,pfc-r8a7790",
840 .compatible = "renesas,pfc-r8a7791",
846 .compatible = "renesas,pfc-r8a7792",
852 .compatible = "renesas,pfc-r8a7793",
858 .compatible = "renesas,pfc-r8a7794",
864 .compatible = "renesas,pfc-r8a7795",
870 .compatible = "renesas,pfc-r8a7796",
873 .compatible = "renesas,pfc-r8a77965",
879 .compatible = "renesas,pfc-r8a77970",
885 .compatible = "renesas,pfc-r8a77990",
891 .compatible = "renesas,pfc-r8a77995",