Benson Leung | d7e34d1 | 2013-01-09 16:25:11 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Cypress APA trackpad with I2C interface |
| 3 | * |
| 4 | * Author: Dudley Du <dudl@cypress.com> |
| 5 | * Further cleanup and restructuring by: |
| 6 | * Daniel Kurtz <djkurtz@chromium.org> |
| 7 | * Benson Leung <bleung@chromium.org> |
| 8 | * |
Dudley Du | 9489761 | 2015-07-20 16:49:06 -0700 | [diff] [blame] | 9 | * Copyright (C) 2011-2015 Cypress Semiconductor, Inc. |
Benson Leung | d7e34d1 | 2013-01-09 16:25:11 -0800 | [diff] [blame] | 10 | * Copyright (C) 2011-2012 Google, Inc. |
| 11 | * |
| 12 | * This file is subject to the terms and conditions of the GNU General Public |
| 13 | * License. See the file COPYING in the main directory of this archive for |
| 14 | * more details. |
| 15 | */ |
| 16 | |
| 17 | #include <linux/delay.h> |
| 18 | #include <linux/i2c.h> |
| 19 | #include <linux/input.h> |
| 20 | #include <linux/input/mt.h> |
| 21 | #include <linux/interrupt.h> |
| 22 | #include <linux/module.h> |
Dudley Du | 9f1cd85 | 2015-01-17 18:35:26 -0800 | [diff] [blame] | 23 | #include <linux/mutex.h> |
Dudley Du | 36e9615 | 2015-07-30 11:19:18 -0700 | [diff] [blame^] | 24 | #include <linux/regulator/consumer.h> |
Benson Leung | d7e34d1 | 2013-01-09 16:25:11 -0800 | [diff] [blame] | 25 | #include <linux/slab.h> |
Dudley Du | 9f1cd85 | 2015-01-17 18:35:26 -0800 | [diff] [blame] | 26 | #include <linux/uaccess.h> |
Dudley Du | 6728650 | 2015-01-17 18:57:42 -0800 | [diff] [blame] | 27 | #include <linux/pm_runtime.h> |
Dudley Du | 7b2171d | 2015-01-17 22:18:59 -0800 | [diff] [blame] | 28 | #include <linux/acpi.h> |
Dudley Du | 9f1cd85 | 2015-01-17 18:35:26 -0800 | [diff] [blame] | 29 | #include "cyapa.h" |
Benson Leung | d7e34d1 | 2013-01-09 16:25:11 -0800 | [diff] [blame] | 30 | |
Benson Leung | d7e34d1 | 2013-01-09 16:25:11 -0800 | [diff] [blame] | 31 | |
Benson Leung | 6ddaf74 | 2013-02-13 13:56:03 -0800 | [diff] [blame] | 32 | #define CYAPA_ADAPTER_FUNC_NONE 0 |
| 33 | #define CYAPA_ADAPTER_FUNC_I2C 1 |
| 34 | #define CYAPA_ADAPTER_FUNC_SMBUS 2 |
| 35 | #define CYAPA_ADAPTER_FUNC_BOTH 3 |
| 36 | |
Dudley Du | c806b0b | 2015-01-17 22:07:12 -0800 | [diff] [blame] | 37 | #define CYAPA_FW_NAME "cyapa.bin" |
| 38 | |
Dudley Du | 9f1cd85 | 2015-01-17 18:35:26 -0800 | [diff] [blame] | 39 | const char product_id[] = "CYTRA"; |
Benson Leung | 6ddaf74 | 2013-02-13 13:56:03 -0800 | [diff] [blame] | 40 | |
Dudley Du | 9f1cd85 | 2015-01-17 18:35:26 -0800 | [diff] [blame] | 41 | static int cyapa_reinitialize(struct cyapa *cyapa); |
Benson Leung | 6ddaf74 | 2013-02-13 13:56:03 -0800 | [diff] [blame] | 42 | |
Dudley Du | 9489761 | 2015-07-20 16:49:06 -0700 | [diff] [blame] | 43 | bool cyapa_is_pip_bl_mode(struct cyapa *cyapa) |
Dudley Du | 9f1cd85 | 2015-01-17 18:35:26 -0800 | [diff] [blame] | 44 | { |
Dudley Du | c2c06c4 | 2015-07-20 16:53:30 -0700 | [diff] [blame] | 45 | if (cyapa->gen == CYAPA_GEN6 && cyapa->state == CYAPA_STATE_GEN6_BL) |
| 46 | return true; |
| 47 | |
Dudley Du | 9f1cd85 | 2015-01-17 18:35:26 -0800 | [diff] [blame] | 48 | if (cyapa->gen == CYAPA_GEN5 && cyapa->state == CYAPA_STATE_GEN5_BL) |
| 49 | return true; |
Benson Leung | 6ddaf74 | 2013-02-13 13:56:03 -0800 | [diff] [blame] | 50 | |
Dudley Du | 9489761 | 2015-07-20 16:49:06 -0700 | [diff] [blame] | 51 | return false; |
| 52 | } |
| 53 | |
| 54 | bool cyapa_is_pip_app_mode(struct cyapa *cyapa) |
| 55 | { |
Dudley Du | c2c06c4 | 2015-07-20 16:53:30 -0700 | [diff] [blame] | 56 | if (cyapa->gen == CYAPA_GEN6 && cyapa->state == CYAPA_STATE_GEN6_APP) |
| 57 | return true; |
| 58 | |
Dudley Du | 9489761 | 2015-07-20 16:49:06 -0700 | [diff] [blame] | 59 | if (cyapa->gen == CYAPA_GEN5 && cyapa->state == CYAPA_STATE_GEN5_APP) |
| 60 | return true; |
| 61 | |
| 62 | return false; |
| 63 | } |
| 64 | |
| 65 | static bool cyapa_is_bootloader_mode(struct cyapa *cyapa) |
| 66 | { |
| 67 | if (cyapa_is_pip_bl_mode(cyapa)) |
| 68 | return true; |
| 69 | |
Dudley Du | 9f1cd85 | 2015-01-17 18:35:26 -0800 | [diff] [blame] | 70 | if (cyapa->gen == CYAPA_GEN3 && |
| 71 | cyapa->state >= CYAPA_STATE_BL_BUSY && |
| 72 | cyapa->state <= CYAPA_STATE_BL_ACTIVE) |
| 73 | return true; |
Benson Leung | 6ddaf74 | 2013-02-13 13:56:03 -0800 | [diff] [blame] | 74 | |
Dudley Du | 9f1cd85 | 2015-01-17 18:35:26 -0800 | [diff] [blame] | 75 | return false; |
| 76 | } |
Benson Leung | 6ddaf74 | 2013-02-13 13:56:03 -0800 | [diff] [blame] | 77 | |
Dudley Du | 9f1cd85 | 2015-01-17 18:35:26 -0800 | [diff] [blame] | 78 | static inline bool cyapa_is_operational_mode(struct cyapa *cyapa) |
| 79 | { |
Dudley Du | 9489761 | 2015-07-20 16:49:06 -0700 | [diff] [blame] | 80 | if (cyapa_is_pip_app_mode(cyapa)) |
Dudley Du | 9f1cd85 | 2015-01-17 18:35:26 -0800 | [diff] [blame] | 81 | return true; |
Benson Leung | 6ddaf74 | 2013-02-13 13:56:03 -0800 | [diff] [blame] | 82 | |
Dudley Du | 9f1cd85 | 2015-01-17 18:35:26 -0800 | [diff] [blame] | 83 | if (cyapa->gen == CYAPA_GEN3 && cyapa->state == CYAPA_STATE_OP) |
| 84 | return true; |
Benson Leung | d7e34d1 | 2013-01-09 16:25:11 -0800 | [diff] [blame] | 85 | |
Dudley Du | 9f1cd85 | 2015-01-17 18:35:26 -0800 | [diff] [blame] | 86 | return false; |
| 87 | } |
Benson Leung | 6ddaf74 | 2013-02-13 13:56:03 -0800 | [diff] [blame] | 88 | |
Dudley Du | 9f1cd85 | 2015-01-17 18:35:26 -0800 | [diff] [blame] | 89 | /* Returns 0 on success, else negative errno on failure. */ |
| 90 | static ssize_t cyapa_i2c_read(struct cyapa *cyapa, u8 reg, size_t len, |
Benson Leung | d7e34d1 | 2013-01-09 16:25:11 -0800 | [diff] [blame] | 91 | u8 *values) |
| 92 | { |
Benson Leung | 6ddaf74 | 2013-02-13 13:56:03 -0800 | [diff] [blame] | 93 | struct i2c_client *client = cyapa->client; |
Dudley Du | 9f1cd85 | 2015-01-17 18:35:26 -0800 | [diff] [blame] | 94 | struct i2c_msg msgs[] = { |
| 95 | { |
| 96 | .addr = client->addr, |
| 97 | .flags = 0, |
| 98 | .len = 1, |
| 99 | .buf = ®, |
| 100 | }, |
| 101 | { |
| 102 | .addr = client->addr, |
| 103 | .flags = I2C_M_RD, |
| 104 | .len = len, |
| 105 | .buf = values, |
| 106 | }, |
| 107 | }; |
| 108 | int ret; |
Benson Leung | 6ddaf74 | 2013-02-13 13:56:03 -0800 | [diff] [blame] | 109 | |
Dudley Du | 9f1cd85 | 2015-01-17 18:35:26 -0800 | [diff] [blame] | 110 | ret = i2c_transfer(client->adapter, msgs, ARRAY_SIZE(msgs)); |
Benson Leung | 6ddaf74 | 2013-02-13 13:56:03 -0800 | [diff] [blame] | 111 | |
Dudley Du | 9f1cd85 | 2015-01-17 18:35:26 -0800 | [diff] [blame] | 112 | if (ret != ARRAY_SIZE(msgs)) |
| 113 | return ret < 0 ? ret : -EIO; |
Benson Leung | 6ddaf74 | 2013-02-13 13:56:03 -0800 | [diff] [blame] | 114 | |
Dudley Du | 9f1cd85 | 2015-01-17 18:35:26 -0800 | [diff] [blame] | 115 | return 0; |
Benson Leung | 6ddaf74 | 2013-02-13 13:56:03 -0800 | [diff] [blame] | 116 | } |
| 117 | |
Dudley Du | 9f1cd85 | 2015-01-17 18:35:26 -0800 | [diff] [blame] | 118 | /** |
| 119 | * cyapa_i2c_write - Execute i2c block data write operation |
| 120 | * @cyapa: Handle to this driver |
| 121 | * @ret: Offset of the data to written in the register map |
| 122 | * @len: number of bytes to write |
| 123 | * @values: Data to be written |
| 124 | * |
| 125 | * Return negative errno code on error; return zero when success. |
| 126 | */ |
| 127 | static int cyapa_i2c_write(struct cyapa *cyapa, u8 reg, |
| 128 | size_t len, const void *values) |
Benson Leung | d7e34d1 | 2013-01-09 16:25:11 -0800 | [diff] [blame] | 129 | { |
Dudley Du | 9f1cd85 | 2015-01-17 18:35:26 -0800 | [diff] [blame] | 130 | struct i2c_client *client = cyapa->client; |
| 131 | char buf[32]; |
| 132 | int ret; |
Benson Leung | d7e34d1 | 2013-01-09 16:25:11 -0800 | [diff] [blame] | 133 | |
Dudley Du | 9f1cd85 | 2015-01-17 18:35:26 -0800 | [diff] [blame] | 134 | if (len > sizeof(buf) - 1) |
| 135 | return -ENOMEM; |
| 136 | |
| 137 | buf[0] = reg; |
| 138 | memcpy(&buf[1], values, len); |
| 139 | |
| 140 | ret = i2c_master_send(client, buf, len + 1); |
| 141 | if (ret != len + 1) |
| 142 | return ret < 0 ? ret : -EIO; |
| 143 | |
| 144 | return 0; |
Benson Leung | d7e34d1 | 2013-01-09 16:25:11 -0800 | [diff] [blame] | 145 | } |
| 146 | |
Dudley Du | 9f1cd85 | 2015-01-17 18:35:26 -0800 | [diff] [blame] | 147 | static u8 cyapa_check_adapter_functionality(struct i2c_client *client) |
Benson Leung | d7e34d1 | 2013-01-09 16:25:11 -0800 | [diff] [blame] | 148 | { |
Dudley Du | 9f1cd85 | 2015-01-17 18:35:26 -0800 | [diff] [blame] | 149 | u8 ret = CYAPA_ADAPTER_FUNC_NONE; |
Benson Leung | d7e34d1 | 2013-01-09 16:25:11 -0800 | [diff] [blame] | 150 | |
Dudley Du | 9f1cd85 | 2015-01-17 18:35:26 -0800 | [diff] [blame] | 151 | if (i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) |
| 152 | ret |= CYAPA_ADAPTER_FUNC_I2C; |
| 153 | if (i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA | |
| 154 | I2C_FUNC_SMBUS_BLOCK_DATA | |
| 155 | I2C_FUNC_SMBUS_I2C_BLOCK)) |
| 156 | ret |= CYAPA_ADAPTER_FUNC_SMBUS; |
| 157 | return ret; |
Benson Leung | d7e34d1 | 2013-01-09 16:25:11 -0800 | [diff] [blame] | 158 | } |
| 159 | |
| 160 | /* |
| 161 | * Query device for its current operating state. |
Benson Leung | d7e34d1 | 2013-01-09 16:25:11 -0800 | [diff] [blame] | 162 | */ |
| 163 | static int cyapa_get_state(struct cyapa *cyapa) |
| 164 | { |
Benson Leung | d7e34d1 | 2013-01-09 16:25:11 -0800 | [diff] [blame] | 165 | u8 status[BL_STATUS_SIZE]; |
Dudley Du | 9f1cd85 | 2015-01-17 18:35:26 -0800 | [diff] [blame] | 166 | u8 cmd[32]; |
| 167 | /* The i2c address of gen4 and gen5 trackpad device must be even. */ |
| 168 | bool even_addr = ((cyapa->client->addr & 0x0001) == 0); |
| 169 | bool smbus = false; |
| 170 | int retries = 2; |
Dudley Du | 823a11f | 2014-12-04 07:00:03 -0800 | [diff] [blame] | 171 | int error; |
Benson Leung | d7e34d1 | 2013-01-09 16:25:11 -0800 | [diff] [blame] | 172 | |
| 173 | cyapa->state = CYAPA_STATE_NO_DEVICE; |
| 174 | |
| 175 | /* |
| 176 | * Get trackpad status by reading 3 registers starting from 0. |
| 177 | * If the device is in the bootloader, this will be BL_HEAD. |
| 178 | * If the device is in operation mode, this will be the DATA regs. |
| 179 | * |
| 180 | */ |
Dudley Du | 823a11f | 2014-12-04 07:00:03 -0800 | [diff] [blame] | 181 | error = cyapa_i2c_reg_read_block(cyapa, BL_HEAD_OFFSET, BL_STATUS_SIZE, |
Dudley Du | 9f1cd85 | 2015-01-17 18:35:26 -0800 | [diff] [blame] | 182 | status); |
Benson Leung | 6ddaf74 | 2013-02-13 13:56:03 -0800 | [diff] [blame] | 183 | |
| 184 | /* |
| 185 | * On smbus systems in OP mode, the i2c_reg_read will fail with |
| 186 | * -ETIMEDOUT. In this case, try again using the smbus equivalent |
| 187 | * command. This should return a BL_HEAD indicating CYAPA_STATE_OP. |
| 188 | */ |
Dudley Du | 9f1cd85 | 2015-01-17 18:35:26 -0800 | [diff] [blame] | 189 | if (cyapa->smbus && (error == -ETIMEDOUT || error == -ENXIO)) { |
| 190 | if (!even_addr) |
| 191 | error = cyapa_read_block(cyapa, |
| 192 | CYAPA_CMD_BL_STATUS, status); |
| 193 | smbus = true; |
| 194 | } |
Benson Leung | 6ddaf74 | 2013-02-13 13:56:03 -0800 | [diff] [blame] | 195 | |
Dudley Du | 823a11f | 2014-12-04 07:00:03 -0800 | [diff] [blame] | 196 | if (error != BL_STATUS_SIZE) |
Benson Leung | d7e34d1 | 2013-01-09 16:25:11 -0800 | [diff] [blame] | 197 | goto error; |
| 198 | |
Dudley Du | 9f1cd85 | 2015-01-17 18:35:26 -0800 | [diff] [blame] | 199 | /* |
| 200 | * Detect trackpad protocol based on characteristic registers and bits. |
| 201 | */ |
| 202 | do { |
| 203 | cyapa->status[REG_OP_STATUS] = status[REG_OP_STATUS]; |
| 204 | cyapa->status[REG_BL_STATUS] = status[REG_BL_STATUS]; |
| 205 | cyapa->status[REG_BL_ERROR] = status[REG_BL_ERROR]; |
Benson Leung | d7e34d1 | 2013-01-09 16:25:11 -0800 | [diff] [blame] | 206 | |
Dudley Du | 9f1cd85 | 2015-01-17 18:35:26 -0800 | [diff] [blame] | 207 | if (cyapa->gen == CYAPA_GEN_UNKNOWN || |
| 208 | cyapa->gen == CYAPA_GEN3) { |
| 209 | error = cyapa_gen3_ops.state_parse(cyapa, |
| 210 | status, BL_STATUS_SIZE); |
| 211 | if (!error) |
| 212 | goto out_detected; |
| 213 | } |
Dudley Du | c2c06c4 | 2015-07-20 16:53:30 -0700 | [diff] [blame] | 214 | if (cyapa->gen == CYAPA_GEN_UNKNOWN || |
| 215 | cyapa->gen == CYAPA_GEN6 || |
| 216 | cyapa->gen == CYAPA_GEN5) { |
| 217 | error = cyapa_pip_state_parse(cyapa, |
| 218 | status, BL_STATUS_SIZE); |
| 219 | if (!error) |
| 220 | goto out_detected; |
| 221 | } |
| 222 | /* For old Gen5 trackpads detecting. */ |
Dudley Du | 6972a85 | 2015-01-17 18:49:37 -0800 | [diff] [blame] | 223 | if ((cyapa->gen == CYAPA_GEN_UNKNOWN || |
| 224 | cyapa->gen == CYAPA_GEN5) && |
| 225 | !smbus && even_addr) { |
| 226 | error = cyapa_gen5_ops.state_parse(cyapa, |
| 227 | status, BL_STATUS_SIZE); |
| 228 | if (!error) |
| 229 | goto out_detected; |
| 230 | } |
Dudley Du | 9f1cd85 | 2015-01-17 18:35:26 -0800 | [diff] [blame] | 231 | |
| 232 | /* |
| 233 | * Write 0x00 0x00 to trackpad device to force update its |
| 234 | * status, then redo the detection again. |
| 235 | */ |
| 236 | if (!smbus) { |
| 237 | cmd[0] = 0x00; |
| 238 | cmd[1] = 0x00; |
| 239 | error = cyapa_i2c_write(cyapa, 0, 2, cmd); |
| 240 | if (error) |
| 241 | goto error; |
| 242 | |
| 243 | msleep(50); |
| 244 | |
| 245 | error = cyapa_i2c_read(cyapa, BL_HEAD_OFFSET, |
| 246 | BL_STATUS_SIZE, status); |
| 247 | if (error) |
| 248 | goto error; |
| 249 | } |
| 250 | } while (--retries > 0 && !smbus); |
| 251 | |
| 252 | goto error; |
| 253 | |
| 254 | out_detected: |
| 255 | if (cyapa->state <= CYAPA_STATE_BL_BUSY) |
| 256 | return -EAGAIN; |
Benson Leung | d7e34d1 | 2013-01-09 16:25:11 -0800 | [diff] [blame] | 257 | return 0; |
Dudley Du | 9f1cd85 | 2015-01-17 18:35:26 -0800 | [diff] [blame] | 258 | |
Benson Leung | d7e34d1 | 2013-01-09 16:25:11 -0800 | [diff] [blame] | 259 | error: |
Dudley Du | 823a11f | 2014-12-04 07:00:03 -0800 | [diff] [blame] | 260 | return (error < 0) ? error : -EAGAIN; |
Benson Leung | d7e34d1 | 2013-01-09 16:25:11 -0800 | [diff] [blame] | 261 | } |
| 262 | |
| 263 | /* |
| 264 | * Poll device for its status in a loop, waiting up to timeout for a response. |
| 265 | * |
| 266 | * When the device switches state, it usually takes ~300 ms. |
| 267 | * However, when running a new firmware image, the device must calibrate its |
| 268 | * sensors, which can take as long as 2 seconds. |
| 269 | * |
| 270 | * Note: The timeout has granularity of the polling rate, which is 100 ms. |
| 271 | * |
| 272 | * Returns: |
| 273 | * 0 when the device eventually responds with a valid non-busy state. |
| 274 | * -ETIMEDOUT if device never responds (too many -EAGAIN) |
Dudley Du | 9f1cd85 | 2015-01-17 18:35:26 -0800 | [diff] [blame] | 275 | * -EAGAIN if bootload is busy, or unknown state. |
| 276 | * < 0 other errors |
Benson Leung | d7e34d1 | 2013-01-09 16:25:11 -0800 | [diff] [blame] | 277 | */ |
Dudley Du | 9f1cd85 | 2015-01-17 18:35:26 -0800 | [diff] [blame] | 278 | int cyapa_poll_state(struct cyapa *cyapa, unsigned int timeout) |
Benson Leung | d7e34d1 | 2013-01-09 16:25:11 -0800 | [diff] [blame] | 279 | { |
Dudley Du | 823a11f | 2014-12-04 07:00:03 -0800 | [diff] [blame] | 280 | int error; |
Benson Leung | d7e34d1 | 2013-01-09 16:25:11 -0800 | [diff] [blame] | 281 | int tries = timeout / 100; |
| 282 | |
Dudley Du | 9f1cd85 | 2015-01-17 18:35:26 -0800 | [diff] [blame] | 283 | do { |
Dudley Du | 823a11f | 2014-12-04 07:00:03 -0800 | [diff] [blame] | 284 | error = cyapa_get_state(cyapa); |
Dudley Du | 9f1cd85 | 2015-01-17 18:35:26 -0800 | [diff] [blame] | 285 | if (!error && cyapa->state > CYAPA_STATE_BL_BUSY) |
| 286 | return 0; |
| 287 | |
| 288 | msleep(100); |
| 289 | } while (tries--); |
| 290 | |
Dudley Du | 823a11f | 2014-12-04 07:00:03 -0800 | [diff] [blame] | 291 | return (error == -EAGAIN || error == -ETIMEDOUT) ? -ETIMEDOUT : error; |
Benson Leung | d7e34d1 | 2013-01-09 16:25:11 -0800 | [diff] [blame] | 292 | } |
| 293 | |
Benson Leung | d7e34d1 | 2013-01-09 16:25:11 -0800 | [diff] [blame] | 294 | /* |
| 295 | * Check if device is operational. |
| 296 | * |
| 297 | * An operational device is responding, has exited bootloader, and has |
| 298 | * firmware supported by this driver. |
| 299 | * |
| 300 | * Returns: |
Dudley Du | 9f1cd85 | 2015-01-17 18:35:26 -0800 | [diff] [blame] | 301 | * -ENODEV no device |
Benson Leung | d7e34d1 | 2013-01-09 16:25:11 -0800 | [diff] [blame] | 302 | * -EBUSY no device or in bootloader |
| 303 | * -EIO failure while reading from device |
Dudley Du | 9f1cd85 | 2015-01-17 18:35:26 -0800 | [diff] [blame] | 304 | * -ETIMEDOUT timeout failure for bus idle or bus no response |
Benson Leung | d7e34d1 | 2013-01-09 16:25:11 -0800 | [diff] [blame] | 305 | * -EAGAIN device is still in bootloader |
| 306 | * if ->state = CYAPA_STATE_BL_IDLE, device has invalid firmware |
| 307 | * -EINVAL device is in operational mode, but not supported by this driver |
| 308 | * 0 device is supported |
| 309 | */ |
| 310 | static int cyapa_check_is_operational(struct cyapa *cyapa) |
| 311 | { |
Dudley Du | 823a11f | 2014-12-04 07:00:03 -0800 | [diff] [blame] | 312 | int error; |
Benson Leung | d7e34d1 | 2013-01-09 16:25:11 -0800 | [diff] [blame] | 313 | |
Dudley Du | 9f1cd85 | 2015-01-17 18:35:26 -0800 | [diff] [blame] | 314 | error = cyapa_poll_state(cyapa, 4000); |
Dudley Du | 823a11f | 2014-12-04 07:00:03 -0800 | [diff] [blame] | 315 | if (error) |
| 316 | return error; |
Benson Leung | d7e34d1 | 2013-01-09 16:25:11 -0800 | [diff] [blame] | 317 | |
Dudley Du | 9f1cd85 | 2015-01-17 18:35:26 -0800 | [diff] [blame] | 318 | switch (cyapa->gen) { |
Dudley Du | c2c06c4 | 2015-07-20 16:53:30 -0700 | [diff] [blame] | 319 | case CYAPA_GEN6: |
| 320 | cyapa->ops = &cyapa_gen6_ops; |
| 321 | break; |
Dudley Du | 6972a85 | 2015-01-17 18:49:37 -0800 | [diff] [blame] | 322 | case CYAPA_GEN5: |
| 323 | cyapa->ops = &cyapa_gen5_ops; |
| 324 | break; |
Dudley Du | 9f1cd85 | 2015-01-17 18:35:26 -0800 | [diff] [blame] | 325 | case CYAPA_GEN3: |
| 326 | cyapa->ops = &cyapa_gen3_ops; |
| 327 | break; |
Benson Leung | d7e34d1 | 2013-01-09 16:25:11 -0800 | [diff] [blame] | 328 | default: |
Dudley Du | 9f1cd85 | 2015-01-17 18:35:26 -0800 | [diff] [blame] | 329 | return -ENODEV; |
Benson Leung | d7e34d1 | 2013-01-09 16:25:11 -0800 | [diff] [blame] | 330 | } |
Dudley Du | 9f1cd85 | 2015-01-17 18:35:26 -0800 | [diff] [blame] | 331 | |
| 332 | error = cyapa->ops->operational_check(cyapa); |
| 333 | if (!error && cyapa_is_operational_mode(cyapa)) |
| 334 | cyapa->operational = true; |
| 335 | else |
| 336 | cyapa->operational = false; |
| 337 | |
| 338 | return error; |
Benson Leung | d7e34d1 | 2013-01-09 16:25:11 -0800 | [diff] [blame] | 339 | } |
| 340 | |
Dudley Du | 9f1cd85 | 2015-01-17 18:35:26 -0800 | [diff] [blame] | 341 | |
| 342 | /* |
| 343 | * Returns 0 on device detected, negative errno on no device detected. |
Dudley Du | 9489761 | 2015-07-20 16:49:06 -0700 | [diff] [blame] | 344 | * And when the device is detected and operational, it will be reset to |
Dudley Du | 9f1cd85 | 2015-01-17 18:35:26 -0800 | [diff] [blame] | 345 | * full power active mode automatically. |
| 346 | */ |
| 347 | static int cyapa_detect(struct cyapa *cyapa) |
Benson Leung | d7e34d1 | 2013-01-09 16:25:11 -0800 | [diff] [blame] | 348 | { |
Benson Leung | d7e34d1 | 2013-01-09 16:25:11 -0800 | [diff] [blame] | 349 | struct device *dev = &cyapa->client->dev; |
Dudley Du | 9f1cd85 | 2015-01-17 18:35:26 -0800 | [diff] [blame] | 350 | int error; |
Benson Leung | d7e34d1 | 2013-01-09 16:25:11 -0800 | [diff] [blame] | 351 | |
Dudley Du | 9f1cd85 | 2015-01-17 18:35:26 -0800 | [diff] [blame] | 352 | error = cyapa_check_is_operational(cyapa); |
| 353 | if (error) { |
| 354 | if (error != -ETIMEDOUT && error != -ENODEV && |
| 355 | cyapa_is_bootloader_mode(cyapa)) { |
| 356 | dev_warn(dev, "device detected but not operational\n"); |
| 357 | return 0; |
| 358 | } |
Benson Leung | d7e34d1 | 2013-01-09 16:25:11 -0800 | [diff] [blame] | 359 | |
Dudley Du | 9f1cd85 | 2015-01-17 18:35:26 -0800 | [diff] [blame] | 360 | dev_err(dev, "no device detected: %d\n", error); |
| 361 | return error; |
Benson Leung | d7e34d1 | 2013-01-09 16:25:11 -0800 | [diff] [blame] | 362 | } |
| 363 | |
Dudley Du | 9f1cd85 | 2015-01-17 18:35:26 -0800 | [diff] [blame] | 364 | return 0; |
Benson Leung | 6ddaf74 | 2013-02-13 13:56:03 -0800 | [diff] [blame] | 365 | } |
| 366 | |
Dudley Du | b1cfa7b | 2014-11-09 12:36:34 -0800 | [diff] [blame] | 367 | static int cyapa_open(struct input_dev *input) |
| 368 | { |
| 369 | struct cyapa *cyapa = input_get_drvdata(input); |
| 370 | struct i2c_client *client = cyapa->client; |
Dudley Du | 757cae5 | 2015-07-20 17:09:59 -0700 | [diff] [blame] | 371 | struct device *dev = &client->dev; |
Dudley Du | b1cfa7b | 2014-11-09 12:36:34 -0800 | [diff] [blame] | 372 | int error; |
| 373 | |
Dudley Du | 9f1cd85 | 2015-01-17 18:35:26 -0800 | [diff] [blame] | 374 | error = mutex_lock_interruptible(&cyapa->state_sync_lock); |
| 375 | if (error) |
Dudley Du | b1cfa7b | 2014-11-09 12:36:34 -0800 | [diff] [blame] | 376 | return error; |
Dudley Du | 9f1cd85 | 2015-01-17 18:35:26 -0800 | [diff] [blame] | 377 | |
| 378 | if (cyapa->operational) { |
| 379 | /* |
| 380 | * though failed to set active power mode, |
| 381 | * but still may be able to work in lower scan rate |
| 382 | * when in operational mode. |
| 383 | */ |
| 384 | error = cyapa->ops->set_power_mode(cyapa, |
Dudley Du | 757cae5 | 2015-07-20 17:09:59 -0700 | [diff] [blame] | 385 | PWR_MODE_FULL_ACTIVE, 0, false); |
Dudley Du | 9f1cd85 | 2015-01-17 18:35:26 -0800 | [diff] [blame] | 386 | if (error) { |
Dudley Du | 757cae5 | 2015-07-20 17:09:59 -0700 | [diff] [blame] | 387 | dev_warn(dev, "set active power failed: %d\n", error); |
Dudley Du | 9f1cd85 | 2015-01-17 18:35:26 -0800 | [diff] [blame] | 388 | goto out; |
| 389 | } |
| 390 | } else { |
| 391 | error = cyapa_reinitialize(cyapa); |
| 392 | if (error || !cyapa->operational) { |
| 393 | error = error ? error : -EAGAIN; |
| 394 | goto out; |
| 395 | } |
Dudley Du | b1cfa7b | 2014-11-09 12:36:34 -0800 | [diff] [blame] | 396 | } |
| 397 | |
| 398 | enable_irq(client->irq); |
Dudley Du | 757cae5 | 2015-07-20 17:09:59 -0700 | [diff] [blame] | 399 | if (!pm_runtime_enabled(dev)) { |
| 400 | pm_runtime_set_active(dev); |
| 401 | pm_runtime_enable(dev); |
Dudley Du | 6728650 | 2015-01-17 18:57:42 -0800 | [diff] [blame] | 402 | } |
Dudley Du | 757cae5 | 2015-07-20 17:09:59 -0700 | [diff] [blame] | 403 | |
| 404 | pm_runtime_get_sync(dev); |
| 405 | pm_runtime_mark_last_busy(dev); |
| 406 | pm_runtime_put_sync_autosuspend(dev); |
Dudley Du | 9f1cd85 | 2015-01-17 18:35:26 -0800 | [diff] [blame] | 407 | out: |
| 408 | mutex_unlock(&cyapa->state_sync_lock); |
| 409 | return error; |
Dudley Du | b1cfa7b | 2014-11-09 12:36:34 -0800 | [diff] [blame] | 410 | } |
| 411 | |
| 412 | static void cyapa_close(struct input_dev *input) |
| 413 | { |
| 414 | struct cyapa *cyapa = input_get_drvdata(input); |
Dudley Du | 9f1cd85 | 2015-01-17 18:35:26 -0800 | [diff] [blame] | 415 | struct i2c_client *client = cyapa->client; |
Dudley Du | 757cae5 | 2015-07-20 17:09:59 -0700 | [diff] [blame] | 416 | struct device *dev = &cyapa->client->dev; |
Dudley Du | b1cfa7b | 2014-11-09 12:36:34 -0800 | [diff] [blame] | 417 | |
Dudley Du | 9f1cd85 | 2015-01-17 18:35:26 -0800 | [diff] [blame] | 418 | mutex_lock(&cyapa->state_sync_lock); |
| 419 | |
| 420 | disable_irq(client->irq); |
Dudley Du | 757cae5 | 2015-07-20 17:09:59 -0700 | [diff] [blame] | 421 | if (pm_runtime_enabled(dev)) |
| 422 | pm_runtime_disable(dev); |
| 423 | pm_runtime_set_suspended(dev); |
Dudley Du | 6728650 | 2015-01-17 18:57:42 -0800 | [diff] [blame] | 424 | |
Dudley Du | 9f1cd85 | 2015-01-17 18:35:26 -0800 | [diff] [blame] | 425 | if (cyapa->operational) |
Dudley Du | 757cae5 | 2015-07-20 17:09:59 -0700 | [diff] [blame] | 426 | cyapa->ops->set_power_mode(cyapa, PWR_MODE_OFF, 0, false); |
Dudley Du | 9f1cd85 | 2015-01-17 18:35:26 -0800 | [diff] [blame] | 427 | |
| 428 | mutex_unlock(&cyapa->state_sync_lock); |
Dudley Du | b1cfa7b | 2014-11-09 12:36:34 -0800 | [diff] [blame] | 429 | } |
| 430 | |
Benson Leung | d7e34d1 | 2013-01-09 16:25:11 -0800 | [diff] [blame] | 431 | static int cyapa_create_input_dev(struct cyapa *cyapa) |
| 432 | { |
| 433 | struct device *dev = &cyapa->client->dev; |
Benson Leung | d7e34d1 | 2013-01-09 16:25:11 -0800 | [diff] [blame] | 434 | struct input_dev *input; |
Dudley Du | b1cfa7b | 2014-11-09 12:36:34 -0800 | [diff] [blame] | 435 | int error; |
Benson Leung | d7e34d1 | 2013-01-09 16:25:11 -0800 | [diff] [blame] | 436 | |
| 437 | if (!cyapa->physical_size_x || !cyapa->physical_size_y) |
| 438 | return -EINVAL; |
| 439 | |
Dudley Du | b1cfa7b | 2014-11-09 12:36:34 -0800 | [diff] [blame] | 440 | input = devm_input_allocate_device(dev); |
Benson Leung | d7e34d1 | 2013-01-09 16:25:11 -0800 | [diff] [blame] | 441 | if (!input) { |
Dudley Du | 823a11f | 2014-12-04 07:00:03 -0800 | [diff] [blame] | 442 | dev_err(dev, "failed to allocate memory for input device.\n"); |
Benson Leung | d7e34d1 | 2013-01-09 16:25:11 -0800 | [diff] [blame] | 443 | return -ENOMEM; |
| 444 | } |
| 445 | |
| 446 | input->name = CYAPA_NAME; |
| 447 | input->phys = cyapa->phys; |
| 448 | input->id.bustype = BUS_I2C; |
| 449 | input->id.version = 1; |
Dudley Du | 823a11f | 2014-12-04 07:00:03 -0800 | [diff] [blame] | 450 | input->id.product = 0; /* Means any product in eventcomm. */ |
Benson Leung | d7e34d1 | 2013-01-09 16:25:11 -0800 | [diff] [blame] | 451 | input->dev.parent = &cyapa->client->dev; |
| 452 | |
Dudley Du | b1cfa7b | 2014-11-09 12:36:34 -0800 | [diff] [blame] | 453 | input->open = cyapa_open; |
| 454 | input->close = cyapa_close; |
| 455 | |
Benson Leung | d7e34d1 | 2013-01-09 16:25:11 -0800 | [diff] [blame] | 456 | input_set_drvdata(input, cyapa); |
| 457 | |
| 458 | __set_bit(EV_ABS, input->evbit); |
| 459 | |
Dudley Du | 823a11f | 2014-12-04 07:00:03 -0800 | [diff] [blame] | 460 | /* Finger position */ |
Benson Leung | d7e34d1 | 2013-01-09 16:25:11 -0800 | [diff] [blame] | 461 | input_set_abs_params(input, ABS_MT_POSITION_X, 0, cyapa->max_abs_x, 0, |
| 462 | 0); |
| 463 | input_set_abs_params(input, ABS_MT_POSITION_Y, 0, cyapa->max_abs_y, 0, |
| 464 | 0); |
Dudley Du | 9f1cd85 | 2015-01-17 18:35:26 -0800 | [diff] [blame] | 465 | input_set_abs_params(input, ABS_MT_PRESSURE, 0, cyapa->max_z, 0, 0); |
| 466 | if (cyapa->gen > CYAPA_GEN3) { |
| 467 | input_set_abs_params(input, ABS_MT_TOUCH_MAJOR, 0, 255, 0, 0); |
| 468 | input_set_abs_params(input, ABS_MT_TOUCH_MINOR, 0, 255, 0, 0); |
| 469 | /* |
| 470 | * Orientation is the angle between the vertical axis and |
| 471 | * the major axis of the contact ellipse. |
| 472 | * The range is -127 to 127. |
| 473 | * the positive direction is clockwise form the vertical axis. |
| 474 | * If the ellipse of contact degenerates into a circle, |
| 475 | * orientation is reported as 0. |
| 476 | * |
| 477 | * Also, for Gen5 trackpad the accurate of this orientation |
| 478 | * value is value + (-30 ~ 30). |
| 479 | */ |
| 480 | input_set_abs_params(input, ABS_MT_ORIENTATION, |
| 481 | -127, 127, 0, 0); |
| 482 | } |
| 483 | if (cyapa->gen >= CYAPA_GEN5) { |
| 484 | input_set_abs_params(input, ABS_MT_WIDTH_MAJOR, 0, 255, 0, 0); |
| 485 | input_set_abs_params(input, ABS_MT_WIDTH_MINOR, 0, 255, 0, 0); |
Dudley Du | 945525e | 2015-07-20 16:57:53 -0700 | [diff] [blame] | 486 | input_set_abs_params(input, ABS_DISTANCE, 0, 1, 0, 0); |
Dudley Du | 9f1cd85 | 2015-01-17 18:35:26 -0800 | [diff] [blame] | 487 | } |
Benson Leung | d7e34d1 | 2013-01-09 16:25:11 -0800 | [diff] [blame] | 488 | |
| 489 | input_abs_set_res(input, ABS_MT_POSITION_X, |
| 490 | cyapa->max_abs_x / cyapa->physical_size_x); |
| 491 | input_abs_set_res(input, ABS_MT_POSITION_Y, |
| 492 | cyapa->max_abs_y / cyapa->physical_size_y); |
| 493 | |
| 494 | if (cyapa->btn_capability & CAPABILITY_LEFT_BTN_MASK) |
| 495 | __set_bit(BTN_LEFT, input->keybit); |
| 496 | if (cyapa->btn_capability & CAPABILITY_MIDDLE_BTN_MASK) |
| 497 | __set_bit(BTN_MIDDLE, input->keybit); |
| 498 | if (cyapa->btn_capability & CAPABILITY_RIGHT_BTN_MASK) |
| 499 | __set_bit(BTN_RIGHT, input->keybit); |
| 500 | |
| 501 | if (cyapa->btn_capability == CAPABILITY_LEFT_BTN_MASK) |
| 502 | __set_bit(INPUT_PROP_BUTTONPAD, input->propbit); |
| 503 | |
Dudley Du | 823a11f | 2014-12-04 07:00:03 -0800 | [diff] [blame] | 504 | /* Handle pointer emulation and unused slots in core */ |
Dudley Du | b1cfa7b | 2014-11-09 12:36:34 -0800 | [diff] [blame] | 505 | error = input_mt_init_slots(input, CYAPA_MAX_MT_SLOTS, |
| 506 | INPUT_MT_POINTER | INPUT_MT_DROP_UNUSED); |
| 507 | if (error) { |
| 508 | dev_err(dev, "failed to initialize MT slots: %d\n", error); |
| 509 | return error; |
Benson Leung | d7e34d1 | 2013-01-09 16:25:11 -0800 | [diff] [blame] | 510 | } |
| 511 | |
Dudley Du | 9f1cd85 | 2015-01-17 18:35:26 -0800 | [diff] [blame] | 512 | /* Register the device in input subsystem */ |
| 513 | error = input_register_device(input); |
| 514 | if (error) { |
| 515 | dev_err(dev, "failed to register input device: %d\n", error); |
| 516 | return error; |
| 517 | } |
| 518 | |
Dudley Du | b1cfa7b | 2014-11-09 12:36:34 -0800 | [diff] [blame] | 519 | cyapa->input = input; |
Benson Leung | d7e34d1 | 2013-01-09 16:25:11 -0800 | [diff] [blame] | 520 | return 0; |
Benson Leung | d7e34d1 | 2013-01-09 16:25:11 -0800 | [diff] [blame] | 521 | } |
| 522 | |
Dudley Du | c806b0b | 2015-01-17 22:07:12 -0800 | [diff] [blame] | 523 | static void cyapa_enable_irq_for_cmd(struct cyapa *cyapa) |
| 524 | { |
| 525 | struct input_dev *input = cyapa->input; |
| 526 | |
| 527 | if (!input || !input->users) { |
| 528 | /* |
| 529 | * When input is NULL, TP must be in deep sleep mode. |
| 530 | * In this mode, later non-power I2C command will always failed |
| 531 | * if not bring it out of deep sleep mode firstly, |
| 532 | * so must command TP to active mode here. |
| 533 | */ |
| 534 | if (!input || cyapa->operational) |
| 535 | cyapa->ops->set_power_mode(cyapa, |
Dudley Du | 757cae5 | 2015-07-20 17:09:59 -0700 | [diff] [blame] | 536 | PWR_MODE_FULL_ACTIVE, 0, false); |
Dudley Du | c806b0b | 2015-01-17 22:07:12 -0800 | [diff] [blame] | 537 | /* Gen3 always using polling mode for command. */ |
| 538 | if (cyapa->gen >= CYAPA_GEN5) |
| 539 | enable_irq(cyapa->client->irq); |
| 540 | } |
| 541 | } |
| 542 | |
| 543 | static void cyapa_disable_irq_for_cmd(struct cyapa *cyapa) |
| 544 | { |
| 545 | struct input_dev *input = cyapa->input; |
| 546 | |
| 547 | if (!input || !input->users) { |
| 548 | if (cyapa->gen >= CYAPA_GEN5) |
| 549 | disable_irq(cyapa->client->irq); |
| 550 | if (!input || cyapa->operational) |
Dudley Du | 757cae5 | 2015-07-20 17:09:59 -0700 | [diff] [blame] | 551 | cyapa->ops->set_power_mode(cyapa, |
| 552 | PWR_MODE_OFF, 0, false); |
Dudley Du | c806b0b | 2015-01-17 22:07:12 -0800 | [diff] [blame] | 553 | } |
| 554 | } |
| 555 | |
Dudley Du | 9f1cd85 | 2015-01-17 18:35:26 -0800 | [diff] [blame] | 556 | /* |
| 557 | * cyapa_sleep_time_to_pwr_cmd and cyapa_pwr_cmd_to_sleep_time |
| 558 | * |
| 559 | * These are helper functions that convert to and from integer idle |
| 560 | * times and register settings to write to the PowerMode register. |
| 561 | * The trackpad supports between 20ms to 1000ms scan intervals. |
| 562 | * The time will be increased in increments of 10ms from 20ms to 100ms. |
| 563 | * From 100ms to 1000ms, time will be increased in increments of 20ms. |
| 564 | * |
| 565 | * When Idle_Time < 100, the format to convert Idle_Time to Idle_Command is: |
| 566 | * Idle_Command = Idle Time / 10; |
| 567 | * When Idle_Time >= 100, the format to convert Idle_Time to Idle_Command is: |
| 568 | * Idle_Command = Idle Time / 20 + 5; |
| 569 | */ |
| 570 | u8 cyapa_sleep_time_to_pwr_cmd(u16 sleep_time) |
| 571 | { |
| 572 | u16 encoded_time; |
| 573 | |
| 574 | sleep_time = clamp_val(sleep_time, 20, 1000); |
| 575 | encoded_time = sleep_time < 100 ? sleep_time / 10 : sleep_time / 20 + 5; |
| 576 | return (encoded_time << 2) & PWR_MODE_MASK; |
| 577 | } |
| 578 | |
| 579 | u16 cyapa_pwr_cmd_to_sleep_time(u8 pwr_mode) |
| 580 | { |
| 581 | u8 encoded_time = pwr_mode >> 2; |
| 582 | |
| 583 | return (encoded_time < 10) ? encoded_time * 10 |
| 584 | : (encoded_time - 5) * 20; |
| 585 | } |
| 586 | |
| 587 | /* 0 on driver initialize and detected successfully, negative on failure. */ |
| 588 | static int cyapa_initialize(struct cyapa *cyapa) |
| 589 | { |
| 590 | int error = 0; |
| 591 | |
| 592 | cyapa->state = CYAPA_STATE_NO_DEVICE; |
| 593 | cyapa->gen = CYAPA_GEN_UNKNOWN; |
| 594 | mutex_init(&cyapa->state_sync_lock); |
| 595 | |
| 596 | /* |
| 597 | * Set to hard code default, they will be updated with trackpad set |
| 598 | * default values after probe and initialized. |
| 599 | */ |
| 600 | cyapa->suspend_power_mode = PWR_MODE_SLEEP; |
| 601 | cyapa->suspend_sleep_time = |
| 602 | cyapa_pwr_cmd_to_sleep_time(cyapa->suspend_power_mode); |
| 603 | |
| 604 | /* ops.initialize() is aimed to prepare for module communications. */ |
| 605 | error = cyapa_gen3_ops.initialize(cyapa); |
Dudley Du | 6972a85 | 2015-01-17 18:49:37 -0800 | [diff] [blame] | 606 | if (!error) |
| 607 | error = cyapa_gen5_ops.initialize(cyapa); |
Dudley Du | c2c06c4 | 2015-07-20 16:53:30 -0700 | [diff] [blame] | 608 | if (!error) |
| 609 | error = cyapa_gen6_ops.initialize(cyapa); |
Dudley Du | 9f1cd85 | 2015-01-17 18:35:26 -0800 | [diff] [blame] | 610 | if (error) |
| 611 | return error; |
| 612 | |
| 613 | error = cyapa_detect(cyapa); |
| 614 | if (error) |
| 615 | return error; |
| 616 | |
| 617 | /* Power down the device until we need it. */ |
| 618 | if (cyapa->operational) |
Dudley Du | 757cae5 | 2015-07-20 17:09:59 -0700 | [diff] [blame] | 619 | cyapa->ops->set_power_mode(cyapa, PWR_MODE_OFF, 0, false); |
Dudley Du | 9f1cd85 | 2015-01-17 18:35:26 -0800 | [diff] [blame] | 620 | |
| 621 | return 0; |
| 622 | } |
| 623 | |
| 624 | static int cyapa_reinitialize(struct cyapa *cyapa) |
| 625 | { |
| 626 | struct device *dev = &cyapa->client->dev; |
| 627 | struct input_dev *input = cyapa->input; |
| 628 | int error; |
| 629 | |
Dudley Du | 6728650 | 2015-01-17 18:57:42 -0800 | [diff] [blame] | 630 | if (pm_runtime_enabled(dev)) |
| 631 | pm_runtime_disable(dev); |
| 632 | |
Dudley Du | 9f1cd85 | 2015-01-17 18:35:26 -0800 | [diff] [blame] | 633 | /* Avoid command failures when TP was in OFF state. */ |
| 634 | if (cyapa->operational) |
Dudley Du | 757cae5 | 2015-07-20 17:09:59 -0700 | [diff] [blame] | 635 | cyapa->ops->set_power_mode(cyapa, |
| 636 | PWR_MODE_FULL_ACTIVE, 0, false); |
Dudley Du | 9f1cd85 | 2015-01-17 18:35:26 -0800 | [diff] [blame] | 637 | |
| 638 | error = cyapa_detect(cyapa); |
| 639 | if (error) |
| 640 | goto out; |
| 641 | |
| 642 | if (!input && cyapa->operational) { |
| 643 | error = cyapa_create_input_dev(cyapa); |
| 644 | if (error) { |
| 645 | dev_err(dev, "create input_dev instance failed: %d\n", |
| 646 | error); |
| 647 | goto out; |
| 648 | } |
| 649 | } |
| 650 | |
| 651 | out: |
| 652 | if (!input || !input->users) { |
| 653 | /* Reset to power OFF state to save power when no user open. */ |
| 654 | if (cyapa->operational) |
Dudley Du | 757cae5 | 2015-07-20 17:09:59 -0700 | [diff] [blame] | 655 | cyapa->ops->set_power_mode(cyapa, |
| 656 | PWR_MODE_OFF, 0, false); |
Dudley Du | 6728650 | 2015-01-17 18:57:42 -0800 | [diff] [blame] | 657 | } else if (!error && cyapa->operational) { |
| 658 | /* |
| 659 | * Make sure only enable runtime PM when device is |
| 660 | * in operational mode and input->users > 0. |
| 661 | */ |
| 662 | pm_runtime_set_active(dev); |
| 663 | pm_runtime_enable(dev); |
Dudley Du | 757cae5 | 2015-07-20 17:09:59 -0700 | [diff] [blame] | 664 | |
| 665 | pm_runtime_get_sync(dev); |
| 666 | pm_runtime_mark_last_busy(dev); |
| 667 | pm_runtime_put_sync_autosuspend(dev); |
Dudley Du | 9f1cd85 | 2015-01-17 18:35:26 -0800 | [diff] [blame] | 668 | } |
| 669 | |
| 670 | return error; |
| 671 | } |
| 672 | |
| 673 | static irqreturn_t cyapa_irq(int irq, void *dev_id) |
| 674 | { |
| 675 | struct cyapa *cyapa = dev_id; |
| 676 | struct device *dev = &cyapa->client->dev; |
Dudley Du | 757cae5 | 2015-07-20 17:09:59 -0700 | [diff] [blame] | 677 | int error; |
Dudley Du | 9f1cd85 | 2015-01-17 18:35:26 -0800 | [diff] [blame] | 678 | |
| 679 | if (device_may_wakeup(dev)) |
| 680 | pm_wakeup_event(dev, 0); |
| 681 | |
Dudley Du | 9489761 | 2015-07-20 16:49:06 -0700 | [diff] [blame] | 682 | /* Interrupt event can be caused by host command to trackpad device. */ |
Dudley Du | 9f1cd85 | 2015-01-17 18:35:26 -0800 | [diff] [blame] | 683 | if (cyapa->ops->irq_cmd_handler(cyapa)) { |
| 684 | /* |
| 685 | * Interrupt event maybe from trackpad device input reporting. |
| 686 | */ |
| 687 | if (!cyapa->input) { |
| 688 | /* |
Dudley Du | 9489761 | 2015-07-20 16:49:06 -0700 | [diff] [blame] | 689 | * Still in probing or in firmware image |
| 690 | * updating or reading. |
Dudley Du | 9f1cd85 | 2015-01-17 18:35:26 -0800 | [diff] [blame] | 691 | */ |
| 692 | cyapa->ops->sort_empty_output_data(cyapa, |
| 693 | NULL, NULL, NULL); |
| 694 | goto out; |
| 695 | } |
| 696 | |
Dudley Du | 757cae5 | 2015-07-20 17:09:59 -0700 | [diff] [blame] | 697 | if (cyapa->operational) { |
| 698 | error = cyapa->ops->irq_handler(cyapa); |
| 699 | |
| 700 | /* |
| 701 | * Apply runtime power management to touch report event |
| 702 | * except the events caused by the command responses. |
| 703 | * Note: |
| 704 | * It will introduce about 20~40 ms additional delay |
| 705 | * time in receiving for first valid touch report data. |
| 706 | * The time is used to execute device runtime resume |
| 707 | * process. |
| 708 | */ |
| 709 | pm_runtime_get_sync(dev); |
| 710 | pm_runtime_mark_last_busy(dev); |
| 711 | pm_runtime_put_sync_autosuspend(dev); |
| 712 | } |
| 713 | |
| 714 | if (!cyapa->operational || error) { |
Dudley Du | 9f1cd85 | 2015-01-17 18:35:26 -0800 | [diff] [blame] | 715 | if (!mutex_trylock(&cyapa->state_sync_lock)) { |
| 716 | cyapa->ops->sort_empty_output_data(cyapa, |
| 717 | NULL, NULL, NULL); |
| 718 | goto out; |
| 719 | } |
| 720 | cyapa_reinitialize(cyapa); |
| 721 | mutex_unlock(&cyapa->state_sync_lock); |
| 722 | } |
| 723 | } |
| 724 | |
| 725 | out: |
| 726 | return IRQ_HANDLED; |
| 727 | } |
| 728 | |
Dudley Du | 22e7db8 | 2015-01-17 18:56:18 -0800 | [diff] [blame] | 729 | /* |
| 730 | ************************************************************** |
| 731 | * sysfs interface |
| 732 | ************************************************************** |
| 733 | */ |
| 734 | #ifdef CONFIG_PM_SLEEP |
| 735 | static ssize_t cyapa_show_suspend_scanrate(struct device *dev, |
| 736 | struct device_attribute *attr, |
| 737 | char *buf) |
| 738 | { |
| 739 | struct cyapa *cyapa = dev_get_drvdata(dev); |
| 740 | u8 pwr_cmd = cyapa->suspend_power_mode; |
| 741 | u16 sleep_time; |
| 742 | int len; |
| 743 | int error; |
| 744 | |
| 745 | error = mutex_lock_interruptible(&cyapa->state_sync_lock); |
| 746 | if (error) |
| 747 | return error; |
| 748 | |
| 749 | pwr_cmd = cyapa->suspend_power_mode; |
| 750 | sleep_time = cyapa->suspend_sleep_time; |
| 751 | |
| 752 | mutex_unlock(&cyapa->state_sync_lock); |
| 753 | |
| 754 | switch (pwr_cmd) { |
| 755 | case PWR_MODE_BTN_ONLY: |
| 756 | len = scnprintf(buf, PAGE_SIZE, "%s\n", BTN_ONLY_MODE_NAME); |
| 757 | break; |
| 758 | |
| 759 | case PWR_MODE_OFF: |
| 760 | len = scnprintf(buf, PAGE_SIZE, "%s\n", OFF_MODE_NAME); |
| 761 | break; |
| 762 | |
| 763 | default: |
| 764 | len = scnprintf(buf, PAGE_SIZE, "%u\n", |
| 765 | cyapa->gen == CYAPA_GEN3 ? |
| 766 | cyapa_pwr_cmd_to_sleep_time(pwr_cmd) : |
| 767 | sleep_time); |
| 768 | break; |
| 769 | } |
| 770 | |
| 771 | return len; |
| 772 | } |
| 773 | |
| 774 | static ssize_t cyapa_update_suspend_scanrate(struct device *dev, |
| 775 | struct device_attribute *attr, |
| 776 | const char *buf, size_t count) |
| 777 | { |
| 778 | struct cyapa *cyapa = dev_get_drvdata(dev); |
| 779 | u16 sleep_time; |
| 780 | int error; |
| 781 | |
| 782 | error = mutex_lock_interruptible(&cyapa->state_sync_lock); |
| 783 | if (error) |
| 784 | return error; |
| 785 | |
| 786 | if (sysfs_streq(buf, BTN_ONLY_MODE_NAME)) { |
| 787 | cyapa->suspend_power_mode = PWR_MODE_BTN_ONLY; |
| 788 | } else if (sysfs_streq(buf, OFF_MODE_NAME)) { |
| 789 | cyapa->suspend_power_mode = PWR_MODE_OFF; |
| 790 | } else if (!kstrtou16(buf, 10, &sleep_time)) { |
Dudley Du | a333a03 | 2015-04-20 10:00:05 -0700 | [diff] [blame] | 791 | cyapa->suspend_sleep_time = min_t(u16, sleep_time, 1000); |
Dudley Du | 22e7db8 | 2015-01-17 18:56:18 -0800 | [diff] [blame] | 792 | cyapa->suspend_power_mode = |
| 793 | cyapa_sleep_time_to_pwr_cmd(cyapa->suspend_sleep_time); |
| 794 | } else { |
| 795 | count = -EINVAL; |
| 796 | } |
| 797 | |
| 798 | mutex_unlock(&cyapa->state_sync_lock); |
| 799 | |
| 800 | return count; |
| 801 | } |
| 802 | |
| 803 | static DEVICE_ATTR(suspend_scanrate_ms, S_IRUGO|S_IWUSR, |
| 804 | cyapa_show_suspend_scanrate, |
| 805 | cyapa_update_suspend_scanrate); |
| 806 | |
| 807 | static struct attribute *cyapa_power_wakeup_entries[] = { |
| 808 | &dev_attr_suspend_scanrate_ms.attr, |
| 809 | NULL, |
| 810 | }; |
| 811 | |
| 812 | static const struct attribute_group cyapa_power_wakeup_group = { |
| 813 | .name = power_group_name, |
| 814 | .attrs = cyapa_power_wakeup_entries, |
| 815 | }; |
| 816 | |
| 817 | static void cyapa_remove_power_wakeup_group(void *data) |
| 818 | { |
| 819 | struct cyapa *cyapa = data; |
| 820 | |
| 821 | sysfs_unmerge_group(&cyapa->client->dev.kobj, |
| 822 | &cyapa_power_wakeup_group); |
| 823 | } |
| 824 | |
| 825 | static int cyapa_prepare_wakeup_controls(struct cyapa *cyapa) |
| 826 | { |
| 827 | struct i2c_client *client = cyapa->client; |
| 828 | struct device *dev = &client->dev; |
| 829 | int error; |
| 830 | |
| 831 | if (device_can_wakeup(dev)) { |
| 832 | error = sysfs_merge_group(&client->dev.kobj, |
| 833 | &cyapa_power_wakeup_group); |
| 834 | if (error) { |
| 835 | dev_err(dev, "failed to add power wakeup group: %d\n", |
| 836 | error); |
| 837 | return error; |
| 838 | } |
| 839 | |
| 840 | error = devm_add_action(dev, |
| 841 | cyapa_remove_power_wakeup_group, cyapa); |
| 842 | if (error) { |
| 843 | cyapa_remove_power_wakeup_group(cyapa); |
| 844 | dev_err(dev, "failed to add power cleanup action: %d\n", |
| 845 | error); |
| 846 | return error; |
| 847 | } |
| 848 | } |
| 849 | |
| 850 | return 0; |
| 851 | } |
| 852 | #else |
| 853 | static inline int cyapa_prepare_wakeup_controls(struct cyapa *cyapa) |
| 854 | { |
| 855 | return 0; |
| 856 | } |
| 857 | #endif /* CONFIG_PM_SLEEP */ |
| 858 | |
Dudley Du | 6728650 | 2015-01-17 18:57:42 -0800 | [diff] [blame] | 859 | #ifdef CONFIG_PM |
| 860 | static ssize_t cyapa_show_rt_suspend_scanrate(struct device *dev, |
| 861 | struct device_attribute *attr, |
| 862 | char *buf) |
| 863 | { |
| 864 | struct cyapa *cyapa = dev_get_drvdata(dev); |
| 865 | u8 pwr_cmd; |
| 866 | u16 sleep_time; |
| 867 | int error; |
| 868 | |
| 869 | error = mutex_lock_interruptible(&cyapa->state_sync_lock); |
| 870 | if (error) |
| 871 | return error; |
| 872 | |
| 873 | pwr_cmd = cyapa->runtime_suspend_power_mode; |
| 874 | sleep_time = cyapa->runtime_suspend_sleep_time; |
| 875 | |
| 876 | mutex_unlock(&cyapa->state_sync_lock); |
| 877 | |
| 878 | return scnprintf(buf, PAGE_SIZE, "%u\n", |
| 879 | cyapa->gen == CYAPA_GEN3 ? |
| 880 | cyapa_pwr_cmd_to_sleep_time(pwr_cmd) : |
| 881 | sleep_time); |
| 882 | } |
| 883 | |
| 884 | static ssize_t cyapa_update_rt_suspend_scanrate(struct device *dev, |
| 885 | struct device_attribute *attr, |
| 886 | const char *buf, size_t count) |
| 887 | { |
| 888 | struct cyapa *cyapa = dev_get_drvdata(dev); |
| 889 | u16 time; |
| 890 | int error; |
| 891 | |
| 892 | if (buf == NULL || count == 0 || kstrtou16(buf, 10, &time)) { |
| 893 | dev_err(dev, "invalid runtime suspend scanrate ms parameter\n"); |
| 894 | return -EINVAL; |
| 895 | } |
| 896 | |
| 897 | /* |
| 898 | * When the suspend scanrate is changed, pm_runtime_get to resume |
| 899 | * a potentially suspended device, update to the new pwr_cmd |
| 900 | * and then pm_runtime_put to suspend into the new power mode. |
| 901 | */ |
| 902 | pm_runtime_get_sync(dev); |
| 903 | |
| 904 | error = mutex_lock_interruptible(&cyapa->state_sync_lock); |
| 905 | if (error) |
| 906 | return error; |
| 907 | |
Dudley Du | a333a03 | 2015-04-20 10:00:05 -0700 | [diff] [blame] | 908 | cyapa->runtime_suspend_sleep_time = min_t(u16, time, 1000); |
Dudley Du | 6728650 | 2015-01-17 18:57:42 -0800 | [diff] [blame] | 909 | cyapa->runtime_suspend_power_mode = |
| 910 | cyapa_sleep_time_to_pwr_cmd(cyapa->runtime_suspend_sleep_time); |
| 911 | |
| 912 | mutex_unlock(&cyapa->state_sync_lock); |
| 913 | |
| 914 | pm_runtime_put_sync_autosuspend(dev); |
| 915 | |
| 916 | return count; |
| 917 | } |
| 918 | |
| 919 | static DEVICE_ATTR(runtime_suspend_scanrate_ms, S_IRUGO|S_IWUSR, |
| 920 | cyapa_show_rt_suspend_scanrate, |
| 921 | cyapa_update_rt_suspend_scanrate); |
| 922 | |
| 923 | static struct attribute *cyapa_power_runtime_entries[] = { |
| 924 | &dev_attr_runtime_suspend_scanrate_ms.attr, |
| 925 | NULL, |
| 926 | }; |
| 927 | |
| 928 | static const struct attribute_group cyapa_power_runtime_group = { |
| 929 | .name = power_group_name, |
| 930 | .attrs = cyapa_power_runtime_entries, |
| 931 | }; |
| 932 | |
| 933 | static void cyapa_remove_power_runtime_group(void *data) |
| 934 | { |
| 935 | struct cyapa *cyapa = data; |
| 936 | |
| 937 | sysfs_unmerge_group(&cyapa->client->dev.kobj, |
| 938 | &cyapa_power_runtime_group); |
| 939 | } |
| 940 | |
| 941 | static int cyapa_start_runtime(struct cyapa *cyapa) |
| 942 | { |
| 943 | struct device *dev = &cyapa->client->dev; |
| 944 | int error; |
| 945 | |
| 946 | cyapa->runtime_suspend_power_mode = PWR_MODE_IDLE; |
| 947 | cyapa->runtime_suspend_sleep_time = |
| 948 | cyapa_pwr_cmd_to_sleep_time(cyapa->runtime_suspend_power_mode); |
| 949 | |
| 950 | error = sysfs_merge_group(&dev->kobj, &cyapa_power_runtime_group); |
| 951 | if (error) { |
| 952 | dev_err(dev, |
| 953 | "failed to create power runtime group: %d\n", error); |
| 954 | return error; |
| 955 | } |
| 956 | |
| 957 | error = devm_add_action(dev, cyapa_remove_power_runtime_group, cyapa); |
| 958 | if (error) { |
| 959 | cyapa_remove_power_runtime_group(cyapa); |
| 960 | dev_err(dev, |
| 961 | "failed to add power runtime cleanup action: %d\n", |
| 962 | error); |
| 963 | return error; |
| 964 | } |
| 965 | |
| 966 | /* runtime is enabled until device is operational and opened. */ |
| 967 | pm_runtime_set_suspended(dev); |
| 968 | pm_runtime_use_autosuspend(dev); |
| 969 | pm_runtime_set_autosuspend_delay(dev, AUTOSUSPEND_DELAY); |
| 970 | |
| 971 | return 0; |
| 972 | } |
| 973 | #else |
| 974 | static inline int cyapa_start_runtime(struct cyapa *cyapa) |
| 975 | { |
| 976 | return 0; |
| 977 | } |
| 978 | #endif /* CONFIG_PM */ |
| 979 | |
Dudley Du | c806b0b | 2015-01-17 22:07:12 -0800 | [diff] [blame] | 980 | static ssize_t cyapa_show_fm_ver(struct device *dev, |
| 981 | struct device_attribute *attr, char *buf) |
| 982 | { |
| 983 | int error; |
| 984 | struct cyapa *cyapa = dev_get_drvdata(dev); |
| 985 | |
| 986 | error = mutex_lock_interruptible(&cyapa->state_sync_lock); |
| 987 | if (error) |
| 988 | return error; |
| 989 | error = scnprintf(buf, PAGE_SIZE, "%d.%d\n", cyapa->fw_maj_ver, |
| 990 | cyapa->fw_min_ver); |
| 991 | mutex_unlock(&cyapa->state_sync_lock); |
| 992 | return error; |
| 993 | } |
| 994 | |
| 995 | static ssize_t cyapa_show_product_id(struct device *dev, |
| 996 | struct device_attribute *attr, char *buf) |
| 997 | { |
| 998 | struct cyapa *cyapa = dev_get_drvdata(dev); |
| 999 | int size; |
| 1000 | int error; |
| 1001 | |
| 1002 | error = mutex_lock_interruptible(&cyapa->state_sync_lock); |
| 1003 | if (error) |
| 1004 | return error; |
| 1005 | size = scnprintf(buf, PAGE_SIZE, "%s\n", cyapa->product_id); |
| 1006 | mutex_unlock(&cyapa->state_sync_lock); |
| 1007 | return size; |
| 1008 | } |
| 1009 | |
| 1010 | static int cyapa_firmware(struct cyapa *cyapa, const char *fw_name) |
| 1011 | { |
| 1012 | struct device *dev = &cyapa->client->dev; |
| 1013 | const struct firmware *fw; |
| 1014 | int error; |
| 1015 | |
| 1016 | error = request_firmware(&fw, fw_name, dev); |
| 1017 | if (error) { |
| 1018 | dev_err(dev, "Could not load firmware from %s: %d\n", |
| 1019 | fw_name, error); |
| 1020 | return error; |
| 1021 | } |
| 1022 | |
| 1023 | error = cyapa->ops->check_fw(cyapa, fw); |
| 1024 | if (error) { |
| 1025 | dev_err(dev, "Invalid CYAPA firmware image: %s\n", |
| 1026 | fw_name); |
| 1027 | goto done; |
| 1028 | } |
| 1029 | |
| 1030 | /* |
| 1031 | * Resume the potentially suspended device because doing FW |
| 1032 | * update on a device not in the FULL mode has a chance to |
| 1033 | * fail. |
| 1034 | */ |
| 1035 | pm_runtime_get_sync(dev); |
| 1036 | |
| 1037 | /* Require IRQ support for firmware update commands. */ |
| 1038 | cyapa_enable_irq_for_cmd(cyapa); |
| 1039 | |
| 1040 | error = cyapa->ops->bl_enter(cyapa); |
| 1041 | if (error) { |
| 1042 | dev_err(dev, "bl_enter failed, %d\n", error); |
| 1043 | goto err_detect; |
| 1044 | } |
| 1045 | |
| 1046 | error = cyapa->ops->bl_activate(cyapa); |
| 1047 | if (error) { |
| 1048 | dev_err(dev, "bl_activate failed, %d\n", error); |
| 1049 | goto err_detect; |
| 1050 | } |
| 1051 | |
| 1052 | error = cyapa->ops->bl_initiate(cyapa, fw); |
| 1053 | if (error) { |
| 1054 | dev_err(dev, "bl_initiate failed, %d\n", error); |
| 1055 | goto err_detect; |
| 1056 | } |
| 1057 | |
| 1058 | error = cyapa->ops->update_fw(cyapa, fw); |
| 1059 | if (error) { |
| 1060 | dev_err(dev, "update_fw failed, %d\n", error); |
| 1061 | goto err_detect; |
| 1062 | } |
| 1063 | |
| 1064 | err_detect: |
| 1065 | cyapa_disable_irq_for_cmd(cyapa); |
| 1066 | pm_runtime_put_noidle(dev); |
| 1067 | |
| 1068 | done: |
| 1069 | release_firmware(fw); |
| 1070 | return error; |
| 1071 | } |
| 1072 | |
| 1073 | static ssize_t cyapa_update_fw_store(struct device *dev, |
| 1074 | struct device_attribute *attr, |
| 1075 | const char *buf, size_t count) |
| 1076 | { |
| 1077 | struct cyapa *cyapa = dev_get_drvdata(dev); |
| 1078 | char fw_name[NAME_MAX]; |
| 1079 | int ret, error; |
| 1080 | |
Dan Carpenter | b481077 | 2015-01-22 08:20:16 -0800 | [diff] [blame] | 1081 | if (count >= NAME_MAX) { |
Dudley Du | c806b0b | 2015-01-17 22:07:12 -0800 | [diff] [blame] | 1082 | dev_err(dev, "File name too long\n"); |
| 1083 | return -EINVAL; |
| 1084 | } |
| 1085 | |
| 1086 | memcpy(fw_name, buf, count); |
| 1087 | if (fw_name[count - 1] == '\n') |
| 1088 | fw_name[count - 1] = '\0'; |
| 1089 | else |
| 1090 | fw_name[count] = '\0'; |
| 1091 | |
| 1092 | if (cyapa->input) { |
| 1093 | /* |
| 1094 | * Force the input device to be registered after the firmware |
| 1095 | * image is updated, so if the corresponding parameters updated |
| 1096 | * in the new firmware image can taken effect immediately. |
| 1097 | */ |
| 1098 | input_unregister_device(cyapa->input); |
| 1099 | cyapa->input = NULL; |
| 1100 | } |
| 1101 | |
| 1102 | error = mutex_lock_interruptible(&cyapa->state_sync_lock); |
| 1103 | if (error) { |
| 1104 | /* |
| 1105 | * Whatever, do reinitialize to try to recover TP state to |
| 1106 | * previous state just as it entered fw update entrance. |
| 1107 | */ |
| 1108 | cyapa_reinitialize(cyapa); |
| 1109 | return error; |
| 1110 | } |
| 1111 | |
| 1112 | error = cyapa_firmware(cyapa, fw_name); |
| 1113 | if (error) |
| 1114 | dev_err(dev, "firmware update failed: %d\n", error); |
| 1115 | else |
| 1116 | dev_dbg(dev, "firmware update successfully done.\n"); |
| 1117 | |
| 1118 | /* |
Dudley Du | 9489761 | 2015-07-20 16:49:06 -0700 | [diff] [blame] | 1119 | * Re-detect trackpad device states because firmware update process |
Dudley Du | c806b0b | 2015-01-17 22:07:12 -0800 | [diff] [blame] | 1120 | * will reset trackpad device into bootloader mode. |
| 1121 | */ |
| 1122 | ret = cyapa_reinitialize(cyapa); |
| 1123 | if (ret) { |
Dudley Du | 9489761 | 2015-07-20 16:49:06 -0700 | [diff] [blame] | 1124 | dev_err(dev, "failed to re-detect after updated: %d\n", ret); |
Dudley Du | c806b0b | 2015-01-17 22:07:12 -0800 | [diff] [blame] | 1125 | error = error ? error : ret; |
| 1126 | } |
| 1127 | |
| 1128 | mutex_unlock(&cyapa->state_sync_lock); |
| 1129 | |
| 1130 | return error ? error : count; |
| 1131 | } |
| 1132 | |
| 1133 | static ssize_t cyapa_calibrate_store(struct device *dev, |
| 1134 | struct device_attribute *attr, |
| 1135 | const char *buf, size_t count) |
| 1136 | { |
| 1137 | struct cyapa *cyapa = dev_get_drvdata(dev); |
| 1138 | int error; |
| 1139 | |
| 1140 | error = mutex_lock_interruptible(&cyapa->state_sync_lock); |
| 1141 | if (error) |
| 1142 | return error; |
| 1143 | |
| 1144 | if (cyapa->operational) { |
| 1145 | cyapa_enable_irq_for_cmd(cyapa); |
| 1146 | error = cyapa->ops->calibrate_store(dev, attr, buf, count); |
| 1147 | cyapa_disable_irq_for_cmd(cyapa); |
| 1148 | } else { |
| 1149 | error = -EBUSY; /* Still running in bootloader mode. */ |
| 1150 | } |
| 1151 | |
| 1152 | mutex_unlock(&cyapa->state_sync_lock); |
| 1153 | return error < 0 ? error : count; |
| 1154 | } |
| 1155 | |
| 1156 | static ssize_t cyapa_show_baseline(struct device *dev, |
| 1157 | struct device_attribute *attr, char *buf) |
| 1158 | { |
| 1159 | struct cyapa *cyapa = dev_get_drvdata(dev); |
| 1160 | ssize_t error; |
| 1161 | |
| 1162 | error = mutex_lock_interruptible(&cyapa->state_sync_lock); |
| 1163 | if (error) |
| 1164 | return error; |
| 1165 | |
| 1166 | if (cyapa->operational) { |
| 1167 | cyapa_enable_irq_for_cmd(cyapa); |
| 1168 | error = cyapa->ops->show_baseline(dev, attr, buf); |
| 1169 | cyapa_disable_irq_for_cmd(cyapa); |
| 1170 | } else { |
| 1171 | error = -EBUSY; /* Still running in bootloader mode. */ |
| 1172 | } |
| 1173 | |
| 1174 | mutex_unlock(&cyapa->state_sync_lock); |
| 1175 | return error; |
| 1176 | } |
| 1177 | |
| 1178 | static char *cyapa_state_to_string(struct cyapa *cyapa) |
| 1179 | { |
| 1180 | switch (cyapa->state) { |
| 1181 | case CYAPA_STATE_BL_BUSY: |
| 1182 | return "bootloader busy"; |
| 1183 | case CYAPA_STATE_BL_IDLE: |
| 1184 | return "bootloader idle"; |
| 1185 | case CYAPA_STATE_BL_ACTIVE: |
| 1186 | return "bootloader active"; |
| 1187 | case CYAPA_STATE_GEN5_BL: |
Dudley Du | c2c06c4 | 2015-07-20 16:53:30 -0700 | [diff] [blame] | 1188 | case CYAPA_STATE_GEN6_BL: |
Dudley Du | c806b0b | 2015-01-17 22:07:12 -0800 | [diff] [blame] | 1189 | return "bootloader"; |
| 1190 | case CYAPA_STATE_OP: |
| 1191 | case CYAPA_STATE_GEN5_APP: |
Dudley Du | c2c06c4 | 2015-07-20 16:53:30 -0700 | [diff] [blame] | 1192 | case CYAPA_STATE_GEN6_APP: |
Dudley Du | c806b0b | 2015-01-17 22:07:12 -0800 | [diff] [blame] | 1193 | return "operational"; /* Normal valid state. */ |
| 1194 | default: |
| 1195 | return "invalid mode"; |
| 1196 | } |
| 1197 | } |
| 1198 | |
| 1199 | static ssize_t cyapa_show_mode(struct device *dev, |
| 1200 | struct device_attribute *attr, char *buf) |
| 1201 | { |
| 1202 | struct cyapa *cyapa = dev_get_drvdata(dev); |
| 1203 | int size; |
| 1204 | int error; |
| 1205 | |
| 1206 | error = mutex_lock_interruptible(&cyapa->state_sync_lock); |
| 1207 | if (error) |
| 1208 | return error; |
| 1209 | |
| 1210 | size = scnprintf(buf, PAGE_SIZE, "gen%d %s\n", |
| 1211 | cyapa->gen, cyapa_state_to_string(cyapa)); |
| 1212 | |
| 1213 | mutex_unlock(&cyapa->state_sync_lock); |
| 1214 | return size; |
| 1215 | } |
| 1216 | |
| 1217 | static DEVICE_ATTR(firmware_version, S_IRUGO, cyapa_show_fm_ver, NULL); |
| 1218 | static DEVICE_ATTR(product_id, S_IRUGO, cyapa_show_product_id, NULL); |
| 1219 | static DEVICE_ATTR(update_fw, S_IWUSR, NULL, cyapa_update_fw_store); |
| 1220 | static DEVICE_ATTR(baseline, S_IRUGO, cyapa_show_baseline, NULL); |
| 1221 | static DEVICE_ATTR(calibrate, S_IWUSR, NULL, cyapa_calibrate_store); |
| 1222 | static DEVICE_ATTR(mode, S_IRUGO, cyapa_show_mode, NULL); |
| 1223 | |
| 1224 | static struct attribute *cyapa_sysfs_entries[] = { |
| 1225 | &dev_attr_firmware_version.attr, |
| 1226 | &dev_attr_product_id.attr, |
| 1227 | &dev_attr_update_fw.attr, |
| 1228 | &dev_attr_baseline.attr, |
| 1229 | &dev_attr_calibrate.attr, |
| 1230 | &dev_attr_mode.attr, |
| 1231 | NULL, |
| 1232 | }; |
| 1233 | |
| 1234 | static const struct attribute_group cyapa_sysfs_group = { |
| 1235 | .attrs = cyapa_sysfs_entries, |
| 1236 | }; |
| 1237 | |
| 1238 | static void cyapa_remove_sysfs_group(void *data) |
| 1239 | { |
| 1240 | struct cyapa *cyapa = data; |
| 1241 | |
| 1242 | sysfs_remove_group(&cyapa->client->dev.kobj, &cyapa_sysfs_group); |
| 1243 | } |
| 1244 | |
Dudley Du | 36e9615 | 2015-07-30 11:19:18 -0700 | [diff] [blame^] | 1245 | static void cyapa_disable_regulator(void *data) |
| 1246 | { |
| 1247 | struct cyapa *cyapa = data; |
| 1248 | |
| 1249 | regulator_disable(cyapa->vcc); |
| 1250 | } |
| 1251 | |
Benson Leung | d7e34d1 | 2013-01-09 16:25:11 -0800 | [diff] [blame] | 1252 | static int cyapa_probe(struct i2c_client *client, |
| 1253 | const struct i2c_device_id *dev_id) |
| 1254 | { |
Benson Leung | d7e34d1 | 2013-01-09 16:25:11 -0800 | [diff] [blame] | 1255 | struct device *dev = &client->dev; |
Dudley Du | b1cfa7b | 2014-11-09 12:36:34 -0800 | [diff] [blame] | 1256 | struct cyapa *cyapa; |
| 1257 | u8 adapter_func; |
Dudley Du | 9f1cd85 | 2015-01-17 18:35:26 -0800 | [diff] [blame] | 1258 | union i2c_smbus_data dummy; |
Dudley Du | b1cfa7b | 2014-11-09 12:36:34 -0800 | [diff] [blame] | 1259 | int error; |
Benson Leung | d7e34d1 | 2013-01-09 16:25:11 -0800 | [diff] [blame] | 1260 | |
Benson Leung | 6ddaf74 | 2013-02-13 13:56:03 -0800 | [diff] [blame] | 1261 | adapter_func = cyapa_check_adapter_functionality(client); |
| 1262 | if (adapter_func == CYAPA_ADAPTER_FUNC_NONE) { |
| 1263 | dev_err(dev, "not a supported I2C/SMBus adapter\n"); |
| 1264 | return -EIO; |
| 1265 | } |
| 1266 | |
Dudley Du | 9f1cd85 | 2015-01-17 18:35:26 -0800 | [diff] [blame] | 1267 | /* Make sure there is something at this address */ |
| 1268 | if (i2c_smbus_xfer(client->adapter, client->addr, 0, |
| 1269 | I2C_SMBUS_READ, 0, I2C_SMBUS_BYTE, &dummy) < 0) |
| 1270 | return -ENODEV; |
| 1271 | |
Dudley Du | b1cfa7b | 2014-11-09 12:36:34 -0800 | [diff] [blame] | 1272 | cyapa = devm_kzalloc(dev, sizeof(struct cyapa), GFP_KERNEL); |
| 1273 | if (!cyapa) |
Benson Leung | d7e34d1 | 2013-01-09 16:25:11 -0800 | [diff] [blame] | 1274 | return -ENOMEM; |
Benson Leung | d7e34d1 | 2013-01-09 16:25:11 -0800 | [diff] [blame] | 1275 | |
Benson Leung | 6ddaf74 | 2013-02-13 13:56:03 -0800 | [diff] [blame] | 1276 | /* i2c isn't supported, use smbus */ |
| 1277 | if (adapter_func == CYAPA_ADAPTER_FUNC_SMBUS) |
| 1278 | cyapa->smbus = true; |
Dudley Du | b1cfa7b | 2014-11-09 12:36:34 -0800 | [diff] [blame] | 1279 | |
Dudley Du | 9f1cd85 | 2015-01-17 18:35:26 -0800 | [diff] [blame] | 1280 | cyapa->client = client; |
| 1281 | i2c_set_clientdata(client, cyapa); |
| 1282 | sprintf(cyapa->phys, "i2c-%d-%04x/input0", client->adapter->nr, |
| 1283 | client->addr); |
Dudley Du | b1cfa7b | 2014-11-09 12:36:34 -0800 | [diff] [blame] | 1284 | |
Dudley Du | 36e9615 | 2015-07-30 11:19:18 -0700 | [diff] [blame^] | 1285 | cyapa->vcc = devm_regulator_get(dev, "vcc"); |
| 1286 | if (IS_ERR(cyapa->vcc)) { |
| 1287 | error = PTR_ERR(cyapa->vcc); |
| 1288 | dev_err(dev, "failed to get vcc regulator: %d\n", error); |
| 1289 | return error; |
| 1290 | } |
| 1291 | |
| 1292 | error = regulator_enable(cyapa->vcc); |
| 1293 | if (error) { |
| 1294 | dev_err(dev, "failed to enable regulator: %d\n", error); |
| 1295 | return error; |
| 1296 | } |
| 1297 | |
| 1298 | error = devm_add_action(dev, cyapa_disable_regulator, cyapa); |
| 1299 | if (error) { |
| 1300 | cyapa_disable_regulator(cyapa); |
| 1301 | dev_err(dev, "failed to add disable regulator action: %d\n", |
| 1302 | error); |
| 1303 | return error; |
| 1304 | } |
| 1305 | |
Dudley Du | 9f1cd85 | 2015-01-17 18:35:26 -0800 | [diff] [blame] | 1306 | error = cyapa_initialize(cyapa); |
Dudley Du | b1cfa7b | 2014-11-09 12:36:34 -0800 | [diff] [blame] | 1307 | if (error) { |
Dudley Du | 9f1cd85 | 2015-01-17 18:35:26 -0800 | [diff] [blame] | 1308 | dev_err(dev, "failed to detect and initialize tp device.\n"); |
Dudley Du | b1cfa7b | 2014-11-09 12:36:34 -0800 | [diff] [blame] | 1309 | return error; |
Benson Leung | d7e34d1 | 2013-01-09 16:25:11 -0800 | [diff] [blame] | 1310 | } |
| 1311 | |
Dudley Du | c806b0b | 2015-01-17 22:07:12 -0800 | [diff] [blame] | 1312 | error = sysfs_create_group(&client->dev.kobj, &cyapa_sysfs_group); |
| 1313 | if (error) { |
| 1314 | dev_err(dev, "failed to create sysfs entries: %d\n", error); |
| 1315 | return error; |
| 1316 | } |
| 1317 | |
| 1318 | error = devm_add_action(dev, cyapa_remove_sysfs_group, cyapa); |
| 1319 | if (error) { |
| 1320 | cyapa_remove_sysfs_group(cyapa); |
| 1321 | dev_err(dev, "failed to add sysfs cleanup action: %d\n", error); |
| 1322 | return error; |
| 1323 | } |
| 1324 | |
Dudley Du | 22e7db8 | 2015-01-17 18:56:18 -0800 | [diff] [blame] | 1325 | error = cyapa_prepare_wakeup_controls(cyapa); |
| 1326 | if (error) { |
| 1327 | dev_err(dev, "failed to prepare wakeup controls: %d\n", error); |
| 1328 | return error; |
| 1329 | } |
| 1330 | |
Dudley Du | 6728650 | 2015-01-17 18:57:42 -0800 | [diff] [blame] | 1331 | error = cyapa_start_runtime(cyapa); |
| 1332 | if (error) { |
| 1333 | dev_err(dev, "failed to start pm_runtime: %d\n", error); |
| 1334 | return error; |
| 1335 | } |
| 1336 | |
Dudley Du | b1cfa7b | 2014-11-09 12:36:34 -0800 | [diff] [blame] | 1337 | error = devm_request_threaded_irq(dev, client->irq, |
| 1338 | NULL, cyapa_irq, |
| 1339 | IRQF_TRIGGER_FALLING | IRQF_ONESHOT, |
| 1340 | "cyapa", cyapa); |
| 1341 | if (error) { |
Dudley Du | 823a11f | 2014-12-04 07:00:03 -0800 | [diff] [blame] | 1342 | dev_err(dev, "failed to request threaded irq: %d\n", error); |
Dudley Du | b1cfa7b | 2014-11-09 12:36:34 -0800 | [diff] [blame] | 1343 | return error; |
Benson Leung | d7e34d1 | 2013-01-09 16:25:11 -0800 | [diff] [blame] | 1344 | } |
| 1345 | |
Dudley Du | b1cfa7b | 2014-11-09 12:36:34 -0800 | [diff] [blame] | 1346 | /* Disable IRQ until the device is opened */ |
| 1347 | disable_irq(client->irq); |
| 1348 | |
Dudley Du | 9f1cd85 | 2015-01-17 18:35:26 -0800 | [diff] [blame] | 1349 | /* |
| 1350 | * Register the device in the input subsystem when it's operational. |
| 1351 | * Otherwise, keep in this driver, so it can be be recovered or updated |
| 1352 | * through the sysfs mode and update_fw interfaces by user or apps. |
| 1353 | */ |
| 1354 | if (cyapa->operational) { |
| 1355 | error = cyapa_create_input_dev(cyapa); |
| 1356 | if (error) { |
| 1357 | dev_err(dev, "create input_dev instance failed: %d\n", |
| 1358 | error); |
| 1359 | return error; |
| 1360 | } |
Benson Leung | d7e34d1 | 2013-01-09 16:25:11 -0800 | [diff] [blame] | 1361 | } |
| 1362 | |
| 1363 | return 0; |
Benson Leung | d7e34d1 | 2013-01-09 16:25:11 -0800 | [diff] [blame] | 1364 | } |
| 1365 | |
Jingoo Han | 572081a | 2014-11-02 00:03:37 -0700 | [diff] [blame] | 1366 | static int __maybe_unused cyapa_suspend(struct device *dev) |
Benson Leung | d7e34d1 | 2013-01-09 16:25:11 -0800 | [diff] [blame] | 1367 | { |
Dudley Du | b1cfa7b | 2014-11-09 12:36:34 -0800 | [diff] [blame] | 1368 | struct i2c_client *client = to_i2c_client(dev); |
| 1369 | struct cyapa *cyapa = i2c_get_clientdata(client); |
Benson Leung | d7e34d1 | 2013-01-09 16:25:11 -0800 | [diff] [blame] | 1370 | u8 power_mode; |
Dudley Du | b1cfa7b | 2014-11-09 12:36:34 -0800 | [diff] [blame] | 1371 | int error; |
Benson Leung | d7e34d1 | 2013-01-09 16:25:11 -0800 | [diff] [blame] | 1372 | |
Dudley Du | 9f1cd85 | 2015-01-17 18:35:26 -0800 | [diff] [blame] | 1373 | error = mutex_lock_interruptible(&cyapa->state_sync_lock); |
Dudley Du | b1cfa7b | 2014-11-09 12:36:34 -0800 | [diff] [blame] | 1374 | if (error) |
| 1375 | return error; |
| 1376 | |
Dudley Du | 6728650 | 2015-01-17 18:57:42 -0800 | [diff] [blame] | 1377 | /* |
| 1378 | * Runtime PM is enable only when device is in operational mode and |
| 1379 | * users in use, so need check it before disable it to |
| 1380 | * avoid unbalance warning. |
| 1381 | */ |
| 1382 | if (pm_runtime_enabled(dev)) |
| 1383 | pm_runtime_disable(dev); |
Dudley Du | b1cfa7b | 2014-11-09 12:36:34 -0800 | [diff] [blame] | 1384 | disable_irq(client->irq); |
Benson Leung | d7e34d1 | 2013-01-09 16:25:11 -0800 | [diff] [blame] | 1385 | |
| 1386 | /* |
| 1387 | * Set trackpad device to idle mode if wakeup is allowed, |
| 1388 | * otherwise turn off. |
| 1389 | */ |
Dudley Du | 9f1cd85 | 2015-01-17 18:35:26 -0800 | [diff] [blame] | 1390 | if (cyapa->operational) { |
| 1391 | power_mode = device_may_wakeup(dev) ? cyapa->suspend_power_mode |
| 1392 | : PWR_MODE_OFF; |
| 1393 | error = cyapa->ops->set_power_mode(cyapa, power_mode, |
Dudley Du | 757cae5 | 2015-07-20 17:09:59 -0700 | [diff] [blame] | 1394 | cyapa->suspend_sleep_time, true); |
Dudley Du | 9f1cd85 | 2015-01-17 18:35:26 -0800 | [diff] [blame] | 1395 | if (error) |
| 1396 | dev_err(dev, "suspend set power mode failed: %d\n", |
| 1397 | error); |
| 1398 | } |
Benson Leung | d7e34d1 | 2013-01-09 16:25:11 -0800 | [diff] [blame] | 1399 | |
Dudley Du | 945525e | 2015-07-20 16:57:53 -0700 | [diff] [blame] | 1400 | /* |
| 1401 | * Disable proximity interrupt when system idle, want true touch to |
| 1402 | * wake the system. |
| 1403 | */ |
| 1404 | if (cyapa->dev_pwr_mode != PWR_MODE_OFF) |
| 1405 | cyapa->ops->set_proximity(cyapa, false); |
| 1406 | |
Benson Leung | d7e34d1 | 2013-01-09 16:25:11 -0800 | [diff] [blame] | 1407 | if (device_may_wakeup(dev)) |
Dudley Du | f68a95c | 2014-12-03 15:29:34 -0800 | [diff] [blame] | 1408 | cyapa->irq_wake = (enable_irq_wake(client->irq) == 0); |
Dudley Du | b1cfa7b | 2014-11-09 12:36:34 -0800 | [diff] [blame] | 1409 | |
Dudley Du | 9f1cd85 | 2015-01-17 18:35:26 -0800 | [diff] [blame] | 1410 | mutex_unlock(&cyapa->state_sync_lock); |
Benson Leung | d7e34d1 | 2013-01-09 16:25:11 -0800 | [diff] [blame] | 1411 | return 0; |
| 1412 | } |
| 1413 | |
Jingoo Han | 572081a | 2014-11-02 00:03:37 -0700 | [diff] [blame] | 1414 | static int __maybe_unused cyapa_resume(struct device *dev) |
Benson Leung | d7e34d1 | 2013-01-09 16:25:11 -0800 | [diff] [blame] | 1415 | { |
Dudley Du | b1cfa7b | 2014-11-09 12:36:34 -0800 | [diff] [blame] | 1416 | struct i2c_client *client = to_i2c_client(dev); |
| 1417 | struct cyapa *cyapa = i2c_get_clientdata(client); |
Dudley Du | b1cfa7b | 2014-11-09 12:36:34 -0800 | [diff] [blame] | 1418 | int error; |
| 1419 | |
Dudley Du | 9f1cd85 | 2015-01-17 18:35:26 -0800 | [diff] [blame] | 1420 | mutex_lock(&cyapa->state_sync_lock); |
Benson Leung | d7e34d1 | 2013-01-09 16:25:11 -0800 | [diff] [blame] | 1421 | |
Dudley Du | 9f1cd85 | 2015-01-17 18:35:26 -0800 | [diff] [blame] | 1422 | if (device_may_wakeup(dev) && cyapa->irq_wake) { |
Dudley Du | f68a95c | 2014-12-03 15:29:34 -0800 | [diff] [blame] | 1423 | disable_irq_wake(client->irq); |
Dudley Du | 9f1cd85 | 2015-01-17 18:35:26 -0800 | [diff] [blame] | 1424 | cyapa->irq_wake = false; |
| 1425 | } |
Benson Leung | d7e34d1 | 2013-01-09 16:25:11 -0800 | [diff] [blame] | 1426 | |
Dudley Du | 945525e | 2015-07-20 16:57:53 -0700 | [diff] [blame] | 1427 | /* |
| 1428 | * Update device states and runtime PM states. |
| 1429 | * Re-Enable proximity interrupt after enter operational mode. |
| 1430 | */ |
Dudley Du | 9f1cd85 | 2015-01-17 18:35:26 -0800 | [diff] [blame] | 1431 | error = cyapa_reinitialize(cyapa); |
Dudley Du | b1cfa7b | 2014-11-09 12:36:34 -0800 | [diff] [blame] | 1432 | if (error) |
Dudley Du | 9f1cd85 | 2015-01-17 18:35:26 -0800 | [diff] [blame] | 1433 | dev_warn(dev, "failed to reinitialize TP device: %d\n", error); |
Benson Leung | d7e34d1 | 2013-01-09 16:25:11 -0800 | [diff] [blame] | 1434 | |
Dudley Du | f68a95c | 2014-12-03 15:29:34 -0800 | [diff] [blame] | 1435 | enable_irq(client->irq); |
Dudley Du | b1cfa7b | 2014-11-09 12:36:34 -0800 | [diff] [blame] | 1436 | |
Dudley Du | 9f1cd85 | 2015-01-17 18:35:26 -0800 | [diff] [blame] | 1437 | mutex_unlock(&cyapa->state_sync_lock); |
Benson Leung | d7e34d1 | 2013-01-09 16:25:11 -0800 | [diff] [blame] | 1438 | return 0; |
| 1439 | } |
Benson Leung | d7e34d1 | 2013-01-09 16:25:11 -0800 | [diff] [blame] | 1440 | |
Dudley Du | 6728650 | 2015-01-17 18:57:42 -0800 | [diff] [blame] | 1441 | static int __maybe_unused cyapa_runtime_suspend(struct device *dev) |
| 1442 | { |
| 1443 | struct cyapa *cyapa = dev_get_drvdata(dev); |
| 1444 | int error; |
| 1445 | |
| 1446 | error = cyapa->ops->set_power_mode(cyapa, |
| 1447 | cyapa->runtime_suspend_power_mode, |
Dudley Du | 757cae5 | 2015-07-20 17:09:59 -0700 | [diff] [blame] | 1448 | cyapa->runtime_suspend_sleep_time, |
| 1449 | false); |
Dudley Du | 6728650 | 2015-01-17 18:57:42 -0800 | [diff] [blame] | 1450 | if (error) |
| 1451 | dev_warn(dev, "runtime suspend failed: %d\n", error); |
| 1452 | |
| 1453 | return 0; |
| 1454 | } |
| 1455 | |
| 1456 | static int __maybe_unused cyapa_runtime_resume(struct device *dev) |
| 1457 | { |
| 1458 | struct cyapa *cyapa = dev_get_drvdata(dev); |
| 1459 | int error; |
| 1460 | |
Dudley Du | 757cae5 | 2015-07-20 17:09:59 -0700 | [diff] [blame] | 1461 | error = cyapa->ops->set_power_mode(cyapa, |
| 1462 | PWR_MODE_FULL_ACTIVE, 0, false); |
Dudley Du | 6728650 | 2015-01-17 18:57:42 -0800 | [diff] [blame] | 1463 | if (error) |
| 1464 | dev_warn(dev, "runtime resume failed: %d\n", error); |
| 1465 | |
| 1466 | return 0; |
| 1467 | } |
| 1468 | |
| 1469 | static const struct dev_pm_ops cyapa_pm_ops = { |
| 1470 | SET_SYSTEM_SLEEP_PM_OPS(cyapa_suspend, cyapa_resume) |
| 1471 | SET_RUNTIME_PM_OPS(cyapa_runtime_suspend, cyapa_runtime_resume, NULL) |
| 1472 | }; |
Benson Leung | d7e34d1 | 2013-01-09 16:25:11 -0800 | [diff] [blame] | 1473 | |
| 1474 | static const struct i2c_device_id cyapa_id_table[] = { |
| 1475 | { "cyapa", 0 }, |
| 1476 | { }, |
| 1477 | }; |
| 1478 | MODULE_DEVICE_TABLE(i2c, cyapa_id_table); |
| 1479 | |
Dudley Du | 7b2171d | 2015-01-17 22:18:59 -0800 | [diff] [blame] | 1480 | #ifdef CONFIG_ACPI |
| 1481 | static const struct acpi_device_id cyapa_acpi_id[] = { |
| 1482 | { "CYAP0000", 0 }, /* Gen3 trackpad with 0x67 I2C address. */ |
| 1483 | { "CYAP0001", 0 }, /* Gen5 trackpad with 0x24 I2C address. */ |
Dudley Du | ce2ae9e | 2015-07-20 17:15:46 -0700 | [diff] [blame] | 1484 | { "CYAP0002", 0 }, /* Gen6 trackpad with 0x24 I2C address. */ |
Dudley Du | 7b2171d | 2015-01-17 22:18:59 -0800 | [diff] [blame] | 1485 | { } |
| 1486 | }; |
| 1487 | MODULE_DEVICE_TABLE(acpi, cyapa_acpi_id); |
| 1488 | #endif |
| 1489 | |
Benson Leung | d7e34d1 | 2013-01-09 16:25:11 -0800 | [diff] [blame] | 1490 | static struct i2c_driver cyapa_driver = { |
| 1491 | .driver = { |
| 1492 | .name = "cyapa", |
Benson Leung | d7e34d1 | 2013-01-09 16:25:11 -0800 | [diff] [blame] | 1493 | .pm = &cyapa_pm_ops, |
Dudley Du | 7b2171d | 2015-01-17 22:18:59 -0800 | [diff] [blame] | 1494 | .acpi_match_table = ACPI_PTR(cyapa_acpi_id), |
Benson Leung | d7e34d1 | 2013-01-09 16:25:11 -0800 | [diff] [blame] | 1495 | }, |
| 1496 | |
| 1497 | .probe = cyapa_probe, |
Benson Leung | d7e34d1 | 2013-01-09 16:25:11 -0800 | [diff] [blame] | 1498 | .id_table = cyapa_id_table, |
| 1499 | }; |
| 1500 | |
| 1501 | module_i2c_driver(cyapa_driver); |
| 1502 | |
| 1503 | MODULE_DESCRIPTION("Cypress APA I2C Trackpad Driver"); |
| 1504 | MODULE_AUTHOR("Dudley Du <dudl@cypress.com>"); |
| 1505 | MODULE_LICENSE("GPL"); |