3535#include <linux/i2c.h>
3636#include <linux/input.h>
3737#include <linux/input/tca8418_keypad.h>
38+ #include <linux/of.h>
3839
3940/* TCA8418 hardware limits */
4041#define TCA8418_MAX_ROWS 8
@@ -116,10 +117,15 @@ static const struct i2c_device_id tca8418_id[] = {
116117};
117118MODULE_DEVICE_TABLE (i2c , tca8418_id );
118119
120+ #ifdef CONFIG_OF
121+ static const struct of_device_id tca8418_dt_ids [] __devinitconst = {
122+ { .compatible = "ti,tca8418" , },
123+ { }
124+ };
125+ MODULE_DEVICE_TABLE (of , tca8418_dt_ids );
126+ #endif
127+
119128struct tca8418_keypad {
120- unsigned int rows ;
121- unsigned int cols ;
122- unsigned int keypad_mask ; /* Mask for keypad col/rol regs */
123129 unsigned int irq ;
124130 unsigned int row_shift ;
125131
@@ -241,7 +247,8 @@ static irqreturn_t tca8418_irq_handler(int irq, void *dev_id)
241247/*
242248 * Configure the TCA8418 for keypad operation
243249 */
244- static int tca8418_configure (struct tca8418_keypad * keypad_data )
250+ static int tca8418_configure (struct tca8418_keypad * keypad_data ,
251+ u32 rows , u32 cols )
245252{
246253 int reg , error ;
247254
@@ -253,9 +260,8 @@ static int tca8418_configure(struct tca8418_keypad *keypad_data)
253260
254261
255262 /* Assemble a mask for row and column registers */
256- reg = ~(~0 << keypad_data -> rows );
257- reg += (~(~0 << keypad_data -> cols )) << 8 ;
258- keypad_data -> keypad_mask = reg ;
263+ reg = ~(~0 << rows );
264+ reg += (~(~0 << cols )) << 8 ;
259265
260266 /* Set registers to keypad mode */
261267 error |= tca8418_write_byte (keypad_data , REG_KP_GPIO1 , reg );
@@ -277,25 +283,36 @@ static int tca8418_keypad_probe(struct i2c_client *client,
277283 client -> dev .platform_data ;
278284 struct tca8418_keypad * keypad_data ;
279285 struct input_dev * input ;
286+ const struct matrix_keymap_data * keymap_data = NULL ;
287+ u32 rows = 0 , cols = 0 ;
288+ bool rep = false;
289+ bool irq_is_gpio = false;
280290 int error , row_shift , max_keys ;
281291
282292 /* Copy the platform data */
283- if (!pdata ) {
284- dev_dbg (& client -> dev , "no platform data\n" );
285- return - EINVAL ;
293+ if (pdata ) {
294+ if (!pdata -> keymap_data ) {
295+ dev_err (& client -> dev , "no keymap data defined\n" );
296+ return - EINVAL ;
297+ }
298+ keymap_data = pdata -> keymap_data ;
299+ rows = pdata -> rows ;
300+ cols = pdata -> cols ;
301+ rep = pdata -> rep ;
302+ irq_is_gpio = pdata -> irq_is_gpio ;
303+ } else {
304+ struct device_node * np = client -> dev .of_node ;
305+ of_property_read_u32 (np , "keypad,num-rows" , & rows );
306+ of_property_read_u32 (np , "keypad,num-columns" , & cols );
307+ rep = of_property_read_bool (np , "keypad,autorepeat" );
286308 }
287309
288- if (!pdata -> keymap_data ) {
289- dev_err (& client -> dev , "no keymap data defined\n" );
290- return - EINVAL ;
291- }
292-
293- if (!pdata -> rows || pdata -> rows > TCA8418_MAX_ROWS ) {
310+ if (!rows || rows > TCA8418_MAX_ROWS ) {
294311 dev_err (& client -> dev , "invalid rows\n" );
295312 return - EINVAL ;
296313 }
297314
298- if (!pdata -> cols || pdata -> cols > TCA8418_MAX_COLS ) {
315+ if (!cols || cols > TCA8418_MAX_COLS ) {
299316 dev_err (& client -> dev , "invalid columns\n" );
300317 return - EINVAL ;
301318 }
@@ -307,22 +324,20 @@ static int tca8418_keypad_probe(struct i2c_client *client,
307324 return - ENODEV ;
308325 }
309326
310- row_shift = get_count_order (pdata -> cols );
311- max_keys = pdata -> rows << row_shift ;
327+ row_shift = get_count_order (cols );
328+ max_keys = rows << row_shift ;
312329
313330 /* Allocate memory for keypad_data, keymap and input device */
314331 keypad_data = kzalloc (sizeof (* keypad_data ) +
315332 max_keys * sizeof (keypad_data -> keymap [0 ]), GFP_KERNEL );
316333 if (!keypad_data )
317334 return - ENOMEM ;
318335
319- keypad_data -> rows = pdata -> rows ;
320- keypad_data -> cols = pdata -> cols ;
321336 keypad_data -> client = client ;
322337 keypad_data -> row_shift = row_shift ;
323338
324339 /* Initialize the chip or fail if chip isn't present */
325- error = tca8418_configure (keypad_data );
340+ error = tca8418_configure (keypad_data , rows , cols );
326341 if (error < 0 )
327342 goto fail1 ;
328343
@@ -342,21 +357,20 @@ static int tca8418_keypad_probe(struct i2c_client *client,
342357 input -> id .product = 0x001 ;
343358 input -> id .version = 0x0001 ;
344359
345- error = matrix_keypad_build_keymap (pdata -> keymap_data , NULL ,
346- pdata -> rows , pdata -> cols ,
360+ error = matrix_keypad_build_keymap (keymap_data , NULL , rows , cols ,
347361 keypad_data -> keymap , input );
348362 if (error ) {
349363 dev_dbg (& client -> dev , "Failed to build keymap\n" );
350364 goto fail2 ;
351365 }
352366
353- if (pdata -> rep )
367+ if (rep )
354368 __set_bit (EV_REP , input -> evbit );
355369 input_set_capability (input , EV_MSC , MSC_SCAN );
356370
357371 input_set_drvdata (input , keypad_data );
358372
359- if (pdata -> irq_is_gpio )
373+ if (irq_is_gpio )
360374 client -> irq = gpio_to_irq (client -> irq );
361375
362376 error = request_threaded_irq (client -> irq , NULL , tca8418_irq_handler ,
@@ -401,11 +415,11 @@ static int tca8418_keypad_remove(struct i2c_client *client)
401415 return 0 ;
402416}
403417
404-
405418static struct i2c_driver tca8418_keypad_driver = {
406419 .driver = {
407420 .name = TCA8418_NAME ,
408421 .owner = THIS_MODULE ,
422+ .of_match_table = of_match_ptr (tca8418_dt_ids ),
409423 },
410424 .probe = tca8418_keypad_probe ,
411425 .remove = tca8418_keypad_remove ,
0 commit comments