Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

at v5.2-rc7 253 lines 6.2 kB view raw
1// SPDX-License-Identifier: GPL-2.0-only 2/* 3 * PXA930 track ball mouse driver 4 * 5 * Copyright (C) 2007 Marvell International Ltd. 6 * 2008-02-28: Yong Yao <yaoyong@marvell.com> 7 * initial version 8 */ 9 10#include <linux/input.h> 11#include <linux/interrupt.h> 12#include <linux/module.h> 13#include <linux/platform_device.h> 14#include <linux/delay.h> 15#include <linux/io.h> 16#include <linux/slab.h> 17 18#include <mach/hardware.h> 19#include <linux/platform_data/mouse-pxa930_trkball.h> 20 21/* Trackball Controller Register Definitions */ 22#define TBCR (0x000C) 23#define TBCNTR (0x0010) 24#define TBSBC (0x0014) 25 26#define TBCR_TBRST (1 << 1) 27#define TBCR_TBSB (1 << 10) 28 29#define TBCR_Y_FLT(n) (((n) & 0xf) << 6) 30#define TBCR_X_FLT(n) (((n) & 0xf) << 2) 31 32#define TBCNTR_YM(n) (((n) >> 24) & 0xff) 33#define TBCNTR_YP(n) (((n) >> 16) & 0xff) 34#define TBCNTR_XM(n) (((n) >> 8) & 0xff) 35#define TBCNTR_XP(n) ((n) & 0xff) 36 37#define TBSBC_TBSBC (0x1) 38 39struct pxa930_trkball { 40 struct pxa930_trkball_platform_data *pdata; 41 42 /* Memory Mapped Register */ 43 struct resource *mem; 44 void __iomem *mmio_base; 45 46 struct input_dev *input; 47}; 48 49static irqreturn_t pxa930_trkball_interrupt(int irq, void *dev_id) 50{ 51 struct pxa930_trkball *trkball = dev_id; 52 struct input_dev *input = trkball->input; 53 int tbcntr, x, y; 54 55 /* According to the spec software must read TBCNTR twice: 56 * if the read value is the same, the reading is valid 57 */ 58 tbcntr = __raw_readl(trkball->mmio_base + TBCNTR); 59 60 if (tbcntr == __raw_readl(trkball->mmio_base + TBCNTR)) { 61 x = (TBCNTR_XP(tbcntr) - TBCNTR_XM(tbcntr)) / 2; 62 y = (TBCNTR_YP(tbcntr) - TBCNTR_YM(tbcntr)) / 2; 63 64 input_report_rel(input, REL_X, x); 65 input_report_rel(input, REL_Y, y); 66 input_sync(input); 67 } 68 69 __raw_writel(TBSBC_TBSBC, trkball->mmio_base + TBSBC); 70 __raw_writel(0, trkball->mmio_base + TBSBC); 71 72 return IRQ_HANDLED; 73} 74 75/* For TBCR, we need to wait for a while to make sure it has been modified. */ 76static int write_tbcr(struct pxa930_trkball *trkball, int v) 77{ 78 int i = 100; 79 80 __raw_writel(v, trkball->mmio_base + TBCR); 81 82 while (--i) { 83 if (__raw_readl(trkball->mmio_base + TBCR) == v) 84 break; 85 msleep(1); 86 } 87 88 if (i == 0) { 89 pr_err("%s: timed out writing TBCR(%x)!\n", __func__, v); 90 return -ETIMEDOUT; 91 } 92 93 return 0; 94} 95 96static void pxa930_trkball_config(struct pxa930_trkball *trkball) 97{ 98 uint32_t tbcr; 99 100 /* According to spec, need to write the filters of x,y to 0xf first! */ 101 tbcr = __raw_readl(trkball->mmio_base + TBCR); 102 write_tbcr(trkball, tbcr | TBCR_X_FLT(0xf) | TBCR_Y_FLT(0xf)); 103 write_tbcr(trkball, TBCR_X_FLT(trkball->pdata->x_filter) | 104 TBCR_Y_FLT(trkball->pdata->y_filter)); 105 106 /* According to spec, set TBCR_TBRST first, before clearing it! */ 107 tbcr = __raw_readl(trkball->mmio_base + TBCR); 108 write_tbcr(trkball, tbcr | TBCR_TBRST); 109 write_tbcr(trkball, tbcr & ~TBCR_TBRST); 110 111 __raw_writel(TBSBC_TBSBC, trkball->mmio_base + TBSBC); 112 __raw_writel(0, trkball->mmio_base + TBSBC); 113 114 pr_debug("%s: final TBCR=%x!\n", __func__, 115 __raw_readl(trkball->mmio_base + TBCR)); 116} 117 118static int pxa930_trkball_open(struct input_dev *dev) 119{ 120 struct pxa930_trkball *trkball = input_get_drvdata(dev); 121 122 pxa930_trkball_config(trkball); 123 124 return 0; 125} 126 127static void pxa930_trkball_disable(struct pxa930_trkball *trkball) 128{ 129 uint32_t tbcr = __raw_readl(trkball->mmio_base + TBCR); 130 131 /* Held in reset, gate the 32-KHz input clock off */ 132 write_tbcr(trkball, tbcr | TBCR_TBRST); 133} 134 135static void pxa930_trkball_close(struct input_dev *dev) 136{ 137 struct pxa930_trkball *trkball = input_get_drvdata(dev); 138 139 pxa930_trkball_disable(trkball); 140} 141 142static int pxa930_trkball_probe(struct platform_device *pdev) 143{ 144 struct pxa930_trkball *trkball; 145 struct input_dev *input; 146 struct resource *res; 147 int irq, error; 148 149 irq = platform_get_irq(pdev, 0); 150 if (irq < 0) { 151 dev_err(&pdev->dev, "failed to get trkball irq\n"); 152 return -ENXIO; 153 } 154 155 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 156 if (!res) { 157 dev_err(&pdev->dev, "failed to get register memory\n"); 158 return -ENXIO; 159 } 160 161 trkball = kzalloc(sizeof(struct pxa930_trkball), GFP_KERNEL); 162 if (!trkball) 163 return -ENOMEM; 164 165 trkball->pdata = dev_get_platdata(&pdev->dev); 166 if (!trkball->pdata) { 167 dev_err(&pdev->dev, "no platform data defined\n"); 168 error = -EINVAL; 169 goto failed; 170 } 171 172 trkball->mmio_base = ioremap_nocache(res->start, resource_size(res)); 173 if (!trkball->mmio_base) { 174 dev_err(&pdev->dev, "failed to ioremap registers\n"); 175 error = -ENXIO; 176 goto failed; 177 } 178 179 /* held the module in reset, will be enabled in open() */ 180 pxa930_trkball_disable(trkball); 181 182 error = request_irq(irq, pxa930_trkball_interrupt, 0, 183 pdev->name, trkball); 184 if (error) { 185 dev_err(&pdev->dev, "failed to request irq: %d\n", error); 186 goto failed_free_io; 187 } 188 189 platform_set_drvdata(pdev, trkball); 190 191 input = input_allocate_device(); 192 if (!input) { 193 dev_err(&pdev->dev, "failed to allocate input device\n"); 194 error = -ENOMEM; 195 goto failed_free_irq; 196 } 197 198 input->name = pdev->name; 199 input->id.bustype = BUS_HOST; 200 input->open = pxa930_trkball_open; 201 input->close = pxa930_trkball_close; 202 input->dev.parent = &pdev->dev; 203 input_set_drvdata(input, trkball); 204 205 trkball->input = input; 206 207 input_set_capability(input, EV_REL, REL_X); 208 input_set_capability(input, EV_REL, REL_Y); 209 210 error = input_register_device(input); 211 if (error) { 212 dev_err(&pdev->dev, "unable to register input device\n"); 213 goto failed_free_input; 214 } 215 216 return 0; 217 218failed_free_input: 219 input_free_device(input); 220failed_free_irq: 221 free_irq(irq, trkball); 222failed_free_io: 223 iounmap(trkball->mmio_base); 224failed: 225 kfree(trkball); 226 return error; 227} 228 229static int pxa930_trkball_remove(struct platform_device *pdev) 230{ 231 struct pxa930_trkball *trkball = platform_get_drvdata(pdev); 232 int irq = platform_get_irq(pdev, 0); 233 234 input_unregister_device(trkball->input); 235 free_irq(irq, trkball); 236 iounmap(trkball->mmio_base); 237 kfree(trkball); 238 239 return 0; 240} 241 242static struct platform_driver pxa930_trkball_driver = { 243 .driver = { 244 .name = "pxa930-trkball", 245 }, 246 .probe = pxa930_trkball_probe, 247 .remove = pxa930_trkball_remove, 248}; 249module_platform_driver(pxa930_trkball_driver); 250 251MODULE_AUTHOR("Yong Yao <yaoyong@marvell.com>"); 252MODULE_DESCRIPTION("PXA930 Trackball Mouse Driver"); 253MODULE_LICENSE("GPL");