From ac45e6293f3074dc6ccf984e210c8793796eaf28 Mon Sep 17 00:00:00 2001 From: WEN Pingbo Date: Mon, 1 Jan 2018 21:29:18 -0800 Subject: Input: hil_mlc - convert timeval to time64_t Since mlc->lcv_t is only interested in seconds, directly using time64_t here. This gets rid of the deprecated do_gettimeofday() and avoids problems with time going backwards since we now use the monotonic clocksource. Signed-off-by: WEN Pingbo Signed-off-by: Arnd Bergmann Patchwork-Id: 10076611 Signed-off-by: Dmitry Torokhov --- drivers/input/serio/hil_mlc.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'drivers/input/serio') diff --git a/drivers/input/serio/hil_mlc.c b/drivers/input/serio/hil_mlc.c index d66d01c5373b..581e47119363 100644 --- a/drivers/input/serio/hil_mlc.c +++ b/drivers/input/serio/hil_mlc.c @@ -274,14 +274,12 @@ static int hilse_match(hil_mlc *mlc, int unused) /* An LCV used to prevent runaway loops, forces 5 second sleep when reset. */ static int hilse_init_lcv(hil_mlc *mlc, int unused) { - struct timeval tv; + time64_t now = ktime_get_seconds(); - do_gettimeofday(&tv); - - if (mlc->lcv && (tv.tv_sec - mlc->lcv_tv.tv_sec) < 5) + if (mlc->lcv && (now - mlc->lcv_time) < 5) return -1; - mlc->lcv_tv = tv; + mlc->lcv_time = now; mlc->lcv = 0; return 0; -- cgit v1.2.3-59-g8ed1b From 59d805af417809820ed54a8a02525b03bc74d62a Mon Sep 17 00:00:00 2001 From: WEN Pingbo Date: Mon, 1 Jan 2018 21:31:18 -0800 Subject: Input: hil_mlc - convert timeval to jiffies struct timeval is not y2038 safe, and what mlc->instart do is scheduling a task in a fixed timeout, so jiffies is the simplest choice here. In hilse_donode(), the expires in mod_timer equals jiffies + intimeout - (now - instart) If we use jiffies in 'now', the expires equals instart + intimeout So, all we need to do is that making sure expires is a future timestamp before passed it to mod_timer. [arnd: slightly simplified patch further] Link: https://lists.linaro.org/pipermail/y2038/2015-October/000937.html Signed-off-by: WEN Pingbo Signed-off-by: Arnd Bergmann Patchwork-Id: 10076615 Signed-off-by: Dmitry Torokhov --- drivers/input/serio/hil_mlc.c | 18 +++++++----------- drivers/input/serio/hp_sdc_mlc.c | 5 +---- include/linux/hil_mlc.h | 4 ++-- 3 files changed, 10 insertions(+), 17 deletions(-) (limited to 'drivers/input/serio') diff --git a/drivers/input/serio/hil_mlc.c b/drivers/input/serio/hil_mlc.c index 581e47119363..e1423f7648d6 100644 --- a/drivers/input/serio/hil_mlc.c +++ b/drivers/input/serio/hil_mlc.c @@ -602,8 +602,8 @@ static inline void hilse_setup_input(hil_mlc *mlc, const struct hilse_node *node BUG(); } mlc->istarted = 1; - mlc->intimeout = node->arg; - do_gettimeofday(&(mlc->instart)); + mlc->intimeout = usecs_to_jiffies(node->arg); + mlc->instart = jiffies; mlc->icount = 15; memset(mlc->ipacket, 0, 16 * sizeof(hil_packet)); BUG_ON(down_trylock(&mlc->isem)); @@ -708,7 +708,7 @@ static int hilse_donode(hil_mlc *mlc) break; } mlc->ostarted = 0; - do_gettimeofday(&(mlc->instart)); + mlc->instart = jiffies; write_unlock_irqrestore(&mlc->lock, flags); nextidx = HILSEN_NEXT; break; @@ -729,18 +729,14 @@ static int hilse_donode(hil_mlc *mlc) #endif while (nextidx & HILSEN_SCHED) { - struct timeval tv; + unsigned long now = jiffies; if (!sched_long) goto sched; - do_gettimeofday(&tv); - tv.tv_usec += USEC_PER_SEC * (tv.tv_sec - mlc->instart.tv_sec); - tv.tv_usec -= mlc->instart.tv_usec; - if (tv.tv_usec >= mlc->intimeout) goto sched; - tv.tv_usec = (mlc->intimeout - tv.tv_usec) * HZ / USEC_PER_SEC; - if (!tv.tv_usec) goto sched; - mod_timer(&hil_mlcs_kicker, jiffies + tv.tv_usec); + if (time_after(now, mlc->instart + mlc->intimeout)) + goto sched; + mod_timer(&hil_mlcs_kicker, mlc->instart + mlc->intimeout); break; sched: tasklet_schedule(&hil_mlcs_tasklet); diff --git a/drivers/input/serio/hp_sdc_mlc.c b/drivers/input/serio/hp_sdc_mlc.c index d50f0678bf47..232d30c825bd 100644 --- a/drivers/input/serio/hp_sdc_mlc.c +++ b/drivers/input/serio/hp_sdc_mlc.c @@ -149,7 +149,6 @@ static int hp_sdc_mlc_in(hil_mlc *mlc, suseconds_t timeout) /* Try to down the semaphore */ if (down_trylock(&mlc->isem)) { - struct timeval tv; if (priv->emtestmode) { mlc->ipacket[0] = HIL_ERR_INT | (mlc->opacket & @@ -160,9 +159,7 @@ static int hp_sdc_mlc_in(hil_mlc *mlc, suseconds_t timeout) /* printk(KERN_DEBUG PREFIX ">[%x]\n", mlc->ipacket[0]); */ goto wasup; } - do_gettimeofday(&tv); - tv.tv_usec += USEC_PER_SEC * (tv.tv_sec - mlc->instart.tv_sec); - if (tv.tv_usec - mlc->instart.tv_usec > mlc->intimeout) { + if (time_after(jiffies, mlc->instart + mlc->intimeout)) { /* printk("!%i %i", tv.tv_usec - mlc->instart.tv_usec, mlc->intimeout); diff --git a/include/linux/hil_mlc.h b/include/linux/hil_mlc.h index d6fc839bdf46..774f7d3b8f6a 100644 --- a/include/linux/hil_mlc.h +++ b/include/linux/hil_mlc.h @@ -144,8 +144,8 @@ struct hil_mlc { hil_packet ipacket[16]; hil_packet imatch; int icount; - struct timeval instart; - suseconds_t intimeout; + unsigned long instart; + unsigned long intimeout; int ddi; /* Last operational device id */ int lcv; /* LCV to throttle loops */ -- cgit v1.2.3-59-g8ed1b From d09ac610eaaa0b3b29c3ac6c4e107cb1dbd4a356 Mon Sep 17 00:00:00 2001 From: Arnd Bergmann Date: Mon, 1 Jan 2018 21:32:02 -0800 Subject: Input: hp_sdc - convert to ktime_get() This gets rid of the deprecated do_gettimeofday() call in favor of ktime_get(), which is also more reliable as it uses monotonic times. The code now gets a bit simpler. Signed-off-by: Arnd Bergmann Patchwork-Id: 10076621 Signed-off-by: Dmitry Torokhov --- drivers/input/serio/hp_sdc.c | 17 +++++++---------- include/linux/hp_sdc.h | 2 +- 2 files changed, 8 insertions(+), 11 deletions(-) (limited to 'drivers/input/serio') diff --git a/drivers/input/serio/hp_sdc.c b/drivers/input/serio/hp_sdc.c index 1d7c7d81a5ef..0b8a25c58d02 100644 --- a/drivers/input/serio/hp_sdc.c +++ b/drivers/input/serio/hp_sdc.c @@ -193,7 +193,7 @@ static void hp_sdc_take(int irq, void *dev_id, uint8_t status, uint8_t data) curr->seq[curr->idx++] = status; curr->seq[curr->idx++] = data; hp_sdc.rqty -= 2; - do_gettimeofday(&hp_sdc.rtv); + hp_sdc.rtime = ktime_get(); if (hp_sdc.rqty <= 0) { /* All data has been gathered. */ @@ -306,13 +306,10 @@ static void hp_sdc_tasklet(unsigned long foo) write_lock_irq(&hp_sdc.rtq_lock); if (hp_sdc.rcurr >= 0) { - struct timeval tv; + ktime_t now = ktime_get(); - do_gettimeofday(&tv); - if (tv.tv_sec > hp_sdc.rtv.tv_sec) - tv.tv_usec += USEC_PER_SEC; - - if (tv.tv_usec - hp_sdc.rtv.tv_usec > HP_SDC_MAX_REG_DELAY) { + if (ktime_after(now, ktime_add_us(hp_sdc.rtime, + HP_SDC_MAX_REG_DELAY))) { hp_sdc_transaction *curr; uint8_t tmp; @@ -321,8 +318,8 @@ static void hp_sdc_tasklet(unsigned long foo) * we'll need to figure out a way to communicate * it back to the application. and be less verbose. */ - printk(KERN_WARNING PREFIX "read timeout (%ius)!\n", - (int)(tv.tv_usec - hp_sdc.rtv.tv_usec)); + printk(KERN_WARNING PREFIX "read timeout (%lldus)!\n", + ktime_us_delta(now, hp_sdc.rtime)); curr->idx += hp_sdc.rqty; hp_sdc.rqty = 0; tmp = curr->seq[curr->actidx]; @@ -551,7 +548,7 @@ unsigned long hp_sdc_put(void) /* Start a new read */ hp_sdc.rqty = curr->seq[curr->idx]; - do_gettimeofday(&hp_sdc.rtv); + hp_sdc.rtime = ktime_get(); curr->idx++; /* Still need to lock here in case of spurious irq. */ write_lock_irq(&hp_sdc.rtq_lock); diff --git a/include/linux/hp_sdc.h b/include/linux/hp_sdc.h index d392975d8887..6f1dee7e67e0 100644 --- a/include/linux/hp_sdc.h +++ b/include/linux/hp_sdc.h @@ -281,7 +281,7 @@ typedef struct { hp_sdc_transaction *tq[HP_SDC_QUEUE_LEN]; /* All pending read/writes */ int rcurr, rqty; /* Current read transact in process */ - struct timeval rtv; /* Time when current read started */ + ktime_t rtime; /* Time when current read started */ int wcurr; /* Current write transact in process */ int dev_err; /* carries status from registration */ -- cgit v1.2.3-59-g8ed1b From 0de45027257bbae71a78240af4903d08447a669c Mon Sep 17 00:00:00 2001 From: Corentin Labbe Date: Thu, 18 Jan 2018 11:16:16 -0800 Subject: Input: remove at32psif Since AVR32 arch is gone, at32psif driver is useless. Signed-off-by: Corentin Labbe Signed-off-by: Dmitry Torokhov --- drivers/input/serio/Kconfig | 10 -- drivers/input/serio/Makefile | 1 - drivers/input/serio/at32psif.c | 357 ----------------------------------------- 3 files changed, 368 deletions(-) delete mode 100644 drivers/input/serio/at32psif.c (limited to 'drivers/input/serio') diff --git a/drivers/input/serio/Kconfig b/drivers/input/serio/Kconfig index 21488c048fa3..ca4530eb3378 100644 --- a/drivers/input/serio/Kconfig +++ b/drivers/input/serio/Kconfig @@ -96,16 +96,6 @@ config SERIO_RPCKBD To compile this driver as a module, choose M here: the module will be called rpckbd. -config SERIO_AT32PSIF - tristate "AVR32 PSIF PS/2 keyboard and mouse controller" - depends on AVR32 - help - Say Y here if you want to use the PSIF peripheral on AVR32 devices - and connect a PS/2 keyboard and/or mouse to it. - - To compile this driver as a module, choose M here: the module will - be called at32psif. - config SERIO_AMBAKMI tristate "AMBA KMI keyboard controller" depends on ARM_AMBA diff --git a/drivers/input/serio/Makefile b/drivers/input/serio/Makefile index a3ca07621542..67950a5ccb3f 100644 --- a/drivers/input/serio/Makefile +++ b/drivers/input/serio/Makefile @@ -13,7 +13,6 @@ obj-$(CONFIG_SERIO_CT82C710) += ct82c710.o obj-$(CONFIG_SERIO_RPCKBD) += rpckbd.o obj-$(CONFIG_SERIO_SA1111) += sa1111ps2.o obj-$(CONFIG_SERIO_AMBAKMI) += ambakmi.o -obj-$(CONFIG_SERIO_AT32PSIF) += at32psif.o obj-$(CONFIG_SERIO_Q40KBD) += q40kbd.o obj-$(CONFIG_SERIO_GSCPS2) += gscps2.o obj-$(CONFIG_HP_SDC) += hp_sdc.o diff --git a/drivers/input/serio/at32psif.c b/drivers/input/serio/at32psif.c deleted file mode 100644 index e420fd781d44..000000000000 --- a/drivers/input/serio/at32psif.c +++ /dev/null @@ -1,357 +0,0 @@ -/* - * Copyright (C) 2007 Atmel Corporation - * - * Driver for the AT32AP700X PS/2 controller (PSIF). - * - * This program is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 as published - * by the Free Software Foundation. - */ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -/* PSIF register offsets */ -#define PSIF_CR 0x00 -#define PSIF_RHR 0x04 -#define PSIF_THR 0x08 -#define PSIF_SR 0x10 -#define PSIF_IER 0x14 -#define PSIF_IDR 0x18 -#define PSIF_IMR 0x1c -#define PSIF_PSR 0x24 - -/* Bitfields in control register. */ -#define PSIF_CR_RXDIS_OFFSET 1 -#define PSIF_CR_RXDIS_SIZE 1 -#define PSIF_CR_RXEN_OFFSET 0 -#define PSIF_CR_RXEN_SIZE 1 -#define PSIF_CR_SWRST_OFFSET 15 -#define PSIF_CR_SWRST_SIZE 1 -#define PSIF_CR_TXDIS_OFFSET 9 -#define PSIF_CR_TXDIS_SIZE 1 -#define PSIF_CR_TXEN_OFFSET 8 -#define PSIF_CR_TXEN_SIZE 1 - -/* Bitfields in interrupt disable, enable, mask and status register. */ -#define PSIF_NACK_OFFSET 8 -#define PSIF_NACK_SIZE 1 -#define PSIF_OVRUN_OFFSET 5 -#define PSIF_OVRUN_SIZE 1 -#define PSIF_PARITY_OFFSET 9 -#define PSIF_PARITY_SIZE 1 -#define PSIF_RXRDY_OFFSET 4 -#define PSIF_RXRDY_SIZE 1 -#define PSIF_TXEMPTY_OFFSET 1 -#define PSIF_TXEMPTY_SIZE 1 -#define PSIF_TXRDY_OFFSET 0 -#define PSIF_TXRDY_SIZE 1 - -/* Bitfields in prescale register. */ -#define PSIF_PSR_PRSCV_OFFSET 0 -#define PSIF_PSR_PRSCV_SIZE 12 - -/* Bitfields in receive hold register. */ -#define PSIF_RHR_RXDATA_OFFSET 0 -#define PSIF_RHR_RXDATA_SIZE 8 - -/* Bitfields in transmit hold register. */ -#define PSIF_THR_TXDATA_OFFSET 0 -#define PSIF_THR_TXDATA_SIZE 8 - -/* Bit manipulation macros */ -#define PSIF_BIT(name) \ - (1 << PSIF_##name##_OFFSET) - -#define PSIF_BF(name, value) \ - (((value) & ((1 << PSIF_##name##_SIZE) - 1)) \ - << PSIF_##name##_OFFSET) - -#define PSIF_BFEXT(name, value) \ - (((value) >> PSIF_##name##_OFFSET) \ - & ((1 << PSIF_##name##_SIZE) - 1)) - -#define PSIF_BFINS(name, value, old) \ - (((old) & ~(((1 << PSIF_##name##_SIZE) - 1) \ - << PSIF_##name##_OFFSET)) \ - | PSIF_BF(name, value)) - -/* Register access macros */ -#define psif_readl(port, reg) \ - __raw_readl((port)->regs + PSIF_##reg) - -#define psif_writel(port, reg, value) \ - __raw_writel((value), (port)->regs + PSIF_##reg) - -struct psif { - struct platform_device *pdev; - struct clk *pclk; - struct serio *io; - void __iomem *regs; - unsigned int irq; - /* Prevent concurrent writes to PSIF THR. */ - spinlock_t lock; - bool open; -}; - -static irqreturn_t psif_interrupt(int irq, void *_ptr) -{ - struct psif *psif = _ptr; - int retval = IRQ_NONE; - unsigned int io_flags = 0; - unsigned long status; - - status = psif_readl(psif, SR); - - if (status & PSIF_BIT(RXRDY)) { - unsigned char val = (unsigned char) psif_readl(psif, RHR); - - if (status & PSIF_BIT(PARITY)) - io_flags |= SERIO_PARITY; - if (status & PSIF_BIT(OVRUN)) - dev_err(&psif->pdev->dev, "overrun read error\n"); - - serio_interrupt(psif->io, val, io_flags); - - retval = IRQ_HANDLED; - } - - return retval; -} - -static int psif_write(struct serio *io, unsigned char val) -{ - struct psif *psif = io->port_data; - unsigned long flags; - int timeout = 10; - int retval = 0; - - spin_lock_irqsave(&psif->lock, flags); - - while (!(psif_readl(psif, SR) & PSIF_BIT(TXEMPTY)) && timeout--) - udelay(50); - - if (timeout >= 0) { - psif_writel(psif, THR, val); - } else { - dev_dbg(&psif->pdev->dev, "timeout writing to THR\n"); - retval = -EBUSY; - } - - spin_unlock_irqrestore(&psif->lock, flags); - - return retval; -} - -static int psif_open(struct serio *io) -{ - struct psif *psif = io->port_data; - int retval; - - retval = clk_enable(psif->pclk); - if (retval) - return retval; - - psif_writel(psif, CR, PSIF_BIT(CR_TXEN) | PSIF_BIT(CR_RXEN)); - psif_writel(psif, IER, PSIF_BIT(RXRDY)); - - psif->open = true; - return retval; -} - -static void psif_close(struct serio *io) -{ - struct psif *psif = io->port_data; - - psif->open = false; - - psif_writel(psif, IDR, ~0UL); - psif_writel(psif, CR, PSIF_BIT(CR_TXDIS) | PSIF_BIT(CR_RXDIS)); - - clk_disable(psif->pclk); -} - -static void psif_set_prescaler(struct psif *psif) -{ - unsigned long prscv; - unsigned long rate = clk_get_rate(psif->pclk); - - /* PRSCV = Pulse length (100 us) * PSIF module frequency. */ - prscv = 100 * (rate / 1000000UL); - - if (prscv > ((1<pdev->dev, "pclk too fast, " - "prescaler set to max\n"); - } - - clk_enable(psif->pclk); - psif_writel(psif, PSR, prscv); - clk_disable(psif->pclk); -} - -static int __init psif_probe(struct platform_device *pdev) -{ - struct resource *regs; - struct psif *psif; - struct serio *io; - struct clk *pclk; - int irq; - int ret; - - psif = kzalloc(sizeof(struct psif), GFP_KERNEL); - if (!psif) - return -ENOMEM; - psif->pdev = pdev; - - io = kzalloc(sizeof(struct serio), GFP_KERNEL); - if (!io) { - ret = -ENOMEM; - goto out_free_psif; - } - psif->io = io; - - regs = platform_get_resource(pdev, IORESOURCE_MEM, 0); - if (!regs) { - dev_dbg(&pdev->dev, "no mmio resources defined\n"); - ret = -ENOMEM; - goto out_free_io; - } - - psif->regs = ioremap(regs->start, resource_size(regs)); - if (!psif->regs) { - ret = -ENOMEM; - dev_dbg(&pdev->dev, "could not map I/O memory\n"); - goto out_free_io; - } - - pclk = clk_get(&pdev->dev, "pclk"); - if (IS_ERR(pclk)) { - dev_dbg(&pdev->dev, "could not get peripheral clock\n"); - ret = PTR_ERR(pclk); - goto out_iounmap; - } - psif->pclk = pclk; - - /* Reset the PSIF to enter at a known state. */ - ret = clk_enable(pclk); - if (ret) { - dev_dbg(&pdev->dev, "could not enable pclk\n"); - goto out_put_clk; - } - psif_writel(psif, CR, PSIF_BIT(CR_SWRST)); - clk_disable(pclk); - - irq = platform_get_irq(pdev, 0); - if (irq < 0) { - dev_dbg(&pdev->dev, "could not get irq\n"); - ret = -ENXIO; - goto out_put_clk; - } - ret = request_irq(irq, psif_interrupt, IRQF_SHARED, "at32psif", psif); - if (ret) { - dev_dbg(&pdev->dev, "could not request irq %d\n", irq); - goto out_put_clk; - } - psif->irq = irq; - - io->id.type = SERIO_8042; - io->write = psif_write; - io->open = psif_open; - io->close = psif_close; - snprintf(io->name, sizeof(io->name), "AVR32 PS/2 port%d", pdev->id); - snprintf(io->phys, sizeof(io->phys), "at32psif/serio%d", pdev->id); - io->port_data = psif; - io->dev.parent = &pdev->dev; - - psif_set_prescaler(psif); - - spin_lock_init(&psif->lock); - serio_register_port(psif->io); - platform_set_drvdata(pdev, psif); - - dev_info(&pdev->dev, "Atmel AVR32 PSIF PS/2 driver on 0x%08x irq %d\n", - (int)psif->regs, psif->irq); - - return 0; - -out_put_clk: - clk_put(psif->pclk); -out_iounmap: - iounmap(psif->regs); -out_free_io: - kfree(io); -out_free_psif: - kfree(psif); - return ret; -} - -static int __exit psif_remove(struct platform_device *pdev) -{ - struct psif *psif = platform_get_drvdata(pdev); - - psif_writel(psif, IDR, ~0UL); - psif_writel(psif, CR, PSIF_BIT(CR_TXDIS) | PSIF_BIT(CR_RXDIS)); - - serio_unregister_port(psif->io); - iounmap(psif->regs); - free_irq(psif->irq, psif); - clk_put(psif->pclk); - kfree(psif); - - return 0; -} - -#ifdef CONFIG_PM_SLEEP -static int psif_suspend(struct device *dev) -{ - struct platform_device *pdev = to_platform_device(dev); - struct psif *psif = platform_get_drvdata(pdev); - - if (psif->open) { - psif_writel(psif, CR, PSIF_BIT(CR_RXDIS) | PSIF_BIT(CR_TXDIS)); - clk_disable(psif->pclk); - } - - return 0; -} - -static int psif_resume(struct device *dev) -{ - struct platform_device *pdev = to_platform_device(dev); - struct psif *psif = platform_get_drvdata(pdev); - - if (psif->open) { - clk_enable(psif->pclk); - psif_set_prescaler(psif); - psif_writel(psif, CR, PSIF_BIT(CR_RXEN) | PSIF_BIT(CR_TXEN)); - } - - return 0; -} -#endif - -static SIMPLE_DEV_PM_OPS(psif_pm_ops, psif_suspend, psif_resume); - -static struct platform_driver psif_driver = { - .remove = __exit_p(psif_remove), - .driver = { - .name = "atmel_psif", - .pm = &psif_pm_ops, - }, -}; - -module_platform_driver_probe(psif_driver, psif_probe); - -MODULE_AUTHOR("Hans-Christian Egtvedt "); -MODULE_DESCRIPTION("Atmel AVR32 PSIF PS/2 driver"); -MODULE_LICENSE("GPL"); -- cgit v1.2.3-59-g8ed1b