Lines Matching full:gc

124 static unsigned long bgpio_line2mask(struct gpio_chip *gc, unsigned int line)  in bgpio_line2mask()  argument
126 if (gc->be_bits) in bgpio_line2mask()
127 return BIT(gc->bgpio_bits - 1 - line); in bgpio_line2mask()
131 static int bgpio_get_set(struct gpio_chip *gc, unsigned int gpio) in bgpio_get_set() argument
133 unsigned long pinmask = bgpio_line2mask(gc, gpio); in bgpio_get_set()
134 bool dir = !!(gc->bgpio_dir & pinmask); in bgpio_get_set()
137 return !!(gc->read_reg(gc->reg_set) & pinmask); in bgpio_get_set()
139 return !!(gc->read_reg(gc->reg_dat) & pinmask); in bgpio_get_set()
146 static int bgpio_get_set_multiple(struct gpio_chip *gc, unsigned long *mask, in bgpio_get_set_multiple() argument
155 set_mask = *mask & gc->bgpio_dir; in bgpio_get_set_multiple()
156 get_mask = *mask & ~gc->bgpio_dir; in bgpio_get_set_multiple()
159 *bits |= gc->read_reg(gc->reg_set) & set_mask; in bgpio_get_set_multiple()
161 *bits |= gc->read_reg(gc->reg_dat) & get_mask; in bgpio_get_set_multiple()
166 static int bgpio_get(struct gpio_chip *gc, unsigned int gpio) in bgpio_get() argument
168 return !!(gc->read_reg(gc->reg_dat) & bgpio_line2mask(gc, gpio)); in bgpio_get()
174 static int bgpio_get_multiple(struct gpio_chip *gc, unsigned long *mask, in bgpio_get_multiple() argument
179 *bits |= gc->read_reg(gc->reg_dat) & *mask; in bgpio_get_multiple()
186 static int bgpio_get_multiple_be(struct gpio_chip *gc, unsigned long *mask, in bgpio_get_multiple_be() argument
197 for_each_set_bit(bit, mask, gc->ngpio) in bgpio_get_multiple_be()
198 readmask |= bgpio_line2mask(gc, bit); in bgpio_get_multiple_be()
201 val = gc->read_reg(gc->reg_dat) & readmask; in bgpio_get_multiple_be()
207 for_each_set_bit(bit, &val, gc->ngpio) in bgpio_get_multiple_be()
208 *bits |= bgpio_line2mask(gc, bit); in bgpio_get_multiple_be()
213 static void bgpio_set_none(struct gpio_chip *gc, unsigned int gpio, int val) in bgpio_set_none() argument
217 static void bgpio_set(struct gpio_chip *gc, unsigned int gpio, int val) in bgpio_set() argument
219 unsigned long mask = bgpio_line2mask(gc, gpio); in bgpio_set()
222 raw_spin_lock_irqsave(&gc->bgpio_lock, flags); in bgpio_set()
225 gc->bgpio_data |= mask; in bgpio_set()
227 gc->bgpio_data &= ~mask; in bgpio_set()
229 gc->write_reg(gc->reg_dat, gc->bgpio_data); in bgpio_set()
231 raw_spin_unlock_irqrestore(&gc->bgpio_lock, flags); in bgpio_set()
234 static void bgpio_set_with_clear(struct gpio_chip *gc, unsigned int gpio, in bgpio_set_with_clear() argument
237 unsigned long mask = bgpio_line2mask(gc, gpio); in bgpio_set_with_clear()
240 gc->write_reg(gc->reg_set, mask); in bgpio_set_with_clear()
242 gc->write_reg(gc->reg_clr, mask); in bgpio_set_with_clear()
245 static void bgpio_set_set(struct gpio_chip *gc, unsigned int gpio, int val) in bgpio_set_set() argument
247 unsigned long mask = bgpio_line2mask(gc, gpio); in bgpio_set_set()
250 raw_spin_lock_irqsave(&gc->bgpio_lock, flags); in bgpio_set_set()
253 gc->bgpio_data |= mask; in bgpio_set_set()
255 gc->bgpio_data &= ~mask; in bgpio_set_set()
257 gc->write_reg(gc->reg_set, gc->bgpio_data); in bgpio_set_set()
259 raw_spin_unlock_irqrestore(&gc->bgpio_lock, flags); in bgpio_set_set()
262 static void bgpio_multiple_get_masks(struct gpio_chip *gc, in bgpio_multiple_get_masks() argument
272 for_each_set_bit(i, mask, gc->bgpio_bits) { in bgpio_multiple_get_masks()
274 *set_mask |= bgpio_line2mask(gc, i); in bgpio_multiple_get_masks()
276 *clear_mask |= bgpio_line2mask(gc, i); in bgpio_multiple_get_masks()
280 static void bgpio_set_multiple_single_reg(struct gpio_chip *gc, in bgpio_set_multiple_single_reg() argument
288 raw_spin_lock_irqsave(&gc->bgpio_lock, flags); in bgpio_set_multiple_single_reg()
290 bgpio_multiple_get_masks(gc, mask, bits, &set_mask, &clear_mask); in bgpio_set_multiple_single_reg()
292 gc->bgpio_data |= set_mask; in bgpio_set_multiple_single_reg()
293 gc->bgpio_data &= ~clear_mask; in bgpio_set_multiple_single_reg()
295 gc->write_reg(reg, gc->bgpio_data); in bgpio_set_multiple_single_reg()
297 raw_spin_unlock_irqrestore(&gc->bgpio_lock, flags); in bgpio_set_multiple_single_reg()
300 static void bgpio_set_multiple(struct gpio_chip *gc, unsigned long *mask, in bgpio_set_multiple() argument
303 bgpio_set_multiple_single_reg(gc, mask, bits, gc->reg_dat); in bgpio_set_multiple()
306 static void bgpio_set_multiple_set(struct gpio_chip *gc, unsigned long *mask, in bgpio_set_multiple_set() argument
309 bgpio_set_multiple_single_reg(gc, mask, bits, gc->reg_set); in bgpio_set_multiple_set()
312 static void bgpio_set_multiple_with_clear(struct gpio_chip *gc, in bgpio_set_multiple_with_clear() argument
318 bgpio_multiple_get_masks(gc, mask, bits, &set_mask, &clear_mask); in bgpio_set_multiple_with_clear()
321 gc->write_reg(gc->reg_set, set_mask); in bgpio_set_multiple_with_clear()
323 gc->write_reg(gc->reg_clr, clear_mask); in bgpio_set_multiple_with_clear()
326 static int bgpio_simple_dir_in(struct gpio_chip *gc, unsigned int gpio) in bgpio_simple_dir_in() argument
331 static int bgpio_dir_out_err(struct gpio_chip *gc, unsigned int gpio, in bgpio_dir_out_err() argument
337 static int bgpio_simple_dir_out(struct gpio_chip *gc, unsigned int gpio, in bgpio_simple_dir_out() argument
340 gc->set(gc, gpio, val); in bgpio_simple_dir_out()
345 static int bgpio_dir_in(struct gpio_chip *gc, unsigned int gpio) in bgpio_dir_in() argument
349 raw_spin_lock_irqsave(&gc->bgpio_lock, flags); in bgpio_dir_in()
351 gc->bgpio_dir &= ~bgpio_line2mask(gc, gpio); in bgpio_dir_in()
353 if (gc->reg_dir_in) in bgpio_dir_in()
354 gc->write_reg(gc->reg_dir_in, ~gc->bgpio_dir); in bgpio_dir_in()
355 if (gc->reg_dir_out) in bgpio_dir_in()
356 gc->write_reg(gc->reg_dir_out, gc->bgpio_dir); in bgpio_dir_in()
358 raw_spin_unlock_irqrestore(&gc->bgpio_lock, flags); in bgpio_dir_in()
363 static int bgpio_get_dir(struct gpio_chip *gc, unsigned int gpio) in bgpio_get_dir() argument
366 if (gc->bgpio_dir_unreadable) { in bgpio_get_dir()
367 if (gc->bgpio_dir & bgpio_line2mask(gc, gpio)) in bgpio_get_dir()
372 if (gc->reg_dir_out) { in bgpio_get_dir()
373 if (gc->read_reg(gc->reg_dir_out) & bgpio_line2mask(gc, gpio)) in bgpio_get_dir()
378 if (gc->reg_dir_in) in bgpio_get_dir()
379 if (!(gc->read_reg(gc->reg_dir_in) & bgpio_line2mask(gc, gpio))) in bgpio_get_dir()
385 static void bgpio_dir_out(struct gpio_chip *gc, unsigned int gpio, int val) in bgpio_dir_out() argument
389 raw_spin_lock_irqsave(&gc->bgpio_lock, flags); in bgpio_dir_out()
391 gc->bgpio_dir |= bgpio_line2mask(gc, gpio); in bgpio_dir_out()
393 if (gc->reg_dir_in) in bgpio_dir_out()
394 gc->write_reg(gc->reg_dir_in, ~gc->bgpio_dir); in bgpio_dir_out()
395 if (gc->reg_dir_out) in bgpio_dir_out()
396 gc->write_reg(gc->reg_dir_out, gc->bgpio_dir); in bgpio_dir_out()
398 raw_spin_unlock_irqrestore(&gc->bgpio_lock, flags); in bgpio_dir_out()
401 static int bgpio_dir_out_dir_first(struct gpio_chip *gc, unsigned int gpio, in bgpio_dir_out_dir_first() argument
404 bgpio_dir_out(gc, gpio, val); in bgpio_dir_out_dir_first()
405 gc->set(gc, gpio, val); in bgpio_dir_out_dir_first()
409 static int bgpio_dir_out_val_first(struct gpio_chip *gc, unsigned int gpio, in bgpio_dir_out_val_first() argument
412 gc->set(gc, gpio, val); in bgpio_dir_out_val_first()
413 bgpio_dir_out(gc, gpio, val); in bgpio_dir_out_val_first()
418 struct gpio_chip *gc, in bgpio_setup_accessors() argument
422 switch (gc->bgpio_bits) { in bgpio_setup_accessors()
424 gc->read_reg = bgpio_read8; in bgpio_setup_accessors()
425 gc->write_reg = bgpio_write8; in bgpio_setup_accessors()
429 gc->read_reg = bgpio_read16be; in bgpio_setup_accessors()
430 gc->write_reg = bgpio_write16be; in bgpio_setup_accessors()
432 gc->read_reg = bgpio_read16; in bgpio_setup_accessors()
433 gc->write_reg = bgpio_write16; in bgpio_setup_accessors()
438 gc->read_reg = bgpio_read32be; in bgpio_setup_accessors()
439 gc->write_reg = bgpio_write32be; in bgpio_setup_accessors()
441 gc->read_reg = bgpio_read32; in bgpio_setup_accessors()
442 gc->write_reg = bgpio_write32; in bgpio_setup_accessors()
452 gc->read_reg = bgpio_read64; in bgpio_setup_accessors()
453 gc->write_reg = bgpio_write64; in bgpio_setup_accessors()
458 dev_err(dev, "unsupported data width %u bits\n", gc->bgpio_bits); in bgpio_setup_accessors()
487 static int bgpio_setup_io(struct gpio_chip *gc, in bgpio_setup_io() argument
494 gc->reg_dat = dat; in bgpio_setup_io()
495 if (!gc->reg_dat) in bgpio_setup_io()
499 gc->reg_set = set; in bgpio_setup_io()
500 gc->reg_clr = clr; in bgpio_setup_io()
501 gc->set = bgpio_set_with_clear; in bgpio_setup_io()
502 gc->set_multiple = bgpio_set_multiple_with_clear; in bgpio_setup_io()
504 gc->reg_set = set; in bgpio_setup_io()
505 gc->set = bgpio_set_set; in bgpio_setup_io()
506 gc->set_multiple = bgpio_set_multiple_set; in bgpio_setup_io()
508 gc->set = bgpio_set_none; in bgpio_setup_io()
509 gc->set_multiple = NULL; in bgpio_setup_io()
511 gc->set = bgpio_set; in bgpio_setup_io()
512 gc->set_multiple = bgpio_set_multiple; in bgpio_setup_io()
517 gc->get = bgpio_get_set; in bgpio_setup_io()
518 if (!gc->be_bits) in bgpio_setup_io()
519 gc->get_multiple = bgpio_get_set_multiple; in bgpio_setup_io()
528 gc->get = bgpio_get; in bgpio_setup_io()
529 if (gc->be_bits) in bgpio_setup_io()
530 gc->get_multiple = bgpio_get_multiple_be; in bgpio_setup_io()
532 gc->get_multiple = bgpio_get_multiple; in bgpio_setup_io()
538 static int bgpio_setup_direction(struct gpio_chip *gc, in bgpio_setup_direction() argument
544 gc->reg_dir_out = dirout; in bgpio_setup_direction()
545 gc->reg_dir_in = dirin; in bgpio_setup_direction()
547 gc->direction_output = bgpio_dir_out_dir_first; in bgpio_setup_direction()
549 gc->direction_output = bgpio_dir_out_val_first; in bgpio_setup_direction()
550 gc->direction_input = bgpio_dir_in; in bgpio_setup_direction()
551 gc->get_direction = bgpio_get_dir; in bgpio_setup_direction()
554 gc->direction_output = bgpio_dir_out_err; in bgpio_setup_direction()
556 gc->direction_output = bgpio_simple_dir_out; in bgpio_setup_direction()
557 gc->direction_input = bgpio_simple_dir_in; in bgpio_setup_direction()
573 * @gc: the GPIO chip to set up
598 int bgpio_init(struct gpio_chip *gc, struct device *dev, in bgpio_init() argument
608 gc->bgpio_bits = sz * 8; in bgpio_init()
609 if (gc->bgpio_bits > BITS_PER_LONG) in bgpio_init()
612 raw_spin_lock_init(&gc->bgpio_lock); in bgpio_init()
613 gc->parent = dev; in bgpio_init()
614 gc->label = dev_name(dev); in bgpio_init()
615 gc->base = -1; in bgpio_init()
616 gc->request = bgpio_request; in bgpio_init()
617 gc->be_bits = !!(flags & BGPIOF_BIG_ENDIAN); in bgpio_init()
619 ret = gpiochip_get_ngpios(gc, dev); in bgpio_init()
621 gc->ngpio = gc->bgpio_bits; in bgpio_init()
623 ret = bgpio_setup_io(gc, dat, set, clr, flags); in bgpio_init()
627 ret = bgpio_setup_accessors(dev, gc, flags & BGPIOF_BIG_ENDIAN_BYTE_ORDER); in bgpio_init()
631 ret = bgpio_setup_direction(gc, dirout, dirin, flags); in bgpio_init()
635 gc->bgpio_data = gc->read_reg(gc->reg_dat); in bgpio_init()
636 if (gc->set == bgpio_set_set && in bgpio_init()
638 gc->bgpio_data = gc->read_reg(gc->reg_set); in bgpio_init()
641 gc->bgpio_dir_unreadable = true; in bgpio_init()
646 if ((gc->reg_dir_out || gc->reg_dir_in) && in bgpio_init()
648 if (gc->reg_dir_out) in bgpio_init()
649 gc->bgpio_dir = gc->read_reg(gc->reg_dir_out); in bgpio_init()
650 else if (gc->reg_dir_in) in bgpio_init()
651 gc->bgpio_dir = ~gc->read_reg(gc->reg_dir_in); in bgpio_init()
658 if (gc->reg_dir_out && gc->reg_dir_in) in bgpio_init()
659 gc->write_reg(gc->reg_dir_in, ~gc->bgpio_dir); in bgpio_init()
728 struct gpio_chip *gc; in bgpio_pdev_probe() local
766 gc = devm_kzalloc(&pdev->dev, sizeof(*gc), GFP_KERNEL); in bgpio_pdev_probe()
767 if (!gc) in bgpio_pdev_probe()
770 err = bgpio_init(gc, dev, sz, dat, set, clr, dirout, dirin, flags); in bgpio_pdev_probe()
776 gc->label = pdata->label; in bgpio_pdev_probe()
777 gc->base = pdata->base; in bgpio_pdev_probe()
779 gc->ngpio = pdata->ngpio; in bgpio_pdev_probe()
782 platform_set_drvdata(pdev, gc); in bgpio_pdev_probe()
784 return devm_gpiochip_add_data(&pdev->dev, gc, NULL); in bgpio_pdev_probe()