There are no in-kernel users of pxa27x_keypad_platform_data in the kernel, and the driver supports configuration via device tree, so drop support of static platform data and move properties parsing from OF-specific methods to generic ones.
Unified · Split
| @@ -21,13 +21,13 @@ · 20 unmodified lines | ||
| 21 | 21 | #include <linux/io.h> |
| 22 | 22 | #include <linux/device.h> |
| 23 | 23 | #include <linux/platform_device.h> |
| 24 | +#include <linux/property.h> | |
| 24 | 25 | #include <linux/clk.h> |
| 25 | 26 | #include <linux/err.h> |
| 26 | 27 | #include <linux/input/matrix_keypad.h> |
| 27 | 28 | #include <linux/slab.h> |
| 28 | 29 | #include <linux/of.h> |
| 29 | 30 | |
| 30 | −#include <linux/platform_data/keypad-pxa27x.h> | |
| 31 | 31 | /* |
| 32 | 32 | * Keypad Controller registers |
| 33 | 33 | */ |
| @@ -100,54 +100,69 @@ · 66 unmodified lines | ||
| 100 | 100 | #define keypad_readl(off) __raw_readl(keypad->mmio_base + (off)) |
| 101 | 101 | #define keypad_writel(off, v) __raw_writel((v), keypad->mmio_base + (off)) |
| 102 | 102 | |
| 103 | +#define MAX_MATRIX_KEY_ROWS 8 | |
| 104 | +#define MAX_MATRIX_KEY_COLS 8 | |
| 105 | +#define MAX_DIRECT_KEY_NUM 8 | |
| 106 | +#define MAX_ROTARY_ENCODERS 2 | |
| 107 | + | |
| 103 | 108 | #define MAX_MATRIX_KEY_NUM (MAX_MATRIX_KEY_ROWS * MAX_MATRIX_KEY_COLS) |
| 104 | 109 | #define MAX_KEYPAD_KEYS (MAX_MATRIX_KEY_NUM + MAX_DIRECT_KEY_NUM) |
| 105 | 110 | |
| 106 | −struct pxa27x_keypad { | |
| 107 | − const struct pxa27x_keypad_platform_data *pdata; | |
| 111 | +struct pxa27x_keypad_rotary { | |
| 112 | + unsigned short *key_codes; | |
| 113 | + int rel_code; | |
| 114 | + bool enabled; | |
| 115 | +}; | |
| 108 | 116 | |
| 117 | +struct pxa27x_keypad { | |
| 109 | 118 | struct clk *clk; |
| 110 | 119 | struct input_dev *input_dev; |
| 111 | 120 | void __iomem *mmio_base; |
| 112 | 121 | |
| 113 | 122 | int irq; |
| 114 | 123 | |
| 115 | − unsigned short keycodes[MAX_KEYPAD_KEYS]; | |
| 116 | − int rotary_rel_code[2]; | |
| 117 | − | |
| 124 | + unsigned int matrix_key_rows; | |
| 125 | + unsigned int matrix_key_cols; | |
| 118 | 126 | unsigned int row_shift; |
| 119 | 127 | |
| 128 | + unsigned int direct_key_num; | |
| 129 | + unsigned int direct_key_mask; | |
| 130 | + bool direct_key_low_active; | |
| 131 | + | |
| 132 | + /* key debounce interval */ | |
| 133 | + unsigned int debounce_interval; | |
| 134 | + | |
| 135 | + unsigned short keycodes[MAX_KEYPAD_KEYS]; | |
| 136 | + | |
| 120 | 137 | /* state row bits of each column scan */ |
| 121 | 138 | u32 matrix_key_state[MAX_MATRIX_KEY_COLS]; |
| 122 | 139 | u32 direct_key_state; |
| 123 | 140 | |
| 124 | − unsigned int direct_key_mask; | |
| 141 | + struct pxa27x_keypad_rotary rotary[MAX_ROTARY_ENCODERS]; | |
| 125 | 142 | }; |
| 126 | 143 | |
| 127 | −#ifdef CONFIG_OF | |
| 128 | −static int pxa27x_keypad_matrix_key_parse_dt(struct pxa27x_keypad *keypad, | |
| 129 | − struct pxa27x_keypad_platform_data *pdata) | |
| 144 | +static int pxa27x_keypad_matrix_key_parse(struct pxa27x_keypad *keypad) | |
| 130 | 145 | { |
| 131 | 146 | struct input_dev *input_dev = keypad->input_dev; |
| 132 | 147 | struct device *dev = input_dev->dev.parent; |
| 133 | − u32 rows, cols; | |
| 134 | 148 | int error; |
| 135 | 149 | |
| 136 | − error = matrix_keypad_parse_properties(dev, &rows, &cols); | |
| 150 | + error = matrix_keypad_parse_properties(dev, &keypad->matrix_key_rows, | |
| 151 | + &keypad->matrix_key_cols); | |
| 137 | 152 | if (error) |
| 138 | 153 | return error; |
| 139 | 154 | |
| 140 | − if (rows > MAX_MATRIX_KEY_ROWS || cols > MAX_MATRIX_KEY_COLS) { | |
| 155 | + if (keypad->matrix_key_rows > MAX_MATRIX_KEY_ROWS || | |
| 156 | + keypad->matrix_key_cols > MAX_MATRIX_KEY_COLS) { | |
| 141 | 157 | dev_err(dev, "rows or cols exceeds maximum value\n"); |
| 142 | 158 | return -EINVAL; |
| 143 | 159 | } |
| 144 | 160 | |
| 145 | − pdata->matrix_key_rows = rows; | |
| 146 | − pdata->matrix_key_cols = cols; | |
| 161 | + keypad->row_shift = get_count_order(keypad->matrix_key_cols); | |
| 147 | 162 | |
| 148 | 163 | error = matrix_keypad_build_keymap(NULL, NULL, |
| 149 | − pdata->matrix_key_rows, | |
| 150 | − pdata->matrix_key_cols, | |
| 164 | + keypad->matrix_key_rows, | |
| 165 | + keypad->matrix_key_cols, | |
| 151 | 166 | keypad->keycodes, input_dev); |
| 152 | 167 | if (error) |
| 153 | 168 | return error; |
| @@ -155,20 +170,17 @@ static int pxa27x_keypad_matrix_key_parse_dt(struct pxa27x_keypad *keypad, · 1 unmodified line | ||
| 155 | 170 | return 0; |
| 156 | 171 | } |
| 157 | 172 | |
| 158 | −static int pxa27x_keypad_direct_key_parse_dt(struct pxa27x_keypad *keypad, | |
| 159 | − struct pxa27x_keypad_platform_data *pdata) | |
| 173 | +static int pxa27x_keypad_direct_key_parse(struct pxa27x_keypad *keypad) | |
| 160 | 174 | { |
| 161 | 175 | struct input_dev *input_dev = keypad->input_dev; |
| 162 | 176 | struct device *dev = input_dev->dev.parent; |
| 163 | − struct device_node *np = dev->of_node; | |
| 164 | − const __be16 *prop; | |
| 165 | 177 | unsigned short code; |
| 166 | − unsigned int proplen, size; | |
| 178 | + int count; | |
| 167 | 179 | int i; |
| 168 | 180 | int error; |
| 169 | 181 | |
| 170 | − error = of_property_read_u32(np, "marvell,direct-key-count", | |
| 171 | − &pdata->direct_key_num); | |
| 182 | + error = device_property_read_u32(dev, "marvell,direct-key-count", | |
| 183 | + &keypad->direct_key_num); | |
| 172 | 184 | if (error) { |
| 173 | 185 | /* |
| 174 | 186 | * If do not have marvel,direct-key-count defined, |
| @@ -177,151 +189,121 @@ static int pxa27x_keypad_direct_key_parse_dt(struct pxa27x_keypad *keypad, · 2 unmodified lines | ||
| 177 | 189 | return error == -EINVAL ? 0 : error; |
| 178 | 190 | } |
| 179 | 191 | |
| 180 | − error = of_property_read_u32(np, "marvell,direct-key-mask", | |
| 181 | − &pdata->direct_key_mask); | |
| 192 | + error = device_property_read_u32(dev, "marvell,direct-key-mask", | |
| 193 | + &keypad->direct_key_mask); | |
| 182 | 194 | if (error) { |
| 183 | 195 | if (error != -EINVAL) |
| 184 | 196 | return error; |
| 185 | 197 | |
| 186 | 198 | /* |
| 187 | 199 | * If marvell,direct-key-mask is not defined, driver will use |
| 188 | − * default value. Default value is set when configure the keypad. | |
| 200 | + * a default value based on number of direct keys set up. | |
| 201 | + * The default value is calculated in pxa27x_keypad_config(). | |
| 189 | 202 | */ |
| 190 | − pdata->direct_key_mask = 0; | |
| 203 | + keypad->direct_key_mask = 0; | |
| 191 | 204 | } |
| 192 | 205 | |
| 193 | − pdata->direct_key_low_active = of_property_read_bool(np, | |
| 194 | − "marvell,direct-key-low-active"); | |
| 195 | − | |
| 196 | − prop = of_get_property(np, "marvell,direct-key-map", &proplen); | |
| 197 | − if (!prop) | |
| 198 | − return -EINVAL; | |
| 206 | + keypad->direct_key_low_active = | |
| 207 | + device_property_read_bool(dev, "marvell,direct-key-low-active"); | |
| 199 | 208 | |
| 200 | − if (proplen % sizeof(u16)) | |
| 209 | + count = device_property_count_u16(dev, "marvell,direct-key-map"); | |
| 210 | + if (count <= 0 || count > MAX_DIRECT_KEY_NUM) | |
| 201 | 211 | return -EINVAL; |
| 202 | 212 | |
| 203 | − size = proplen / sizeof(u16); | |
| 204 | − | |
| 205 | − /* Only MAX_DIRECT_KEY_NUM is accepted.*/ | |
| 206 | − if (size > MAX_DIRECT_KEY_NUM) | |
| 207 | − return -EINVAL; | |
| 213 | + error = device_property_read_u16_array(dev, "marvell,direct-key-map", | |
| 214 | + &keypad->keycodes[MAX_MATRIX_KEY_NUM], | |
| 215 | + count); | |
| 208 | 216 | |
| 209 | − for (i = 0; i < size; i++) { | |
| 210 | − code = be16_to_cpup(prop + i); | |
| 211 | − keypad->keycodes[MAX_MATRIX_KEY_NUM + i] = code; | |
| 217 | + for (i = 0; i < count; i++) { | |
| 218 | + code = keypad->keycodes[MAX_MATRIX_KEY_NUM + i]; | |
| 212 | 219 | __set_bit(code, input_dev->keybit); |
| 213 | 220 | } |
| 214 | 221 | |
| 215 | 222 | return 0; |
| 216 | 223 | } |
| 217 | 224 | |
| 218 | −static int pxa27x_keypad_rotary_parse_dt(struct pxa27x_keypad *keypad, | |
| 219 | − struct pxa27x_keypad_platform_data *pdata) | |
| 225 | +static int pxa27x_keypad_rotary_parse(struct pxa27x_keypad *keypad) | |
| 220 | 226 | { |
| 221 | − const __be32 *prop; | |
| 222 | − int i, relkey_ret; | |
| 223 | − unsigned int code, proplen; | |
| 224 | − const char *rotaryname[2] = { | |
| 225 | − "marvell,rotary0", "marvell,rotary1"}; | |
| 226 | − const char relkeyname[] = {"marvell,rotary-rel-key"}; | |
| 227 | + static const char * const rotaryname[] = { "marvell,rotary0", "marvell,rotary1" }; | |
| 227 | 228 | struct input_dev *input_dev = keypad->input_dev; |
| 228 | 229 | struct device *dev = input_dev->dev.parent; |
| 229 | − struct device_node *np = dev->of_node; | |
| 230 | − | |
| 231 | − relkey_ret = of_property_read_u32(np, relkeyname, &code); | |
| 232 | − /* if can read correct rotary key-code, we do not need this. */ | |
| 233 | − if (relkey_ret == 0) { | |
| 234 | − unsigned short relcode; | |
| 230 | + struct pxa27x_keypad_rotary *encoder; | |
| 231 | + unsigned int code; | |
| 232 | + int i; | |
| 233 | + int error; | |
| 235 | 234 | |
| 236 | − /* rotary0 taks lower half, rotary1 taks upper half. */ | |
| 237 | − relcode = code & 0xffff; | |
| 238 | − pdata->rotary0_rel_code = (code & 0xffff); | |
| 239 | − __set_bit(relcode, input_dev->relbit); | |
| 235 | + error = device_property_read_u32(dev, "marvell,rotary-rel-key", &code); | |
| 236 | + if (!error) { | |
| 237 | + for (i = 0; i < MAX_ROTARY_ENCODERS; i++, code >>= 16) { | |
| 238 | + encoder = &keypad->rotary[i]; | |
| 239 | + encoder->enabled = true; | |
| 240 | + encoder->rel_code = code & 0xffff; | |
| 241 | + input_set_capability(input_dev, EV_REL, encoder->rel_code); | |
| 242 | + } | |
| 240 | 243 | |
| 241 | − relcode = code >> 16; | |
| 242 | − pdata->rotary1_rel_code = relcode; | |
| 243 | − __set_bit(relcode, input_dev->relbit); | |
| 244 | + return 0; | |
| 244 | 245 | } |
| 245 | 246 | |
| 246 | − for (i = 0; i < 2; i++) { | |
| 247 | − prop = of_get_property(np, rotaryname[i], &proplen); | |
| 247 | + for (i = 0; i < MAX_ROTARY_ENCODERS; i++) { | |
| 248 | + encoder = &keypad->rotary[i]; | |
| 249 | + | |
| 248 | 250 | /* |
| 249 | 251 | * If the prop is not set, it means keypad does not need |
| 250 | 252 | * initialize the rotaryX. |
| 251 | 253 | */ |
| 252 | − if (!prop) | |
| 254 | + if (!device_property_present(dev, rotaryname[i])) | |
| 253 | 255 | continue; |
| 254 | 256 | |
| 255 | − code = be32_to_cpup(prop); | |
| 257 | + error = device_property_read_u32(dev, rotaryname[i], &code); | |
| 258 | + if (error) | |
| 259 | + return error; | |
| 260 | + | |
| 256 | 261 | /* |
| 257 | 262 | * Not all up/down key code are valid. |
| 258 | 263 | * Now we depends on direct-rel-code. |
| 259 | 264 | */ |
| 260 | − if ((!(code & 0xffff) || !(code >> 16)) && relkey_ret) { | |
| 261 | − return relkey_ret; | |
| 262 | − } else { | |
| 263 | − unsigned int n = MAX_MATRIX_KEY_NUM + (i << 1); | |
| 264 | − unsigned short keycode; | |
| 265 | − | |
| 266 | − keycode = code & 0xffff; | |
| 267 | − keypad->keycodes[n] = keycode; | |
| 268 | − __set_bit(keycode, input_dev->keybit); | |
| 269 | − | |
| 270 | − keycode = code >> 16; | |
| 271 | − keypad->keycodes[n + 1] = keycode; | |
| 272 | − __set_bit(keycode, input_dev->keybit); | |
| 273 | − | |
| 274 | − if (i == 0) | |
| 275 | − pdata->rotary0_rel_code = -1; | |
| 276 | − else | |
| 277 | − pdata->rotary1_rel_code = -1; | |
| 278 | − } | |
| 279 | − if (i == 0) | |
| 280 | − pdata->enable_rotary0 = 1; | |
| 281 | − else | |
| 282 | − pdata->enable_rotary1 = 1; | |
| 283 | − } | |
| 265 | + if (!(code & 0xffff) || !(code >> 16)) | |
| 266 | + return -EINVAL; | |
| 267 | + | |
| 268 | + encoder->enabled = true; | |
| 269 | + encoder->rel_code = -1; | |
| 270 | + encoder->key_codes = &keypad->keycodes[MAX_MATRIX_KEY_NUM + i * 2]; | |
| 271 | + encoder->key_codes[0] = code & 0xffff; | |
| 272 | + encoder->key_codes[1] = code >> 16; | |
| 284 | 273 | |
| 285 | − keypad->rotary_rel_code[0] = pdata->rotary0_rel_code; | |
| 286 | − keypad->rotary_rel_code[1] = pdata->rotary1_rel_code; | |
| 274 | + input_set_capability(input_dev, EV_KEY, encoder->key_codes[0]); | |
| 275 | + input_set_capability(input_dev, EV_KEY, encoder->key_codes[1]); | |
| 276 | + } | |
| 287 | 277 | |
| 288 | 278 | return 0; |
| 289 | 279 | } |
| 290 | 280 | |
| 291 | −static int pxa27x_keypad_build_keycode_from_dt(struct pxa27x_keypad *keypad) | |
| 281 | +static int pxa27x_keypad_parse_properties(struct pxa27x_keypad *keypad) | |
| 292 | 282 | { |
| 293 | 283 | struct input_dev *input_dev = keypad->input_dev; |
| 294 | 284 | struct device *dev = input_dev->dev.parent; |
| 295 | − struct device_node *np = dev->of_node; | |
| 296 | − struct pxa27x_keypad_platform_data *pdata; | |
| 297 | 285 | int error; |
| 298 | 286 | |
| 299 | − pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL); | |
| 300 | − if (!pdata) { | |
| 301 | − dev_err(dev, "failed to allocate memory for pdata\n"); | |
| 302 | − return -ENOMEM; | |
| 303 | − } | |
| 304 | − | |
| 305 | − error = pxa27x_keypad_matrix_key_parse_dt(keypad, pdata); | |
| 287 | + error = pxa27x_keypad_matrix_key_parse(keypad); | |
| 306 | 288 | if (error) { |
| 307 | 289 | dev_err(dev, "failed to parse matrix key\n"); |
| 308 | 290 | return error; |
| 309 | 291 | } |
| 310 | 292 | |
| 311 | − error = pxa27x_keypad_direct_key_parse_dt(keypad, pdata); | |
| 293 | + error = pxa27x_keypad_direct_key_parse(keypad); | |
| 312 | 294 | if (error) { |
| 313 | 295 | dev_err(dev, "failed to parse direct key\n"); |
| 314 | 296 | return error; |
| 315 | 297 | } |
| 316 | 298 | |
| 317 | − error = pxa27x_keypad_rotary_parse_dt(keypad, pdata); | |
| 299 | + error = pxa27x_keypad_rotary_parse(keypad); | |
| 318 | 300 | if (error) { |
| 319 | 301 | dev_err(dev, "failed to parse rotary key\n"); |
| 320 | 302 | return error; |
| 321 | 303 | } |
| 322 | 304 | |
| 323 | − error = of_property_read_u32(np, "marvell,debounce-interval", | |
| 324 | − &pdata->debounce_interval); | |
| 305 | + error = device_property_read_u32(dev, "marvell,debounce-interval", | |
| 306 | + &keypad->debounce_interval); | |
| 325 | 307 | if (error) { |
| 326 | 308 | dev_err(dev, "failed to parse debounce-interval\n"); |
| 327 | 309 | return error; |
| @@ -333,91 +315,11 @@ static int pxa27x_keypad_build_keycode_from_dt(struct pxa27x_keypad *keypad) · 5 unmodified lines | ||
| 333 | 315 | */ |
| 334 | 316 | input_dev->keycodemax = ARRAY_SIZE(keypad->keycodes); |
| 335 | 317 | |
| 336 | − keypad->pdata = pdata; | |
| 337 | − return 0; | |
| 338 | −} | |
| 339 | − | |
| 340 | −#else | |
| 341 | − | |
| 342 | −static int pxa27x_keypad_build_keycode_from_dt(struct pxa27x_keypad *keypad) | |
| 343 | −{ | |
| 344 | − dev_info(keypad->input_dev->dev.parent, "missing platform data\n"); | |
| 345 | − | |
| 346 | − return -EINVAL; | |
| 347 | −} | |
| 348 | − | |
| 349 | −#endif | |
| 350 | − | |
| 351 | −static int pxa27x_keypad_build_keycode(struct pxa27x_keypad *keypad) | |
| 352 | −{ | |
| 353 | − const struct pxa27x_keypad_platform_data *pdata = keypad->pdata; | |
| 354 | − struct input_dev *input_dev = keypad->input_dev; | |
| 355 | − unsigned short keycode; | |
| 356 | − int i; | |
| 357 | − int error; | |
| 358 | − | |
| 359 | − error = matrix_keypad_build_keymap(pdata->matrix_keymap_data, NULL, | |
| 360 | − pdata->matrix_key_rows, | |
| 361 | − pdata->matrix_key_cols, | |
| 362 | − keypad->keycodes, input_dev); | |
| 363 | − if (error) | |
| 364 | − return error; | |
| 365 | − | |
| 366 | − /* | |
| 367 | − * The keycodes may not only include matrix keys but also the direct | |
| 368 | − * or rotary keys. | |
| 369 | − */ | |
| 370 | − input_dev->keycodemax = ARRAY_SIZE(keypad->keycodes); | |
| 371 | − | |
| 372 | − /* For direct keys. */ | |
| 373 | − for (i = 0; i < pdata->direct_key_num; i++) { | |
| 374 | − keycode = pdata->direct_key_map[i]; | |
| 375 | − keypad->keycodes[MAX_MATRIX_KEY_NUM + i] = keycode; | |
| 376 | − __set_bit(keycode, input_dev->keybit); | |
| 377 | − } | |
| 378 | − | |
| 379 | − if (pdata->enable_rotary0) { | |
| 380 | − if (pdata->rotary0_up_key && pdata->rotary0_down_key) { | |
| 381 | − keycode = pdata->rotary0_up_key; | |
| 382 | − keypad->keycodes[MAX_MATRIX_KEY_NUM + 0] = keycode; | |
| 383 | − __set_bit(keycode, input_dev->keybit); | |
| 384 | − | |
| 385 | − keycode = pdata->rotary0_down_key; | |
| 386 | − keypad->keycodes[MAX_MATRIX_KEY_NUM + 1] = keycode; | |
| 387 | − __set_bit(keycode, input_dev->keybit); | |
| 388 | − | |
| 389 | − keypad->rotary_rel_code[0] = -1; | |
| 390 | − } else { | |
| 391 | − keypad->rotary_rel_code[0] = pdata->rotary0_rel_code; | |
| 392 | − __set_bit(pdata->rotary0_rel_code, input_dev->relbit); | |
| 393 | − } | |
| 394 | − } | |
| 395 | − | |
| 396 | − if (pdata->enable_rotary1) { | |
| 397 | − if (pdata->rotary1_up_key && pdata->rotary1_down_key) { | |
| 398 | − keycode = pdata->rotary1_up_key; | |
| 399 | − keypad->keycodes[MAX_MATRIX_KEY_NUM + 2] = keycode; | |
| 400 | − __set_bit(keycode, input_dev->keybit); | |
| 401 | − | |
| 402 | − keycode = pdata->rotary1_down_key; | |
| 403 | − keypad->keycodes[MAX_MATRIX_KEY_NUM + 3] = keycode; | |
| 404 | − __set_bit(keycode, input_dev->keybit); | |
| 405 | − | |
| 406 | − keypad->rotary_rel_code[1] = -1; | |
| 407 | − } else { | |
| 408 | − keypad->rotary_rel_code[1] = pdata->rotary1_rel_code; | |
| 409 | − __set_bit(pdata->rotary1_rel_code, input_dev->relbit); | |
| 410 | − } | |
| 411 | − } | |
| 412 | − | |
| 413 | − __clear_bit(KEY_RESERVED, input_dev->keybit); | |
| 414 | − | |
| 415 | 318 | return 0; |
| 416 | 319 | } |
| 417 | 320 | |
| 418 | 321 | static void pxa27x_keypad_scan_matrix(struct pxa27x_keypad *keypad) |
| 419 | 322 | { |
| 420 | − const struct pxa27x_keypad_platform_data *pdata = keypad->pdata; | |
| 421 | 323 | struct input_dev *input_dev = keypad->input_dev; |
| 422 | 324 | int row, col, num_keys_pressed = 0; |
| 423 | 325 | u32 new_state[MAX_MATRIX_KEY_COLS]; |
| @@ -435,8 +337,8 @@ static void pxa27x_keypad_scan_matrix(struct pxa27x_keypad *keypad) · 11 unmodified lines | ||
| 435 | 337 | row = KPAS_RP(kpas); |
| 436 | 338 | |
| 437 | 339 | /* if invalid row/col, treat as no key pressed */ |
| 438 | − if (col >= pdata->matrix_key_cols || | |
| 439 | − row >= pdata->matrix_key_rows) | |
| 340 | + if (col >= keypad->matrix_key_cols || | |
| 341 | + row >= keypad->matrix_key_rows) | |
| 440 | 342 | goto scan; |
| 441 | 343 | |
| 442 | 344 | new_state[col] = BIT(row); |
| @@ -459,7 +361,7 @@ static void pxa27x_keypad_scan_matrix(struct pxa27x_keypad *keypad) · 16 unmodified lines | ||
| 459 | 361 | new_state[7] = (kpasmkp3 >> 16) & KPASMKP_MKC_MASK; |
| 460 | 362 | } |
| 461 | 363 | scan: |
| 462 | − for (col = 0; col < pdata->matrix_key_cols; col++) { | |
| 364 | + for (col = 0; col < keypad->matrix_key_cols; col++) { | |
| 463 | 365 | u32 bits_changed; |
| 464 | 366 | int code; |
| 465 | 367 | |
| @@ -467,7 +369,7 @@ scan: · 1 unmodified line | ||
| 467 | 369 | if (bits_changed == 0) |
| 468 | 370 | continue; |
| 469 | 371 | |
| 470 | − for (row = 0; row < pdata->matrix_key_rows; row++) { | |
| 372 | + for (row = 0; row < keypad->matrix_key_rows; row++) { | |
| 471 | 373 | if ((bits_changed & BIT(row)) == 0) |
| 472 | 374 | continue; |
| 473 | 375 | |
| @@ -496,14 +398,16 @@ static inline int rotary_delta(u32 kprec) · 22 unmodified lines | ||
| 496 | 398 | |
| 497 | 399 | static void report_rotary_event(struct pxa27x_keypad *keypad, int r, int delta) |
| 498 | 400 | { |
| 401 | + struct pxa27x_keypad_rotary *encoder = &keypad->rotary[r]; | |
| 499 | 402 | struct input_dev *dev = keypad->input_dev; |
| 500 | 403 | |
| 501 | − if (delta == 0) | |
| 404 | + if (!encoder->enabled || delta == 0) | |
| 502 | 405 | return; |
| 503 | 406 | |
| 504 | − if (keypad->rotary_rel_code[r] == -1) { | |
| 505 | − int code = MAX_MATRIX_KEY_NUM + 2 * r + (delta > 0 ? 0 : 1); | |
| 506 | − unsigned char keycode = keypad->keycodes[code]; | |
| 407 | + if (encoder->rel_code == -1) { | |
| 408 | + int idx = delta > 0 ? 0 : 1; | |
| 409 | + int code = MAX_MATRIX_KEY_NUM + 2 * r + idx; | |
| 410 | + unsigned char keycode = encoder->key_codes[idx]; | |
| 507 | 411 | |
| 508 | 412 | /* simulate a press-n-release */ |
| 509 | 413 | input_event(dev, EV_MSC, MSC_SCAN, code); |
| @@ -513,30 +417,28 @@ static void report_rotary_event(struct pxa27x_keypad *keypad, int r, int delta) · 3 unmodified lines | ||
| 513 | 417 | input_report_key(dev, keycode, 0); |
| 514 | 418 | input_sync(dev); |
| 515 | 419 | } else { |
| 516 | − input_report_rel(dev, keypad->rotary_rel_code[r], delta); | |
| 420 | + input_report_rel(dev, encoder->rel_code, delta); | |
| 517 | 421 | input_sync(dev); |
| 518 | 422 | } |
| 519 | 423 | } |
| 520 | 424 | |
| 521 | 425 | static void pxa27x_keypad_scan_rotary(struct pxa27x_keypad *keypad) |
| 522 | 426 | { |
| 523 | − const struct pxa27x_keypad_platform_data *pdata = keypad->pdata; | |
| 524 | 427 | u32 kprec; |
| 428 | + int i; | |
| 525 | 429 | |
| 526 | 430 | /* read and reset to default count value */ |
| 527 | 431 | kprec = keypad_readl(KPREC); |
| 528 | 432 | keypad_writel(KPREC, DEFAULT_KPREC); |
| 529 | 433 | |
| 530 | − if (pdata->enable_rotary0) | |
| 434 | + for (i = 0; i < MAX_ROTARY_ENCODERS; i++) { | |
| 531 | 435 | report_rotary_event(keypad, 0, rotary_delta(kprec)); |
| 532 | − | |
| 533 | − if (pdata->enable_rotary1) | |
| 534 | − report_rotary_event(keypad, 1, rotary_delta(kprec >> 16)); | |
| 436 | + kprec >>= 16; | |
| 437 | + } | |
| 535 | 438 | } |
| 536 | 439 | |
| 537 | 440 | static void pxa27x_keypad_scan_direct(struct pxa27x_keypad *keypad) |
| 538 | 441 | { |
| 539 | − const struct pxa27x_keypad_platform_data *pdata = keypad->pdata; | |
| 540 | 442 | struct input_dev *input_dev = keypad->input_dev; |
| 541 | 443 | unsigned int new_state; |
| 542 | 444 | u32 kpdk, bits_changed; |
| @@ -544,14 +446,14 @@ static void pxa27x_keypad_scan_direct(struct pxa27x_keypad *keypad) · 1 unmodified line | ||
| 544 | 446 | |
| 545 | 447 | kpdk = keypad_readl(KPDK); |
| 546 | 448 | |
| 547 | − if (pdata->enable_rotary0 || pdata->enable_rotary1) | |
| 449 | + if (keypad->rotary[0].enabled || keypad->rotary[1].enabled) | |
| 548 | 450 | pxa27x_keypad_scan_rotary(keypad); |
| 549 | 451 | |
| 550 | 452 | /* |
| 551 | 453 | * The KPDR_DK only output the key pin level, so it relates to board, |
| 552 | 454 | * and low level may be active. |
| 553 | 455 | */ |
| 554 | − if (pdata->direct_key_low_active) | |
| 456 | + if (keypad->direct_key_low_active) | |
| 555 | 457 | new_state = ~KPDK_DK(kpdk) & keypad->direct_key_mask; |
| 556 | 458 | else |
| 557 | 459 | new_state = KPDK_DK(kpdk) & keypad->direct_key_mask; |
| @@ -561,7 +463,7 @@ static void pxa27x_keypad_scan_direct(struct pxa27x_keypad *keypad) · 3 unmodified lines | ||
| 561 | 463 | if (bits_changed == 0) |
| 562 | 464 | return; |
| 563 | 465 | |
| 564 | − for (i = 0; i < pdata->direct_key_num; i++) { | |
| 466 | + for (i = 0; i < keypad->direct_key_num; i++) { | |
| 565 | 467 | if (bits_changed & BIT(i)) { |
| 566 | 468 | int code = MAX_MATRIX_KEY_NUM + i; |
| 567 | 469 | |
| @@ -574,21 +476,11 @@ static void pxa27x_keypad_scan_direct(struct pxa27x_keypad *keypad) · 6 unmodified lines | ||
| 574 | 476 | keypad->direct_key_state = new_state; |
| 575 | 477 | } |
| 576 | 478 | |
| 577 | −static void clear_wakeup_event(struct pxa27x_keypad *keypad) | |
| 578 | −{ | |
| 579 | − const struct pxa27x_keypad_platform_data *pdata = keypad->pdata; | |
| 580 | − | |
| 581 | − if (pdata->clear_wakeup_event) | |
| 582 | − (pdata->clear_wakeup_event)(); | |
| 583 | −} | |
| 584 | − | |
| 585 | 479 | static irqreturn_t pxa27x_keypad_irq_handler(int irq, void *dev_id) |
| 586 | 480 | { |
| 587 | 481 | struct pxa27x_keypad *keypad = dev_id; |
| 588 | 482 | unsigned long kpc = keypad_readl(KPC); |
| 589 | 483 | |
| 590 | − clear_wakeup_event(keypad); | |
| 591 | − | |
| 592 | 484 | if (kpc & KPC_DI) |
| 593 | 485 | pxa27x_keypad_scan_direct(keypad); |
| 594 | 486 | |
| @@ -600,7 +492,6 @@ static irqreturn_t pxa27x_keypad_irq_handler(int irq, void *dev_id) · 5 unmodified lines | ||
| 600 | 492 | |
| 601 | 493 | static void pxa27x_keypad_config(struct pxa27x_keypad *keypad) |
| 602 | 494 | { |
| 603 | − const struct pxa27x_keypad_platform_data *pdata = keypad->pdata; | |
| 604 | 495 | unsigned int mask = 0, direct_key_num = 0; |
| 605 | 496 | unsigned long kpc = 0; |
| 606 | 497 | |
| @@ -608,35 +499,33 @@ static void pxa27x_keypad_config(struct pxa27x_keypad *keypad) · 1 unmodified line | ||
| 608 | 499 | keypad_readl(KPC); |
| 609 | 500 | |
| 610 | 501 | /* enable matrix keys with automatic scan */ |
| 611 | − if (pdata->matrix_key_rows && pdata->matrix_key_cols) { | |
| 502 | + if (keypad->matrix_key_rows && keypad->matrix_key_cols) { | |
| 612 | 503 | kpc |= KPC_ASACT | KPC_MIE | KPC_ME | KPC_MS_ALL; |
| 613 | − kpc |= KPC_MKRN(pdata->matrix_key_rows) | | |
| 614 | − KPC_MKCN(pdata->matrix_key_cols); | |
| 504 | + kpc |= KPC_MKRN(keypad->matrix_key_rows) | | |
| 505 | + KPC_MKCN(keypad->matrix_key_cols); | |
| 615 | 506 | } |
| 616 | 507 | |
| 617 | 508 | /* enable rotary key, debounce interval same as direct keys */ |
| 618 | − if (pdata->enable_rotary0) { | |
| 509 | + if (keypad->rotary[0].enabled) { | |
| 619 | 510 | mask |= 0x03; |
| 620 | 511 | direct_key_num = 2; |
| 621 | 512 | kpc |= KPC_REE0; |
| 622 | 513 | } |
| 623 | 514 | |
| 624 | − if (pdata->enable_rotary1) { | |
| 515 | + if (keypad->rotary[1].enabled) { | |
| 625 | 516 | mask |= 0x0c; |
| 626 | 517 | direct_key_num = 4; |
| 627 | 518 | kpc |= KPC_REE1; |
| 628 | 519 | } |
| 629 | 520 | |
| 630 | − if (pdata->direct_key_num > direct_key_num) | |
| 631 | − direct_key_num = pdata->direct_key_num; | |
| 521 | + if (keypad->direct_key_num > direct_key_num) | |
| 522 | + direct_key_num = keypad->direct_key_num; | |
| 632 | 523 | |
| 633 | 524 | /* |
| 634 | 525 | * Direct keys usage may not start from KP_DKIN0, check the platfrom |
| 635 | 526 | * mask data to config the specific. |
| 636 | 527 | */ |
| 637 | − if (pdata->direct_key_mask) | |
| 638 | − keypad->direct_key_mask = pdata->direct_key_mask; | |
| 639 | − else | |
| 528 | + if (!keypad->direct_key_mask) | |
| 640 | 529 | keypad->direct_key_mask = GENMASK(direct_key_num - 1, 0) & ~mask; |
| 641 | 530 | |
| 642 | 531 | /* enable direct key */ |
| @@ -645,7 +534,7 @@ static void pxa27x_keypad_config(struct pxa27x_keypad *keypad) · 2 unmodified lines | ||
| 645 | 534 | |
| 646 | 535 | keypad_writel(KPC, kpc | KPC_RE_ZERO_DEB); |
| 647 | 536 | keypad_writel(KPREC, DEFAULT_KPREC); |
| 648 | − keypad_writel(KPKDI, pdata->debounce_interval); | |
| 537 | + keypad_writel(KPKDI, keypad->debounce_interval); | |
| 649 | 538 | } |
| 650 | 539 | |
| 651 | 540 | static int pxa27x_keypad_open(struct input_dev *dev) |
| @@ -719,19 +608,12 @@ static int pxa27x_keypad_resume(struct device *dev) · 67 unmodified lines | ||
| 719 | 608 | static DEFINE_SIMPLE_DEV_PM_OPS(pxa27x_keypad_pm_ops, |
| 720 | 609 | pxa27x_keypad_suspend, pxa27x_keypad_resume); |
| 721 | 610 | |
| 722 | − | |
| 723 | 611 | static int pxa27x_keypad_probe(struct platform_device *pdev) |
| 724 | 612 | { |
| 725 | − const struct pxa27x_keypad_platform_data *pdata = | |
| 726 | − dev_get_platdata(&pdev->dev); | |
| 727 | − struct device_node *np = pdev->dev.of_node; | |
| 728 | 613 | struct pxa27x_keypad *keypad; |
| 729 | 614 | struct input_dev *input_dev; |
| 730 | − int irq, error; | |
| 731 | − | |
| 732 | − /* Driver need build keycode from device tree or pdata */ | |
| 733 | − if (!np && !pdata) | |
| 734 | − return -EINVAL; | |
| 615 | + int irq; | |
| 616 | + int error; | |
| 735 | 617 | |
| 736 | 618 | irq = platform_get_irq(pdev, 0); |
| 737 | 619 | if (irq < 0) |
| @@ -746,7 +628,6 @@ static int pxa27x_keypad_probe(struct platform_device *pdev) · 8 unmodified lines | ||
| 746 | 628 | if (!input_dev) |
| 747 | 629 | return -ENOMEM; |
| 748 | 630 | |
| 749 | − keypad->pdata = pdata; | |
| 750 | 631 | keypad->input_dev = input_dev; |
| 751 | 632 | keypad->irq = irq; |
| 752 | 633 | |
| @@ -775,29 +656,12 @@ static int pxa27x_keypad_probe(struct platform_device *pdev) · 22 unmodified lines | ||
| 775 | 656 | input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REP); |
| 776 | 657 | input_set_capability(input_dev, EV_MSC, MSC_SCAN); |
| 777 | 658 | |
| 778 | − if (pdata) { | |
| 779 | − error = pxa27x_keypad_build_keycode(keypad); | |
| 780 | − } else { | |
| 781 | − error = pxa27x_keypad_build_keycode_from_dt(keypad); | |
| 782 | − /* | |
| 783 | − * Data that we get from DT resides in dynamically | |
| 784 | − * allocated memory so we need to update our pdata | |
| 785 | − * pointer. | |
| 786 | − */ | |
| 787 | − pdata = keypad->pdata; | |
| 788 | − } | |
| 659 | + error = pxa27x_keypad_parse_properties(keypad); | |
| 789 | 660 | if (error) { |
| 790 | − dev_err(&pdev->dev, "failed to build keycode\n"); | |
| 661 | + dev_err(&pdev->dev, "failed to parse keypad properties\n"); | |
| 791 | 662 | return error; |
| 792 | 663 | } |
| 793 | 664 | |
| 794 | − keypad->row_shift = get_count_order(pdata->matrix_key_cols); | |
| 795 | − | |
| 796 | − if ((pdata->enable_rotary0 && keypad->rotary_rel_code[0] != -1) || | |
| 797 | − (pdata->enable_rotary1 && keypad->rotary_rel_code[1] != -1)) { | |
| 798 | − input_dev->evbit[0] |= BIT_MASK(EV_REL); | |
| 799 | − } | |
| 800 | − | |
| 801 | 665 | error = devm_request_irq(&pdev->dev, irq, pxa27x_keypad_irq_handler, |
| 802 | 666 | 0, pdev->name, keypad); |
| 803 | 667 | if (error) { |
| @@ -1,73 +0,0 @@ | ||
| 1 | −/* SPDX-License-Identifier: GPL-2.0 */ | |
| 2 | −#ifndef __ASM_ARCH_PXA27x_KEYPAD_H | |
| 3 | −#define __ASM_ARCH_PXA27x_KEYPAD_H | |
| 4 | − | |
| 5 | −#include <linux/input.h> | |
| 6 | −#include <linux/input/matrix_keypad.h> | |
| 7 | − | |
| 8 | −#define MAX_MATRIX_KEY_ROWS (8) | |
| 9 | −#define MAX_MATRIX_KEY_COLS (8) | |
| 10 | −#define MATRIX_ROW_SHIFT (3) | |
| 11 | −#define MAX_DIRECT_KEY_NUM (8) | |
| 12 | − | |
| 13 | −/* pxa3xx keypad platform specific parameters | |
| 14 | − * | |
| 15 | − * NOTE: | |
| 16 | − * 1. direct_key_num indicates the number of keys in the direct keypad | |
| 17 | − * _plus_ the number of rotary-encoder sensor inputs, this can be | |
| 18 | − * left as 0 if only rotary encoders are enabled, the driver will | |
| 19 | − * automatically calculate this | |
| 20 | − * | |
| 21 | − * 2. direct_key_map is the key code map for the direct keys, if rotary | |
| 22 | − * encoder(s) are enabled, direct key 0/1(2/3) will be ignored | |
| 23 | − * | |
| 24 | − * 3. rotary can be either interpreted as a relative input event (e.g. | |
| 25 | − * REL_WHEEL/REL_HWHEEL) or specific keys (e.g. UP/DOWN/LEFT/RIGHT) | |
| 26 | − * | |
| 27 | − * 4. matrix key and direct key will use the same debounce_interval by | |
| 28 | − * default, which should be sufficient in most cases | |
| 29 | − * | |
| 30 | − * pxa168 keypad platform specific parameter | |
| 31 | − * | |
| 32 | − * NOTE: | |
| 33 | − * clear_wakeup_event callback is a workaround required to clear the | |
| 34 | − * keypad interrupt. The keypad wake must be cleared in addition to | |
| 35 | − * reading the MI/DI bits in the KPC register. | |
| 36 | − */ | |
| 37 | −struct pxa27x_keypad_platform_data { | |
| 38 | − | |
| 39 | − /* code map for the matrix keys */ | |
| 40 | − const struct matrix_keymap_data *matrix_keymap_data; | |
| 41 | − unsigned int matrix_key_rows; | |
| 42 | − unsigned int matrix_key_cols; | |
| 43 | − | |
| 44 | − /* direct keys */ | |
| 45 | − int direct_key_num; | |
| 46 | − unsigned int direct_key_map[MAX_DIRECT_KEY_NUM]; | |
| 47 | − /* the key output may be low active */ | |
| 48 | − int direct_key_low_active; | |
| 49 | − /* give board a chance to choose the start direct key */ | |
| 50 | − unsigned int direct_key_mask; | |
| 51 | − | |
| 52 | − /* rotary encoders 0 */ | |
| 53 | − int enable_rotary0; | |
| 54 | − int rotary0_rel_code; | |
| 55 | − int rotary0_up_key; | |
| 56 | − int rotary0_down_key; | |
| 57 | − | |
| 58 | − /* rotary encoders 1 */ | |
| 59 | − int enable_rotary1; | |
| 60 | − int rotary1_rel_code; | |
| 61 | − int rotary1_up_key; | |
| 62 | − int rotary1_down_key; | |
| 63 | − | |
| 64 | − /* key debounce interval */ | |
| 65 | − unsigned int debounce_interval; | |
| 66 | − | |
| 67 | − /* clear wakeup event requirement for pxa168 */ | |
| 68 | − void (*clear_wakeup_event)(void); | |
| 69 | −}; | |
| 70 | − | |
| 71 | −extern void pxa_set_keypad_info(struct pxa27x_keypad_platform_data *info); | |
| 72 | − | |
| 73 | −#endif /* __ASM_ARCH_PXA27x_KEYPAD_H */ | |