Lines Matching refs:gpt
137 struct mpc52xx_gpt_priv *gpt = irq_data_get_irq_chip_data(d); in mpc52xx_gpt_irq_unmask() local
140 raw_spin_lock_irqsave(&gpt->lock, flags); in mpc52xx_gpt_irq_unmask()
141 setbits32(&gpt->regs->mode, MPC52xx_GPT_MODE_IRQ_EN); in mpc52xx_gpt_irq_unmask()
142 raw_spin_unlock_irqrestore(&gpt->lock, flags); in mpc52xx_gpt_irq_unmask()
147 struct mpc52xx_gpt_priv *gpt = irq_data_get_irq_chip_data(d); in mpc52xx_gpt_irq_mask() local
150 raw_spin_lock_irqsave(&gpt->lock, flags); in mpc52xx_gpt_irq_mask()
151 clrbits32(&gpt->regs->mode, MPC52xx_GPT_MODE_IRQ_EN); in mpc52xx_gpt_irq_mask()
152 raw_spin_unlock_irqrestore(&gpt->lock, flags); in mpc52xx_gpt_irq_mask()
157 struct mpc52xx_gpt_priv *gpt = irq_data_get_irq_chip_data(d); in mpc52xx_gpt_irq_ack() local
159 out_be32(&gpt->regs->status, MPC52xx_GPT_STATUS_IRQMASK); in mpc52xx_gpt_irq_ack()
164 struct mpc52xx_gpt_priv *gpt = irq_data_get_irq_chip_data(d); in mpc52xx_gpt_irq_set_type() local
168 dev_dbg(gpt->dev, "%s: virq=%i type=%x\n", __func__, d->irq, flow_type); in mpc52xx_gpt_irq_set_type()
170 raw_spin_lock_irqsave(&gpt->lock, flags); in mpc52xx_gpt_irq_set_type()
171 reg = in_be32(&gpt->regs->mode) & ~MPC52xx_GPT_MODE_ICT_MASK; in mpc52xx_gpt_irq_set_type()
176 out_be32(&gpt->regs->mode, reg); in mpc52xx_gpt_irq_set_type()
177 raw_spin_unlock_irqrestore(&gpt->lock, flags); in mpc52xx_gpt_irq_set_type()
192 struct mpc52xx_gpt_priv *gpt = irq_desc_get_handler_data(desc); in mpc52xx_gpt_irq_cascade() local
196 status = in_be32(&gpt->regs->status) & MPC52xx_GPT_STATUS_IRQMASK; in mpc52xx_gpt_irq_cascade()
198 sub_virq = irq_linear_revmap(gpt->irqhost, 0); in mpc52xx_gpt_irq_cascade()
206 struct mpc52xx_gpt_priv *gpt = h->host_data; in mpc52xx_gpt_irq_map() local
208 dev_dbg(gpt->dev, "%s: h=%p, virq=%i\n", __func__, h, virq); in mpc52xx_gpt_irq_map()
209 irq_set_chip_data(virq, gpt); in mpc52xx_gpt_irq_map()
220 struct mpc52xx_gpt_priv *gpt = h->host_data; in mpc52xx_gpt_irq_xlate() local
222 dev_dbg(gpt->dev, "%s: flags=%i\n", __func__, intspec[0]); in mpc52xx_gpt_irq_xlate()
225 dev_err(gpt->dev, "bad irq specifier in %pOF\n", ct); in mpc52xx_gpt_irq_xlate()
241 mpc52xx_gpt_irq_setup(struct mpc52xx_gpt_priv *gpt, struct device_node *node) in mpc52xx_gpt_irq_setup() argument
251 gpt->irqhost = irq_domain_add_linear(node, 1, &mpc52xx_gpt_irq_ops, gpt); in mpc52xx_gpt_irq_setup()
252 if (!gpt->irqhost) { in mpc52xx_gpt_irq_setup()
253 dev_err(gpt->dev, "irq_domain_add_linear() failed\n"); in mpc52xx_gpt_irq_setup()
257 irq_set_handler_data(cascade_virq, gpt); in mpc52xx_gpt_irq_setup()
263 raw_spin_lock_irqsave(&gpt->lock, flags); in mpc52xx_gpt_irq_setup()
264 mode = in_be32(&gpt->regs->mode); in mpc52xx_gpt_irq_setup()
266 out_be32(&gpt->regs->mode, mode | MPC52xx_GPT_MODE_MS_IC); in mpc52xx_gpt_irq_setup()
267 raw_spin_unlock_irqrestore(&gpt->lock, flags); in mpc52xx_gpt_irq_setup()
269 dev_dbg(gpt->dev, "%s() complete. virq=%i\n", __func__, cascade_virq); in mpc52xx_gpt_irq_setup()
279 struct mpc52xx_gpt_priv *gpt = gpiochip_get_data(gc); in mpc52xx_gpt_gpio_get() local
281 return (in_be32(&gpt->regs->status) >> 8) & 1; in mpc52xx_gpt_gpio_get()
287 struct mpc52xx_gpt_priv *gpt = gpiochip_get_data(gc); in mpc52xx_gpt_gpio_set() local
291 dev_dbg(gpt->dev, "%s: gpio:%d v:%d\n", __func__, gpio, v); in mpc52xx_gpt_gpio_set()
294 raw_spin_lock_irqsave(&gpt->lock, flags); in mpc52xx_gpt_gpio_set()
295 clrsetbits_be32(&gpt->regs->mode, MPC52xx_GPT_MODE_GPIO_MASK, r); in mpc52xx_gpt_gpio_set()
296 raw_spin_unlock_irqrestore(&gpt->lock, flags); in mpc52xx_gpt_gpio_set()
301 struct mpc52xx_gpt_priv *gpt = gpiochip_get_data(gc); in mpc52xx_gpt_gpio_dir_in() local
304 dev_dbg(gpt->dev, "%s: gpio:%d\n", __func__, gpio); in mpc52xx_gpt_gpio_dir_in()
306 raw_spin_lock_irqsave(&gpt->lock, flags); in mpc52xx_gpt_gpio_dir_in()
307 clrbits32(&gpt->regs->mode, MPC52xx_GPT_MODE_GPIO_MASK); in mpc52xx_gpt_gpio_dir_in()
308 raw_spin_unlock_irqrestore(&gpt->lock, flags); in mpc52xx_gpt_gpio_dir_in()
321 mpc52xx_gpt_gpio_setup(struct mpc52xx_gpt_priv *gpt, struct device_node *node) in mpc52xx_gpt_gpio_setup() argument
330 gpt->gc.label = kasprintf(GFP_KERNEL, "%pOF", node); in mpc52xx_gpt_gpio_setup()
331 if (!gpt->gc.label) { in mpc52xx_gpt_gpio_setup()
332 dev_err(gpt->dev, "out of memory\n"); in mpc52xx_gpt_gpio_setup()
336 gpt->gc.ngpio = 1; in mpc52xx_gpt_gpio_setup()
337 gpt->gc.direction_input = mpc52xx_gpt_gpio_dir_in; in mpc52xx_gpt_gpio_setup()
338 gpt->gc.direction_output = mpc52xx_gpt_gpio_dir_out; in mpc52xx_gpt_gpio_setup()
339 gpt->gc.get = mpc52xx_gpt_gpio_get; in mpc52xx_gpt_gpio_setup()
340 gpt->gc.set = mpc52xx_gpt_gpio_set; in mpc52xx_gpt_gpio_setup()
341 gpt->gc.base = -1; in mpc52xx_gpt_gpio_setup()
342 gpt->gc.of_node = node; in mpc52xx_gpt_gpio_setup()
345 clrsetbits_be32(&gpt->regs->mode, MPC52xx_GPT_MODE_MS_MASK, in mpc52xx_gpt_gpio_setup()
348 rc = gpiochip_add_data(&gpt->gc, gpt); in mpc52xx_gpt_gpio_setup()
350 dev_err(gpt->dev, "gpiochip_add_data() failed; rc=%i\n", rc); in mpc52xx_gpt_gpio_setup()
352 dev_dbg(gpt->dev, "%s() complete.\n", __func__); in mpc52xx_gpt_gpio_setup()
369 struct mpc52xx_gpt_priv *gpt; in mpc52xx_gpt_from_irq() local
375 gpt = container_of(pos, struct mpc52xx_gpt_priv, list); in mpc52xx_gpt_from_irq()
376 if (gpt->irqhost && irq == irq_linear_revmap(gpt->irqhost, 0)) { in mpc52xx_gpt_from_irq()
378 return gpt; in mpc52xx_gpt_from_irq()
387 static int mpc52xx_gpt_do_start(struct mpc52xx_gpt_priv *gpt, u64 period, in mpc52xx_gpt_do_start() argument
407 clocks = period * (u64)gpt->ipb_freq; in mpc52xx_gpt_do_start()
435 raw_spin_lock_irqsave(&gpt->lock, flags); in mpc52xx_gpt_do_start()
437 gpt->wdt_mode |= MPC52xx_GPT_IS_WDT; in mpc52xx_gpt_do_start()
438 else if ((gpt->wdt_mode & MPC52xx_GPT_IS_WDT) != 0) { in mpc52xx_gpt_do_start()
439 raw_spin_unlock_irqrestore(&gpt->lock, flags); in mpc52xx_gpt_do_start()
442 out_be32(&gpt->regs->count, prescale << 16 | clocks); in mpc52xx_gpt_do_start()
443 clrsetbits_be32(&gpt->regs->mode, clear, set); in mpc52xx_gpt_do_start()
444 raw_spin_unlock_irqrestore(&gpt->lock, flags); in mpc52xx_gpt_do_start()
457 int mpc52xx_gpt_start_timer(struct mpc52xx_gpt_priv *gpt, u64 period, in mpc52xx_gpt_start_timer() argument
460 return mpc52xx_gpt_do_start(gpt, period, continuous, 0); in mpc52xx_gpt_start_timer()
470 int mpc52xx_gpt_stop_timer(struct mpc52xx_gpt_priv *gpt) in mpc52xx_gpt_stop_timer() argument
475 raw_spin_lock_irqsave(&gpt->lock, flags); in mpc52xx_gpt_stop_timer()
476 if ((gpt->wdt_mode & MPC52xx_GPT_IS_WDT) != 0) { in mpc52xx_gpt_stop_timer()
477 raw_spin_unlock_irqrestore(&gpt->lock, flags); in mpc52xx_gpt_stop_timer()
481 clrbits32(&gpt->regs->mode, MPC52xx_GPT_MODE_COUNTER_ENABLE); in mpc52xx_gpt_stop_timer()
482 raw_spin_unlock_irqrestore(&gpt->lock, flags); in mpc52xx_gpt_stop_timer()
493 u64 mpc52xx_gpt_timer_period(struct mpc52xx_gpt_priv *gpt) in mpc52xx_gpt_timer_period() argument
499 raw_spin_lock_irqsave(&gpt->lock, flags); in mpc52xx_gpt_timer_period()
500 period = in_be32(&gpt->regs->count); in mpc52xx_gpt_timer_period()
501 raw_spin_unlock_irqrestore(&gpt->lock, flags); in mpc52xx_gpt_timer_period()
508 do_div(period, (u64)gpt->ipb_freq); in mpc52xx_gpt_timer_period()
676 static int mpc52xx_gpt_wdt_setup(struct mpc52xx_gpt_priv *gpt, in mpc52xx_gpt_wdt_setup() argument
682 mpc52xx_gpt_wdt = gpt; in mpc52xx_gpt_wdt_setup()
689 if (mpc52xx_gpt_do_start(gpt, real_timeout, 0, 1)) in mpc52xx_gpt_wdt_setup()
690 dev_warn(gpt->dev, "starting as wdt failed\n"); in mpc52xx_gpt_wdt_setup()
692 dev_info(gpt->dev, "watchdog set to %us timeout\n", *period); in mpc52xx_gpt_wdt_setup()
703 static inline int mpc52xx_gpt_wdt_setup(struct mpc52xx_gpt_priv *gpt, in mpc52xx_gpt_wdt_setup() argument
716 struct mpc52xx_gpt_priv *gpt; in mpc52xx_gpt_probe() local
718 gpt = devm_kzalloc(&ofdev->dev, sizeof *gpt, GFP_KERNEL); in mpc52xx_gpt_probe()
719 if (!gpt) in mpc52xx_gpt_probe()
722 raw_spin_lock_init(&gpt->lock); in mpc52xx_gpt_probe()
723 gpt->dev = &ofdev->dev; in mpc52xx_gpt_probe()
724 gpt->ipb_freq = mpc5xxx_get_bus_frequency(ofdev->dev.of_node); in mpc52xx_gpt_probe()
725 gpt->regs = of_iomap(ofdev->dev.of_node, 0); in mpc52xx_gpt_probe()
726 if (!gpt->regs) in mpc52xx_gpt_probe()
729 dev_set_drvdata(&ofdev->dev, gpt); in mpc52xx_gpt_probe()
731 mpc52xx_gpt_gpio_setup(gpt, ofdev->dev.of_node); in mpc52xx_gpt_probe()
732 mpc52xx_gpt_irq_setup(gpt, ofdev->dev.of_node); in mpc52xx_gpt_probe()
735 list_add(&gpt->list, &mpc52xx_gpt_list); in mpc52xx_gpt_probe()
743 gpt->wdt_mode = MPC52xx_GPT_CAN_WDT; in mpc52xx_gpt_probe()
747 dev_info(gpt->dev, "used as watchdog\n"); in mpc52xx_gpt_probe()
748 gpt->wdt_mode |= MPC52xx_GPT_IS_WDT; in mpc52xx_gpt_probe()
750 dev_info(gpt->dev, "can function as watchdog\n"); in mpc52xx_gpt_probe()
751 mpc52xx_gpt_wdt_setup(gpt, on_boot_wdt); in mpc52xx_gpt_probe()