Lines Matching +full:gpio +full:- +full:ctrl2
1 // SPDX-License-Identifier: GPL-2.0-or-later
9 * - Power on the chip when open() and power down when close()
10 * - Manage power mode
16 #include <linux/gpio/consumer.h>
51 /* CTRL2 bits */
57 #define AS5011_MIN_AXIS (-80)
75 .addr = client->addr, in as5011_i2c_write()
82 error = i2c_transfer(client->adapter, &msg, 1); in as5011_i2c_write()
92 .addr = client->addr, in as5011_i2c_read()
98 .addr = client->addr, in as5011_i2c_read()
106 error = i2c_transfer(client->adapter, msg_set, 2); in as5011_i2c_read()
110 *value = data[0] & 0x80 ? -1 * (1 + ~data[0]) : data[0]; in as5011_i2c_read()
117 int val = gpiod_get_value_cansleep(as5011->button_gpiod); in as5011_button_interrupt()
119 input_report_key(as5011->input_dev, BTN_JOYSTICK, !val); in as5011_button_interrupt()
120 input_sync(as5011->input_dev); in as5011_button_interrupt()
131 error = as5011_i2c_read(as5011->i2c_client, AS5011_X_RES_INT, &x); in as5011_axis_interrupt()
135 error = as5011_i2c_read(as5011->i2c_client, AS5011_Y_RES_INT, &y); in as5011_axis_interrupt()
139 input_report_abs(as5011->input_dev, ABS_X, x); in as5011_axis_interrupt()
140 input_report_abs(as5011->input_dev, ABS_Y, y); in as5011_axis_interrupt()
141 input_sync(as5011->input_dev); in as5011_axis_interrupt()
150 struct i2c_client *client = as5011->i2c_client; in as5011_configure_chip()
158 dev_err(&client->dev, "Soft reset failed\n"); in as5011_configure_chip()
169 dev_err(&client->dev, "Power config failed\n"); in as5011_configure_chip()
176 dev_err(&client->dev, "Can't invert spinning\n"); in as5011_configure_chip()
181 error = as5011_i2c_write(client, AS5011_XP, plat_dat->xp); in as5011_configure_chip()
183 dev_err(&client->dev, "Can't write threshold\n"); in as5011_configure_chip()
187 error = as5011_i2c_write(client, AS5011_XN, plat_dat->xn); in as5011_configure_chip()
189 dev_err(&client->dev, "Can't write threshold\n"); in as5011_configure_chip()
193 error = as5011_i2c_write(client, AS5011_YP, plat_dat->yp); in as5011_configure_chip()
195 dev_err(&client->dev, "Can't write threshold\n"); in as5011_configure_chip()
199 error = as5011_i2c_write(client, AS5011_YN, plat_dat->yn); in as5011_configure_chip()
201 dev_err(&client->dev, "Can't write threshold\n"); in as5011_configure_chip()
205 /* to free irq gpio in chip */ in as5011_configure_chip()
208 dev_err(&client->dev, "Can't read i2c X resolution value\n"); in as5011_configure_chip()
223 plat_data = dev_get_platdata(&client->dev); in as5011_probe()
225 return -EINVAL; in as5011_probe()
227 if (!plat_data->axis_irq) { in as5011_probe()
228 dev_err(&client->dev, "No axis IRQ?\n"); in as5011_probe()
229 return -EINVAL; in as5011_probe()
232 if (!i2c_check_functionality(client->adapter, in as5011_probe()
235 dev_err(&client->dev, in as5011_probe()
237 return -ENODEV; in as5011_probe()
243 dev_err(&client->dev, in as5011_probe()
245 error = -ENOMEM; in as5011_probe()
249 as5011->i2c_client = client; in as5011_probe()
250 as5011->input_dev = input_dev; in as5011_probe()
251 as5011->axis_irq = plat_data->axis_irq; in as5011_probe()
253 input_dev->name = "Austria Microsystem as5011 joystick"; in as5011_probe()
254 input_dev->id.bustype = BUS_I2C; in as5011_probe()
255 input_dev->dev.parent = &client->dev; in as5011_probe()
261 input_set_abs_params(as5011->input_dev, ABS_Y, in as5011_probe()
264 as5011->button_gpiod = devm_gpiod_get(&client->dev, NULL, GPIOD_IN); in as5011_probe()
265 if (IS_ERR(as5011->button_gpiod)) { in as5011_probe()
266 error = PTR_ERR(as5011->button_gpiod); in as5011_probe()
267 dev_err(&client->dev, "Failed to request button GPIO\n"); in as5011_probe()
270 gpiod_set_consumer_name(as5011->button_gpiod, "AS5011 button"); in as5011_probe()
272 irq = gpiod_to_irq(as5011->button_gpiod); in as5011_probe()
274 dev_err(&client->dev, in as5011_probe()
275 "Failed to get irq number for button gpio\n"); in as5011_probe()
280 as5011->button_irq = irq; in as5011_probe()
282 error = request_threaded_irq(as5011->button_irq, in as5011_probe()
288 dev_err(&client->dev, in as5011_probe()
289 "Can't allocate button irq %d\n", as5011->button_irq); in as5011_probe()
297 error = request_threaded_irq(as5011->axis_irq, NULL, in as5011_probe()
299 plat_data->axis_irqflags | IRQF_ONESHOT, in as5011_probe()
302 dev_err(&client->dev, in as5011_probe()
303 "Can't allocate axis irq %d\n", plat_data->axis_irq); in as5011_probe()
307 error = input_register_device(as5011->input_dev); in as5011_probe()
309 dev_err(&client->dev, "Failed to register input device\n"); in as5011_probe()
318 free_irq(as5011->axis_irq, as5011); in as5011_probe()
320 free_irq(as5011->button_irq, as5011); in as5011_probe()
332 free_irq(as5011->axis_irq, as5011); in as5011_remove()
333 free_irq(as5011->button_irq, as5011); in as5011_remove()
335 input_unregister_device(as5011->input_dev); in as5011_remove()