^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0+
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Azoteq IQS620A/621/622/624/625 Keys and Switches
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright (C) 2019 Jeff LaBundy <jeff@labundy.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #include <linux/device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include <linux/input.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/mfd/iqs62x.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/notifier.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/platform_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/property.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/regmap.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) enum {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) IQS62X_SW_HALL_N,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) IQS62X_SW_HALL_S,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) static const char * const iqs62x_switch_names[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) [IQS62X_SW_HALL_N] = "hall-switch-north",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) [IQS62X_SW_HALL_S] = "hall-switch-south",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) struct iqs62x_switch_desc {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) enum iqs62x_event_flag flag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) unsigned int code;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) bool enabled;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) struct iqs62x_keys_private {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) struct iqs62x_core *iqs62x;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) struct input_dev *input;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) struct notifier_block notifier;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) struct iqs62x_switch_desc switches[ARRAY_SIZE(iqs62x_switch_names)];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) unsigned int keycode[IQS62X_NUM_KEYS];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) unsigned int keycodemax;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) u8 interval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) static int iqs62x_keys_parse_prop(struct platform_device *pdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) struct iqs62x_keys_private *iqs62x_keys)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) struct fwnode_handle *child;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) unsigned int val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) int ret, i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) ret = device_property_count_u32(&pdev->dev, "linux,keycodes");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) if (ret > IQS62X_NUM_KEYS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) dev_err(&pdev->dev, "Too many keycodes present\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) } else if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) dev_err(&pdev->dev, "Failed to count keycodes: %d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) iqs62x_keys->keycodemax = ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) ret = device_property_read_u32_array(&pdev->dev, "linux,keycodes",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) iqs62x_keys->keycode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) iqs62x_keys->keycodemax);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) dev_err(&pdev->dev, "Failed to read keycodes: %d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) for (i = 0; i < ARRAY_SIZE(iqs62x_keys->switches); i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) child = device_get_named_child_node(&pdev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) iqs62x_switch_names[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) if (!child)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) ret = fwnode_property_read_u32(child, "linux,code", &val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) dev_err(&pdev->dev, "Failed to read switch code: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) iqs62x_keys->switches[i].code = val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) iqs62x_keys->switches[i].enabled = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) if (fwnode_property_present(child, "azoteq,use-prox"))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) iqs62x_keys->switches[i].flag = (i == IQS62X_SW_HALL_N ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) IQS62X_EVENT_HALL_N_P :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) IQS62X_EVENT_HALL_S_P);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) iqs62x_keys->switches[i].flag = (i == IQS62X_SW_HALL_N ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) IQS62X_EVENT_HALL_N_T :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) IQS62X_EVENT_HALL_S_T);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) static int iqs62x_keys_init(struct iqs62x_keys_private *iqs62x_keys)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) struct iqs62x_core *iqs62x = iqs62x_keys->iqs62x;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) enum iqs62x_event_flag flag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) unsigned int event_reg, val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) unsigned int event_mask = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) int ret, i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) switch (iqs62x->dev_desc->prod_num) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) case IQS620_PROD_NUM:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) case IQS621_PROD_NUM:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) case IQS622_PROD_NUM:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) event_reg = IQS620_GLBL_EVENT_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) * Discreet button, hysteresis and SAR UI flags represent keys
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) * and are unmasked if mapped to a valid keycode.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) for (i = 0; i < iqs62x_keys->keycodemax; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) if (iqs62x_keys->keycode[i] == KEY_RESERVED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) if (iqs62x_events[i].reg == IQS62X_EVENT_PROX)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) event_mask |= iqs62x->dev_desc->prox_mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) else if (iqs62x_events[i].reg == IQS62X_EVENT_HYST)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) event_mask |= (iqs62x->dev_desc->hyst_mask |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) iqs62x->dev_desc->sar_mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) ret = regmap_read(iqs62x->regmap, iqs62x->dev_desc->hall_flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) &val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) * Hall UI flags represent switches and are unmasked if their
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) * corresponding child nodes are present.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) for (i = 0; i < ARRAY_SIZE(iqs62x_keys->switches); i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) if (!(iqs62x_keys->switches[i].enabled))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) flag = iqs62x_keys->switches[i].flag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) if (iqs62x_events[flag].reg != IQS62X_EVENT_HALL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) event_mask |= iqs62x->dev_desc->hall_mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) input_report_switch(iqs62x_keys->input,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) iqs62x_keys->switches[i].code,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) (val & iqs62x_events[flag].mask) ==
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) iqs62x_events[flag].val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) input_sync(iqs62x_keys->input);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) case IQS624_PROD_NUM:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) event_reg = IQS624_HALL_UI;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) * Interval change events represent keys and are unmasked if
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) * either wheel movement flag is mapped to a valid keycode.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) if (iqs62x_keys->keycode[IQS62X_EVENT_WHEEL_UP] != KEY_RESERVED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) event_mask |= IQS624_HALL_UI_INT_EVENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) if (iqs62x_keys->keycode[IQS62X_EVENT_WHEEL_DN] != KEY_RESERVED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) event_mask |= IQS624_HALL_UI_INT_EVENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) ret = regmap_read(iqs62x->regmap, iqs62x->dev_desc->interval,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) &val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) iqs62x_keys->interval = val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) return regmap_update_bits(iqs62x->regmap, event_reg, event_mask, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) static int iqs62x_keys_notifier(struct notifier_block *notifier,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) unsigned long event_flags, void *context)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) struct iqs62x_event_data *event_data = context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) struct iqs62x_keys_private *iqs62x_keys;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) int ret, i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) iqs62x_keys = container_of(notifier, struct iqs62x_keys_private,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) notifier);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) if (event_flags & BIT(IQS62X_EVENT_SYS_RESET)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) ret = iqs62x_keys_init(iqs62x_keys);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) dev_err(iqs62x_keys->input->dev.parent,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) "Failed to re-initialize device: %d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) return NOTIFY_BAD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) return NOTIFY_OK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) for (i = 0; i < iqs62x_keys->keycodemax; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) if (iqs62x_events[i].reg == IQS62X_EVENT_WHEEL &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) event_data->interval == iqs62x_keys->interval)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) input_report_key(iqs62x_keys->input, iqs62x_keys->keycode[i],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) event_flags & BIT(i));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) for (i = 0; i < ARRAY_SIZE(iqs62x_keys->switches); i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) if (iqs62x_keys->switches[i].enabled)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) input_report_switch(iqs62x_keys->input,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) iqs62x_keys->switches[i].code,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) event_flags &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) BIT(iqs62x_keys->switches[i].flag));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) input_sync(iqs62x_keys->input);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) if (event_data->interval == iqs62x_keys->interval)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) return NOTIFY_OK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) * Each frame contains at most one wheel event (up or down), in which
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) * case a complementary release cycle is emulated.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) if (event_flags & BIT(IQS62X_EVENT_WHEEL_UP)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) input_report_key(iqs62x_keys->input,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) iqs62x_keys->keycode[IQS62X_EVENT_WHEEL_UP],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) input_sync(iqs62x_keys->input);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) } else if (event_flags & BIT(IQS62X_EVENT_WHEEL_DN)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) input_report_key(iqs62x_keys->input,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) iqs62x_keys->keycode[IQS62X_EVENT_WHEEL_DN],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) input_sync(iqs62x_keys->input);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) iqs62x_keys->interval = event_data->interval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) return NOTIFY_OK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) static int iqs62x_keys_probe(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) struct iqs62x_core *iqs62x = dev_get_drvdata(pdev->dev.parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) struct iqs62x_keys_private *iqs62x_keys;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) struct input_dev *input;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) int ret, i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) iqs62x_keys = devm_kzalloc(&pdev->dev, sizeof(*iqs62x_keys),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) if (!iqs62x_keys)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) platform_set_drvdata(pdev, iqs62x_keys);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) ret = iqs62x_keys_parse_prop(pdev, iqs62x_keys);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) input = devm_input_allocate_device(&pdev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) if (!input)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) input->keycodemax = iqs62x_keys->keycodemax;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) input->keycode = iqs62x_keys->keycode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) input->keycodesize = sizeof(*iqs62x_keys->keycode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) input->name = iqs62x->dev_desc->dev_name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) input->id.bustype = BUS_I2C;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) for (i = 0; i < iqs62x_keys->keycodemax; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) if (iqs62x_keys->keycode[i] != KEY_RESERVED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) input_set_capability(input, EV_KEY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) iqs62x_keys->keycode[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) for (i = 0; i < ARRAY_SIZE(iqs62x_keys->switches); i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) if (iqs62x_keys->switches[i].enabled)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) input_set_capability(input, EV_SW,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) iqs62x_keys->switches[i].code);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) iqs62x_keys->iqs62x = iqs62x;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) iqs62x_keys->input = input;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) ret = iqs62x_keys_init(iqs62x_keys);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) dev_err(&pdev->dev, "Failed to initialize device: %d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) ret = input_register_device(iqs62x_keys->input);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) dev_err(&pdev->dev, "Failed to register device: %d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) iqs62x_keys->notifier.notifier_call = iqs62x_keys_notifier;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) ret = blocking_notifier_chain_register(&iqs62x_keys->iqs62x->nh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) &iqs62x_keys->notifier);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) dev_err(&pdev->dev, "Failed to register notifier: %d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) static int iqs62x_keys_remove(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) struct iqs62x_keys_private *iqs62x_keys = platform_get_drvdata(pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) ret = blocking_notifier_chain_unregister(&iqs62x_keys->iqs62x->nh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) &iqs62x_keys->notifier);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) dev_err(&pdev->dev, "Failed to unregister notifier: %d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) static struct platform_driver iqs62x_keys_platform_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) .driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) .name = "iqs62x-keys",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) .probe = iqs62x_keys_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) .remove = iqs62x_keys_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) module_platform_driver(iqs62x_keys_platform_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) MODULE_AUTHOR("Jeff LaBundy <jeff@labundy.com>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) MODULE_DESCRIPTION("Azoteq IQS620A/621/622/624/625 Keys and Switches");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) MODULE_ALIAS("platform:iqs62x-keys");