Lines Matching +full:request +full:- +full:gpios
1 // SPDX-License-Identifier: GPL-2.0
6 * Copyright (C) 2009 - 2012 Paul Mundt
40 return chip->pfc; in gpio_to_pfc()
47 int idx = sh_pfc_get_pin_index(chip->pfc, offset); in gpio_get_data_reg()
48 struct sh_pfc_gpio_pin *gpio_pin = &chip->pins[idx]; in gpio_get_data_reg()
50 *reg = &chip->regs[gpio_pin->dreg]; in gpio_get_data_reg()
51 *bit = gpio_pin->dbit; in gpio_get_data_reg()
57 phys_addr_t address = dreg->reg; in gpio_read_data_reg()
58 void __iomem *mem = address - chip->mem->phys + chip->mem->virt; in gpio_read_data_reg()
60 return sh_pfc_read_raw_reg(mem, dreg->reg_width); in gpio_read_data_reg()
66 phys_addr_t address = dreg->reg; in gpio_write_data_reg()
67 void __iomem *mem = address - chip->mem->phys + chip->mem->virt; in gpio_write_data_reg()
69 sh_pfc_write_raw_reg(mem, dreg->reg_width, value); in gpio_write_data_reg()
74 struct sh_pfc *pfc = chip->pfc; in gpio_setup_data_reg()
75 struct sh_pfc_gpio_pin *gpio_pin = &chip->pins[idx]; in gpio_setup_data_reg()
76 const struct sh_pfc_pin *pin = &pfc->info->pins[idx]; in gpio_setup_data_reg()
81 for (i = 0, dreg = pfc->info->data_regs; dreg->reg_width; ++i, ++dreg) { in gpio_setup_data_reg()
82 for (bit = 0; bit < dreg->reg_width; bit++) { in gpio_setup_data_reg()
83 if (dreg->enum_ids[bit] == pin->enum_id) { in gpio_setup_data_reg()
84 gpio_pin->dreg = i; in gpio_setup_data_reg()
85 gpio_pin->dbit = bit; in gpio_setup_data_reg()
96 struct sh_pfc *pfc = chip->pfc; in gpio_setup_data_regs()
103 for (i = 0; pfc->info->data_regs[i].reg_width; ++i) in gpio_setup_data_regs()
106 chip->regs = devm_kcalloc(pfc->dev, i, sizeof(*chip->regs), in gpio_setup_data_regs()
108 if (chip->regs == NULL) in gpio_setup_data_regs()
109 return -ENOMEM; in gpio_setup_data_regs()
111 for (i = 0, dreg = pfc->info->data_regs; dreg->reg_width; ++i, ++dreg) { in gpio_setup_data_regs()
112 chip->regs[i].info = dreg; in gpio_setup_data_regs()
113 chip->regs[i].shadow = gpio_read_data_reg(chip, dreg); in gpio_setup_data_regs()
116 for (i = 0; i < pfc->info->nr_pins; i++) { in gpio_setup_data_regs()
117 if (pfc->info->pins[i].enum_id == 0) in gpio_setup_data_regs()
126 /* -----------------------------------------------------------------------------
127 * Pin GPIOs
135 if (idx < 0 || pfc->info->pins[idx].enum_id == 0) in gpio_pin_request()
136 return -EINVAL; in gpio_pin_request()
155 pos = reg->info->reg_width - (bit + 1); in gpio_pin_set_value()
158 reg->shadow |= BIT(pos); in gpio_pin_set_value()
160 reg->shadow &= ~BIT(pos); in gpio_pin_set_value()
162 gpio_write_data_reg(chip, reg->info, reg->shadow); in gpio_pin_set_value()
187 pos = reg->info->reg_width - (bit + 1); in gpio_pin_get()
189 return (gpio_read_data_reg(chip, reg->info) >> pos) & 1; in gpio_pin_get()
202 for (i = 0; i < pfc->info->gpio_irq_size; i++) { in gpio_pin_to_irq()
203 const short *gpios = pfc->info->gpio_irq[i].gpios; in gpio_pin_to_irq() local
205 for (k = 0; gpios[k] >= 0; k++) { in gpio_pin_to_irq()
206 if (gpios[k] == offset) in gpio_pin_to_irq()
207 return pfc->irqs[i]; in gpio_pin_to_irq()
216 struct sh_pfc *pfc = chip->pfc; in gpio_pin_setup()
217 struct gpio_chip *gc = &chip->gpio_chip; in gpio_pin_setup()
220 chip->pins = devm_kcalloc(pfc->dev, in gpio_pin_setup()
221 pfc->info->nr_pins, sizeof(*chip->pins), in gpio_pin_setup()
223 if (chip->pins == NULL) in gpio_pin_setup()
224 return -ENOMEM; in gpio_pin_setup()
230 gc->request = gpio_pin_request; in gpio_pin_setup()
231 gc->free = gpio_pin_free; in gpio_pin_setup()
232 gc->direction_input = gpio_pin_direction_input; in gpio_pin_setup()
233 gc->get = gpio_pin_get; in gpio_pin_setup()
234 gc->direction_output = gpio_pin_direction_output; in gpio_pin_setup()
235 gc->set = gpio_pin_set; in gpio_pin_setup()
236 gc->to_irq = gpio_pin_to_irq; in gpio_pin_setup()
238 gc->label = pfc->info->name; in gpio_pin_setup()
239 gc->parent = pfc->dev; in gpio_pin_setup()
240 gc->owner = THIS_MODULE; in gpio_pin_setup()
241 gc->base = IS_ENABLED(CONFIG_PINCTRL_SH_FUNC_GPIO) ? 0 : -1; in gpio_pin_setup()
242 gc->ngpio = pfc->nr_gpio_pins; in gpio_pin_setup()
247 /* -----------------------------------------------------------------------------
248 * Function GPIOs
255 unsigned int mark = pfc->info->func_gpios[offset].enum_id; in gpio_function_request()
259 dev_notice_once(pfc->dev, in gpio_function_request()
263 return -EINVAL; in gpio_function_request()
265 spin_lock_irqsave(&pfc->lock, flags); in gpio_function_request()
267 spin_unlock_irqrestore(&pfc->lock, flags); in gpio_function_request()
274 struct sh_pfc *pfc = chip->pfc; in gpio_function_setup()
275 struct gpio_chip *gc = &chip->gpio_chip; in gpio_function_setup()
277 gc->request = gpio_function_request; in gpio_function_setup()
279 gc->label = pfc->info->name; in gpio_function_setup()
280 gc->owner = THIS_MODULE; in gpio_function_setup()
281 gc->base = pfc->nr_gpio_pins; in gpio_function_setup()
282 gc->ngpio = pfc->info->nr_func_gpios; in gpio_function_setup()
288 /* -----------------------------------------------------------------------------
299 chip = devm_kzalloc(pfc->dev, sizeof(*chip), GFP_KERNEL); in sh_pfc_add_gpiochip()
301 return ERR_PTR(-ENOMEM); in sh_pfc_add_gpiochip()
303 chip->mem = mem; in sh_pfc_add_gpiochip()
304 chip->pfc = pfc; in sh_pfc_add_gpiochip()
310 ret = devm_gpiochip_add_data(pfc->dev, &chip->gpio_chip, chip); in sh_pfc_add_gpiochip()
314 dev_info(pfc->dev, "%s handling gpio %u -> %u\n", in sh_pfc_add_gpiochip()
315 chip->gpio_chip.label, chip->gpio_chip.base, in sh_pfc_add_gpiochip()
316 chip->gpio_chip.base + chip->gpio_chip.ngpio - 1); in sh_pfc_add_gpiochip()
327 if (pfc->info->data_regs == NULL) in sh_pfc_register_gpiochip()
333 * GPIOs. in sh_pfc_register_gpiochip()
335 address = pfc->info->data_regs[0].reg; in sh_pfc_register_gpiochip()
336 for (i = 0; i < pfc->num_windows; ++i) { in sh_pfc_register_gpiochip()
337 struct sh_pfc_window *window = &pfc->windows[i]; in sh_pfc_register_gpiochip()
339 if (address >= window->phys && in sh_pfc_register_gpiochip()
340 address < window->phys + window->size) in sh_pfc_register_gpiochip()
344 if (i == pfc->num_windows) in sh_pfc_register_gpiochip()
348 if (pfc->num_irqs != pfc->info->gpio_irq_size) { in sh_pfc_register_gpiochip()
349 dev_err(pfc->dev, "invalid number of IRQ resources\n"); in sh_pfc_register_gpiochip()
350 return -EINVAL; in sh_pfc_register_gpiochip()
353 /* Register the real GPIOs chip. */ in sh_pfc_register_gpiochip()
354 chip = sh_pfc_add_gpiochip(pfc, gpio_pin_setup, &pfc->windows[i]); in sh_pfc_register_gpiochip()
358 pfc->gpio = chip; in sh_pfc_register_gpiochip()
360 if (IS_ENABLED(CONFIG_OF) && pfc->dev->of_node) in sh_pfc_register_gpiochip()
370 for (i = 0; i < pfc->nr_ranges; ++i) { in sh_pfc_register_gpiochip()
371 const struct sh_pfc_pin_range *range = &pfc->ranges[i]; in sh_pfc_register_gpiochip()
374 if (range->start >= pfc->nr_gpio_pins) in sh_pfc_register_gpiochip()
377 ret = gpiochip_add_pin_range(&chip->gpio_chip, in sh_pfc_register_gpiochip()
378 dev_name(pfc->dev), range->start, range->start, in sh_pfc_register_gpiochip()
379 range->end - range->start + 1); in sh_pfc_register_gpiochip()
384 /* Register the function GPIOs chip. */ in sh_pfc_register_gpiochip()
385 if (pfc->info->nr_func_gpios) { in sh_pfc_register_gpiochip()