26 #include <linux/i2c.h>
28 #include <linux/input.h>
32 #include <linux/slab.h>
33 #include <linux/module.h>
35 #define DRIVER_DESC "Driver for Austria Microsystems AS5011 joystick"
36 #define MODULE_DEVICE_ALIAS "as5011"
43 #define AS5011_CTRL1 0x76
44 #define AS5011_CTRL2 0x75
45 #define AS5011_XP 0x43
46 #define AS5011_XN 0x44
47 #define AS5011_YP 0x53
48 #define AS5011_YN 0x54
49 #define AS5011_X_REG 0x41
50 #define AS5011_Y_REG 0x42
51 #define AS5011_X_RES_INT 0x51
52 #define AS5011_Y_RES_INT 0x52
55 #define AS5011_CTRL1_LP_PULSED 0x80
56 #define AS5011_CTRL1_LP_ACTIVE 0x40
57 #define AS5011_CTRL1_LP_CONTINUE 0x20
58 #define AS5011_CTRL1_INT_WUP_EN 0x10
59 #define AS5011_CTRL1_INT_ACT_EN 0x08
60 #define AS5011_CTRL1_EXT_CLK_EN 0x04
61 #define AS5011_CTRL1_SOFT_RST 0x02
62 #define AS5011_CTRL1_DATA_VALID 0x01
65 #define AS5011_CTRL2_EXT_SAMPLE_EN 0x08
66 #define AS5011_CTRL2_RC_BIAS_ON 0x04
67 #define AS5011_CTRL2_INV_SPINNING 0x02
69 #define AS5011_MAX_AXIS 80
70 #define AS5011_MIN_AXIS (-80)
72 #define AS5011_FLAT 40
93 return error < 0 ? error : 0;
96 static int as5011_i2c_read(
struct i2c_client *client,
110 *value = data[0] & 0x80 ? -1 * (1 + ~data[0]) : data[0];
169 dev_err(&client->
dev,
"Power config failed\n");
176 dev_err(&client->
dev,
"Can't invert spinning\n");
181 error = as5011_i2c_write(client,
AS5011_XP, plat_dat->
xp);
183 dev_err(&client->
dev,
"Can't write threshold\n");
187 error = as5011_i2c_write(client,
AS5011_XN, plat_dat->
xn);
189 dev_err(&client->
dev,
"Can't write threshold\n");
193 error = as5011_i2c_write(client,
AS5011_YP, plat_dat->
yp);
195 dev_err(&client->
dev,
"Can't write threshold\n");
199 error = as5011_i2c_write(client,
AS5011_YN, plat_dat->
yn);
201 dev_err(&client->
dev,
"Can't write threshold\n");
208 dev_err(&client->
dev,
"Can't read i2c X resolution value\n");
220 struct input_dev *input_dev;
224 plat_data = client->
dev.platform_data;
233 if (!i2c_check_functionality(client->
adapter,
237 "need i2c bus that supports protocol mangling\n");
242 input_dev = input_allocate_device();
243 if (!as5011 || !input_dev) {
245 "Can't allocate memory for device structure\n");
255 input_dev->name =
"Austria Microsystem as5011 joystick";
256 input_dev->id.bustype =
BUS_I2C;
257 input_dev->dev.parent = &client->
dev;
263 input_set_abs_params(input_dev,
ABS_X,
270 dev_err(&client->
dev,
"Failed to request button gpio\n");
277 "Failed to get irq number for button gpio\n");
278 goto err_free_button_gpio;
284 NULL, as5011_button_interrupt,
287 "as5011_button", as5011);
290 "Can't allocate button irq %d\n", as5011->
button_irq);
291 goto err_free_button_gpio;
294 error = as5011_configure_chip(as5011, plat_data);
296 goto err_free_button_irq;
299 as5011_axis_interrupt,
301 "as5011_joystick", as5011);
304 "Can't allocate axis irq %d\n", plat_data->
axis_irq);
305 goto err_free_button_irq;
308 error = input_register_device(as5011->
input_dev);
310 dev_err(&client->
dev,
"Failed to register input device\n");
311 goto err_free_axis_irq;
314 i2c_set_clientdata(client, as5011);
322 err_free_button_gpio:
325 input_free_device(input_dev);
339 input_unregister_device(as5011->
input_dev);
355 .probe = as5011_probe,
357 .id_table = as5011_id,