Lines Matching +full:linux +full:- +full:keycodes
1 // SPDX-License-Identifier: GPL-2.0-only
8 #include <linux/bitmap.h>
9 #include <linux/bitops.h>
10 #include <linux/device.h>
11 #include <linux/i2c.h>
12 #include <linux/input.h>
13 #include <linux/interrupt.h>
14 #include <linux/module.h>
15 #include <linux/pm.h>
16 #include <linux/regulator/consumer.h>
18 #define CYPRESS_SF_DEV_NAME "cypress-sf"
26 u32 *keycodes; member
38 val = i2c_smbus_read_byte_data(touchkey->client, in cypress_sf_irq_handler()
41 dev_err(&touchkey->client->dev, in cypress_sf_irq_handler()
47 bitmap_xor(&changed, &keystates, &touchkey->keystates, in cypress_sf_irq_handler()
48 touchkey->num_keys); in cypress_sf_irq_handler()
50 for_each_set_bit(key, &changed, touchkey->num_keys) { in cypress_sf_irq_handler()
52 dev_dbg(&touchkey->client->dev, in cypress_sf_irq_handler()
54 input_report_key(touchkey->input_dev, in cypress_sf_irq_handler()
55 touchkey->keycodes[key], new_state); in cypress_sf_irq_handler()
58 input_sync(touchkey->input_dev); in cypress_sf_irq_handler()
59 touchkey->keystates = keystates; in cypress_sf_irq_handler()
68 regulator_bulk_disable(ARRAY_SIZE(touchkey->regulators), in cypress_sf_disable_regulators()
69 touchkey->regulators); in cypress_sf_disable_regulators()
77 touchkey = devm_kzalloc(&client->dev, sizeof(*touchkey), GFP_KERNEL); in cypress_sf_probe()
79 return -ENOMEM; in cypress_sf_probe()
81 touchkey->client = client; in cypress_sf_probe()
84 touchkey->regulators[0].supply = "vdd"; in cypress_sf_probe()
85 touchkey->regulators[1].supply = "avdd"; in cypress_sf_probe()
87 error = devm_regulator_bulk_get(&client->dev, in cypress_sf_probe()
88 ARRAY_SIZE(touchkey->regulators), in cypress_sf_probe()
89 touchkey->regulators); in cypress_sf_probe()
91 dev_err(&client->dev, "Failed to get regulators: %d\n", error); in cypress_sf_probe()
95 touchkey->num_keys = device_property_read_u32_array(&client->dev, in cypress_sf_probe()
96 "linux,keycodes", in cypress_sf_probe()
98 if (touchkey->num_keys < 0) { in cypress_sf_probe()
100 touchkey->num_keys = 2; in cypress_sf_probe()
103 touchkey->keycodes = devm_kcalloc(&client->dev, in cypress_sf_probe()
104 touchkey->num_keys, in cypress_sf_probe()
105 sizeof(*touchkey->keycodes), in cypress_sf_probe()
107 if (!touchkey->keycodes) in cypress_sf_probe()
108 return -ENOMEM; in cypress_sf_probe()
110 error = device_property_read_u32_array(&client->dev, "linux,keycodes", in cypress_sf_probe()
111 touchkey->keycodes, in cypress_sf_probe()
112 touchkey->num_keys); in cypress_sf_probe()
115 dev_warn(&client->dev, in cypress_sf_probe()
116 "Failed to read keycodes: %d, using defaults\n", in cypress_sf_probe()
119 /* Default keycodes */ in cypress_sf_probe()
120 touchkey->keycodes[0] = KEY_BACK; in cypress_sf_probe()
121 touchkey->keycodes[1] = KEY_MENU; in cypress_sf_probe()
124 error = regulator_bulk_enable(ARRAY_SIZE(touchkey->regulators), in cypress_sf_probe()
125 touchkey->regulators); in cypress_sf_probe()
127 dev_err(&client->dev, in cypress_sf_probe()
132 error = devm_add_action_or_reset(&client->dev, in cypress_sf_probe()
138 touchkey->input_dev = devm_input_allocate_device(&client->dev); in cypress_sf_probe()
139 if (!touchkey->input_dev) { in cypress_sf_probe()
140 dev_err(&client->dev, "Failed to allocate input device\n"); in cypress_sf_probe()
141 return -ENOMEM; in cypress_sf_probe()
144 touchkey->input_dev->name = CYPRESS_SF_DEV_NAME; in cypress_sf_probe()
145 touchkey->input_dev->id.bustype = BUS_I2C; in cypress_sf_probe()
147 for (key = 0; key < touchkey->num_keys; ++key) in cypress_sf_probe()
148 input_set_capability(touchkey->input_dev, in cypress_sf_probe()
149 EV_KEY, touchkey->keycodes[key]); in cypress_sf_probe()
151 error = input_register_device(touchkey->input_dev); in cypress_sf_probe()
153 dev_err(&client->dev, in cypress_sf_probe()
158 error = devm_request_threaded_irq(&client->dev, client->irq, in cypress_sf_probe()
163 dev_err(&client->dev, in cypress_sf_probe()
177 disable_irq(client->irq); in cypress_sf_suspend()
179 error = regulator_bulk_disable(ARRAY_SIZE(touchkey->regulators), in cypress_sf_suspend()
180 touchkey->regulators); in cypress_sf_suspend()
183 enable_irq(client->irq); in cypress_sf_suspend()
196 error = regulator_bulk_enable(ARRAY_SIZE(touchkey->regulators), in cypress_sf_resume()
197 touchkey->regulators); in cypress_sf_resume()
203 enable_irq(client->irq); in cypress_sf_resume()