• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *
3  * Copyright (C) 2015 Allwinnertech Ltd.
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16  */
17 //#define DEBUG
18 #include <linux/module.h>
19 #include <linux/init.h>
20 #include <linux/input.h>
21 #include <linux/delay.h>
22 #include <linux/slab.h>
23 #include <linux/interrupt.h>
24 #include <linux/keyboard.h>
25 #include <linux/ioport.h>
26 #include <asm/irq.h>
27 #include <asm/io.h>
28 #include <linux/timer.h>
29 #include <linux/clk.h>
30 #include <linux/irq.h>
31 #include <linux/of_platform.h>
32 #include <linux/of_irq.h>
33 #include <linux/of_address.h>
34 
35 #include <linux/iio/iio.h>
36 #include <linux/iio/machine.h>
37 #include <linux/iio/driver.h>
38 #include <linux/reset.h>
39 
40 #if IS_ENABLED(CONFIG_PM)
41 #include <linux/pm.h>
42 #endif
43 #include "sunxi-lradc.h"
44 
45 #define	LRADC_BITS		6
46 #define LRADC_RESOLUTION	(1 << LRADC_BITS)
47 
48 static unsigned char keypad_mapindex[LRADC_RESOLUTION];
49 
50 #define INITIAL_VALUE (0xff)
51 #define VOL_NUM KEY_MAX_CNT
52 
53 static u32 sunxi_keyboard_regs_offset[] = {
54 	LRADC_CTRL,
55 	LRADC_INTC,
56 };
57 
58 struct sunxi_key_data {
59 	struct platform_device	*pdev;
60 	struct clk *mclk;
61 	struct clk *pclk;
62 	struct reset_control	*rst_clk;
63 	struct input_dev *input_dev;
64 	struct sunxi_adc_disc *disc;
65 	spinlock_t		lock; /* syn */
66 	void __iomem *reg_base;
67 	u32 scankeycodes[KEY_MAX_CNT];
68 	int irq_num;
69 	u32 key_val;
70 	unsigned char compare_later;
71 	unsigned char compare_before;
72 	u8 key_code;
73 	u8 last_key_code;
74 	char key_name[16];
75 	u8 key_cnt;
76 	int wakeup;
77 	u32 regs_backup[ARRAY_SIZE(sunxi_keyboard_regs_offset)];
78 };
79 
80 static struct sunxi_adc_disc disc_1350 = {
81 	.measure = 1350,
82 	.resol = 21,
83 };
84 
85 static struct sunxi_adc_disc disc_1200 = {
86 	.measure = 1200,
87 	.resol = 19,
88 };
89 
90 static struct sunxi_adc_disc disc_2000 = {
91 	.measure = 2000,
92 	.resol = 31,
93 };
94 
95 /*
96  * Translate OpenFirmware node properties into platform_data
97  */
98 static struct of_device_id const sunxi_keyboard_of_match[] = {
99 	{ .compatible = "allwinner,keyboard_1350mv",
100 		.data = &disc_1350 },
101 	{ .compatible = "allwinner,keyboard_1200mv",
102 		.data = &disc_1200 },
103 	{ .compatible = "allwinner,keyboard_2000mv",
104 		.data = &disc_2000 },
105 	{ },
106 };
107 MODULE_DEVICE_TABLE(of, sunxi_keyboard_of_match);
108 
sunxi_keyboard_save_regs(struct sunxi_key_data * key_data)109 static inline void sunxi_keyboard_save_regs(struct sunxi_key_data *key_data)
110 {
111 	int i;
112 
113 	for (i = 0; i < ARRAY_SIZE(sunxi_keyboard_regs_offset); i++)
114 		key_data->regs_backup[i] = readl(key_data->reg_base + sunxi_keyboard_regs_offset[i]);
115 }
116 
sunxi_keyboard_restore_regs(struct sunxi_key_data * key_data)117 static inline void sunxi_keyboard_restore_regs(struct sunxi_key_data *key_data)
118 {
119 	int i;
120 
121 	for (i = 0; i < ARRAY_SIZE(sunxi_keyboard_regs_offset); i++)
122 		writel(key_data->regs_backup[i], key_data->reg_base + sunxi_keyboard_regs_offset[i]);
123 }
124 
125 #if IS_ENABLED(CONFIG_PM)
sunxi_keyboard_suspend(struct device * dev)126 static int sunxi_keyboard_suspend(struct device *dev)
127 {
128 	struct platform_device *pdev = to_platform_device(dev);
129 	struct sunxi_key_data *key_data = platform_get_drvdata(pdev);
130 
131 	pr_debug("[%s] enter standby\n", __func__);
132 
133 	/* Used to determine whether the device can be wakeup, and use
134 	 * this function */
135 	if (device_may_wakeup(dev)) {
136 		if (key_data->wakeup)
137 			enable_irq_wake(key_data->irq_num);
138 	} else {
139 		disable_irq_nosync(key_data->irq_num);
140 
141 		sunxi_keyboard_save_regs(key_data);
142 
143 		clk_disable_unprepare(key_data->mclk);
144 
145 		reset_control_assert(key_data->rst_clk);
146 	}
147 
148 	return 0;
149 }
150 
sunxi_keyboard_resume(struct device * dev)151 static int sunxi_keyboard_resume(struct device *dev)
152 {
153 	struct platform_device *pdev = to_platform_device(dev);
154 	struct sunxi_key_data *key_data = platform_get_drvdata(pdev);
155 
156 	pr_debug("[%s] return from standby\n", __func__);
157 
158 	/* Used to determine whether the device can be wakeup, and use
159 	 * this function */
160 	if (device_may_wakeup(dev)) {
161 		if (key_data->wakeup)
162 			disable_irq_wake(key_data->irq_num);
163 	} else {
164 		reset_control_deassert(key_data->rst_clk);
165 
166 		clk_prepare_enable(key_data->mclk);
167 
168 		sunxi_keyboard_restore_regs(key_data);
169 
170 		enable_irq(key_data->irq_num);
171 	}
172 
173 	return 0;
174 }
175 #endif
176 
sunxi_report_key_down_event(struct sunxi_key_data * key_data)177 static void sunxi_report_key_down_event(struct sunxi_key_data *key_data)
178 {
179 	if (key_data->last_key_code == INITIAL_VALUE) {
180 		/* first time report key down event */
181 		input_report_key(key_data->input_dev,
182 				key_data->scankeycodes[key_data->key_code], 1);
183 		input_sync(key_data->input_dev);
184 		key_data->last_key_code = key_data->key_code;
185 		return;
186 	}
187 	if (key_data->scankeycodes[key_data->key_code] ==
188 		key_data->scankeycodes[key_data->last_key_code]) {
189 #ifdef REPORT_REPEAT_KEY_BY_INPUT_CORE
190 		/* report repeat key down event */
191 		input_report_key(key_data->input_dev,
192 				key_data->scankeycodes[key_data->key_code], 1);
193 		input_sync(key_data->input_dev);
194 #endif
195 	} else {
196 		/* report previous key up event
197 		 * and report current key down event
198 		 */
199 		input_report_key(key_data->input_dev,
200 				key_data->scankeycodes[key_data->last_key_code], 0);
201 		input_sync(key_data->input_dev);
202 		input_report_key(key_data->input_dev,
203 				key_data->scankeycodes[key_data->key_code], 1);
204 		input_sync(key_data->input_dev);
205 		key_data->last_key_code = key_data->key_code;
206 	}
207 }
208 
sunxi_isr_key(int irq,void * dummy)209 static irqreturn_t sunxi_isr_key(int irq, void *dummy)
210 {
211 	struct sunxi_key_data *key_data = (struct sunxi_key_data *)dummy;
212 	u32 reg_val = 0;
213 	u32 key_val = 0;
214 
215 	pr_debug("Key Interrupt\n");
216 
217 	/* Clear interrupt register */
218 	reg_val = readl(key_data->reg_base + LRADC_INT_STA);
219 	writel(reg_val, key_data->reg_base + LRADC_INT_STA);
220 
221 	if (reg_val & LRADC_ADC0_DOWNPEND)
222 		pr_debug("key down\n");
223 
224 	if (reg_val & LRADC_ADC0_DATAPEND) {
225 		key_data->key_cnt++;
226 		key_val = readl(key_data->reg_base + LRADC_DATA0);
227 		key_data->compare_before = key_val & 0x3f;
228 		if (key_data->compare_before == key_data->compare_later) {
229 			key_data->key_code = keypad_mapindex[key_val & 0x3f];
230 			sunxi_report_key_down_event(key_data);
231 			key_data->key_cnt = 0;
232 		}
233 		if (key_data->key_cnt == 2) {
234 			key_data->compare_later = key_data->compare_before;
235 			key_data->key_cnt = 0;
236 		}
237 	}
238 
239 	if (reg_val & LRADC_ADC0_UPPEND) {
240 		if (key_data->wakeup)
241 			pm_wakeup_event(key_data->input_dev->dev.parent, 0);
242 		pr_debug("report data:%8d key_val:%8d\n",
243 				key_data->scankeycodes[key_data->key_code],
244 				key_val);
245 		input_report_key(key_data->input_dev,
246 				key_data->scankeycodes[key_data->key_code], 0);
247 		input_sync(key_data->input_dev);
248 		pr_debug("key up\n");
249 		key_data->key_cnt = 0;
250 		key_data->compare_later = 0;
251 		key_data->last_key_code = INITIAL_VALUE;
252 	}
253 
254 	return IRQ_HANDLED;
255 }
256 
sunxi_keyboard_startup(struct sunxi_key_data * key_data,struct platform_device * pdev)257 static int sunxi_keyboard_startup(struct sunxi_key_data *key_data,
258 				struct platform_device *pdev)
259 {
260 	int ret;
261 	struct resource *res;
262 	struct device *dev = &pdev->dev;
263 
264 	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
265 	if (!res) {
266 		dev_err(dev, "Fail to get IORESOURCE_MEM\n");
267 		return -EINVAL;
268 	}
269 
270 	key_data->reg_base = devm_ioremap_resource(dev, res);
271 	if (IS_ERR(key_data->reg_base)) {
272 		dev_err(dev, "Fail to map IO resource\n");
273 		return PTR_ERR(key_data->reg_base);
274 	}
275 
276 	key_data->irq_num = platform_get_irq(pdev, 0);
277 	if (key_data->irq_num < 0) {
278 		dev_err(dev, "No IRQ resource\n");
279 		return -EINVAL;
280 	}
281 
282 	/* some IC will use clock gating while others HW use 24MHZ, So just try
283 	 * to get the clock, if it doesn't exist, give warning instead of error
284 	 */
285 	key_data->rst_clk = devm_reset_control_get(dev, NULL);
286 	if (IS_ERR(key_data->rst_clk)) {
287 		dev_err(dev, "reset_control_get() failed\n");
288 		goto err0;
289 	}
290 
291 	if (reset_control_deassert(key_data->rst_clk)) {
292 		dev_err(dev, "enable apb1_keyadc clock failed!\n");
293 		goto err0;
294 	}
295 
296 	key_data->mclk = devm_clk_get(dev, NULL);
297 	if (IS_ERR(key_data->mclk)) {
298 		dev_err(dev, "Failed to get clock 'mclk'\n");
299 		return PTR_ERR(key_data->mclk);
300 	}
301 
302 	ret = clk_prepare_enable(key_data->mclk);
303 	if (ret) {
304 		dev_err(dev, "cannot enable clock 'mclk'");
305 		goto err1;
306 	}
307 
308 	return ret;
309 
310 err1:
311 	reset_control_assert(key_data->rst_clk);
312 err0:
313 	return ret;
314 
315 }
316 
sunxikbd_key_init(struct sunxi_key_data * key_data,struct platform_device * pdev)317 static int sunxikbd_key_init(struct sunxi_key_data *key_data,
318 			struct platform_device *pdev)
319 {
320 	struct device_node *np;
321 	const struct of_device_id *match;
322 	struct sunxi_adc_disc *disc;
323 	int i;
324 	int j = 0;
325 	u32 val[2] = {0, 0};
326 	u32 key_num ;
327 	u32 key_vol[VOL_NUM];
328 
329 	np = pdev->dev.of_node;
330 	match = of_match_node(sunxi_keyboard_of_match, np);
331 	disc = (struct sunxi_adc_disc *)match->data;
332 	key_data->disc = disc;
333 	if (of_property_read_u32(np, "key_cnt", &key_num)) {
334 		pr_err("%s: get key count failed", __func__);
335 		return -EBUSY;
336 	}
337 	pr_debug("%s key number = %d.\n", __func__, key_num);
338 	if (key_num < 1 || key_num >= VOL_NUM) {
339 		pr_err("incorrect key number.\n");
340 		return -1;
341 	}
342 	for (i = 0; i < key_num; i++) {
343 		sprintf(key_data->key_name, "key%d", i);
344 		if (of_property_read_u32_array(np, key_data->key_name,
345 						val, ARRAY_SIZE(val))) {
346 			pr_err("%s:get%s err!\n", __func__, key_data->key_name);
347 			return -EBUSY;
348 		}
349 		key_vol[i] = val[0];
350 		key_data->scankeycodes[i] = val[1];
351 		pr_debug("%s: key%d vol= %d code= %d\n", __func__, i,
352 				key_vol[i], key_data->scankeycodes[i]);
353 	}
354 
355 	/* set the key judgment threshold */
356 	key_vol[key_num] = disc->measure;
357 	for (i = 0; i < key_num; i++)
358 		key_vol[i] += (key_vol[i+1] - key_vol[i])/2;
359 
360 	for (i = 0; i < 64; i++) {
361 		if (i * disc->resol > key_vol[j])
362 			j++;
363 		keypad_mapindex[i] = j;
364 	}
365 
366 	key_data->wakeup = of_property_read_bool(np, "wakeup-source");
367 	device_init_wakeup(&pdev->dev, key_data->wakeup);
368 
369 	key_data->last_key_code = INITIAL_VALUE;
370 
371 	return 0;
372 }
373 
374 #if IS_ENABLED(CONFIG_IIO)
375 struct sunxi_lradc_iio {
376 	struct sunxi_key_data *key_data;
377 };
378 
379 static const struct iio_chan_spec sunxi_lradc_channels[] = {
380 	{
381 		.indexed = 1,
382 		.type = IIO_VOLTAGE,
383 		.channel = 0,
384 		.datasheet_name = "LRADC",
385 		.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
386 	},
387 };
388 
389 /* default maps used by iio consumer (axp charger driver) */
390 static struct iio_map sunxi_lradc_default_iio_maps[] = {
391 	{
392 		.consumer_dev_name = "axp-charger",
393 		.consumer_channel = "axp-battery-lradc",
394 		.adc_channel_label = "LRADC",
395 	},
396 	{ }
397 };
398 
sunxi_lradc_read_raw(struct iio_dev * indio_dev,struct iio_chan_spec const * chan,int * val,int * val2,long mask)399 static int sunxi_lradc_read_raw(struct iio_dev *indio_dev,
400 			struct iio_chan_spec const *chan,
401 			int *val, int *val2, long mask)
402 {
403 	int ret = 0;
404 	int key_val, id_vol;
405 	struct sunxi_lradc_iio *info = iio_priv(indio_dev);
406 	struct sunxi_key_data *key_data = info->key_data;
407 	struct sunxi_adc_disc *disc = key_data->disc;
408 
409 	mutex_lock(&indio_dev->mlock);
410 	switch (mask) {
411 	case IIO_CHAN_INFO_RAW:
412 		key_val = readl(key_data->reg_base + LRADC_DATA0) & 0x3f;
413 		id_vol = key_val * disc->resol;
414 		*val = id_vol;
415 		break;
416 	default:
417 		ret = -EINVAL;
418 	}
419 	mutex_unlock(&indio_dev->mlock);
420 
421 	return ret;
422 }
423 
424 static const struct iio_info sunxi_lradc_iio_info = {
425 	.read_raw = &sunxi_lradc_read_raw,
426 };
427 
sunxi_lradc_remove_iio(void * _data)428 static void sunxi_lradc_remove_iio(void *_data)
429 {
430 	struct iio_dev *indio_dev = _data;
431 
432 	if (IS_ERR_OR_NULL(indio_dev)) {
433 		pr_err("indio_dev is null\n");
434 	} else {
435 		iio_device_unregister(indio_dev);
436 		iio_map_array_unregister(indio_dev);
437 	}
438 }
439 
sunxi_keyboard_iio_init(struct platform_device * pdev)440 static int sunxi_keyboard_iio_init(struct platform_device *pdev)
441 {
442 	int ret;
443 	struct iio_dev *indio_dev;
444 	struct sunxi_lradc_iio *info;
445 	struct sunxi_key_data *key_data = platform_get_drvdata(pdev);
446 
447 	indio_dev = devm_iio_device_alloc(&pdev->dev, sizeof(*info));
448 	if (!indio_dev)
449 		return -ENOMEM;
450 
451 	info = iio_priv(indio_dev);
452 	info->key_data = key_data;
453 
454 	indio_dev->dev.parent = &pdev->dev;
455 	indio_dev->name = pdev->name;
456 	indio_dev->channels = sunxi_lradc_channels;
457 	indio_dev->num_channels = ARRAY_SIZE(sunxi_lradc_channels);
458 	indio_dev->info = &sunxi_lradc_iio_info;
459 	indio_dev->modes = INDIO_DIRECT_MODE;
460 	ret = iio_map_array_register(indio_dev, sunxi_lradc_default_iio_maps);
461 	if (ret < 0)
462 		return ret;
463 
464 	ret = iio_device_register(indio_dev);
465 	if (ret < 0) {
466 		dev_err(&pdev->dev, "unable to register iio device\n");
467 		goto err_array_unregister;
468 	}
469 
470 	ret = devm_add_action(&pdev->dev,
471 				sunxi_lradc_remove_iio, indio_dev);
472 	if (ret) {
473 		dev_err(&pdev->dev, "unable to add iio cleanup action\n");
474 		goto err_iio_unregister;
475 	}
476 
477 	return 0;
478 
479 err_iio_unregister:
480 	iio_device_unregister(indio_dev);
481 
482 err_array_unregister:
483 	iio_map_array_unregister(indio_dev);
484 
485 	return ret;
486 }
487 #else
sunxi_keyboard_iio_init(struct platform_device * pdev)488 static inline int sunxi_keyboard_iio_init(struct platform_device *pdev)
489 {
490 	return -ENODEV;
491 }
492 #endif
493 
sunxi_keyboard_probe(struct platform_device * pdev)494 static int sunxi_keyboard_probe(struct platform_device *pdev)
495 {
496 	static struct input_dev *sunxikbd_dev;
497 	struct sunxi_key_data *key_data;
498 	unsigned long mask, para;
499 	u32 reg_val;
500 	int i;
501 	int err;
502 
503 	key_data = kzalloc(sizeof(*key_data), GFP_KERNEL);
504 	if (!key_data) {
505 		pr_err("key_data: not enough memory for key data\n");
506 		return -ENOMEM;
507 	}
508 
509 	pr_debug("sunxikbd_init\n");
510 
511 	err = sunxi_keyboard_startup(key_data, pdev);
512 	if (err < 0)
513 		goto fail1;
514 
515 	if (sunxikbd_key_init(key_data, pdev)) {
516 		err = -EFAULT;
517 		goto fail2;
518 	}
519 
520 	sunxikbd_dev = input_allocate_device();
521 	if (!sunxikbd_dev) {
522 		pr_err("sunxikbd: not enough memory for input device\n");
523 		err = -ENOMEM;
524 		goto fail3;
525 	}
526 
527 	sunxikbd_dev->name = INPUT_DEV_NAME;
528 	sunxikbd_dev->phys = "sunxikbd/input0";
529 	sunxikbd_dev->id.bustype = BUS_HOST;
530 	sunxikbd_dev->id.vendor = 0x0001;
531 	sunxikbd_dev->id.product = 0x0001;
532 	sunxikbd_dev->id.version = 0x0100;
533 
534 #ifdef REPORT_REPEAT_KEY_BY_INPUT_CORE
535 	sunxikbd_dev->evbit[0] = BIT_MASK(EV_KEY)|BIT_MASK(EV_REP);
536 	pr_info("support report repeat key value.\n");
537 #else
538 	sunxikbd_dev->evbit[0] = BIT_MASK(EV_KEY);
539 #endif
540 
541 	for (i = 0; i < KEY_MAX_CNT; i++) {
542 		if (key_data->scankeycodes[i] < KEY_MAX)
543 			set_bit(key_data->scankeycodes[i], sunxikbd_dev->keybit);
544 	}
545 	key_data->input_dev = sunxikbd_dev;
546 	platform_set_drvdata(pdev, key_data);
547 #ifdef ONE_CHANNEL
548 
549 	reg_val = readl(key_data->reg_base + LRADC_INTC);
550 	para = LRADC_ADC0_UP_EN | LRADC_ADC0_DOWN_EN | LRADC_ADC0_DATA_EN;
551 	mask = LRADC_ADC0_UP_EN_MASK | LRADC_ADC0_DOWN_EN_MASK | LRADC_ADC0_DATA_EN_MASK;
552 	reg_val &= ~mask;
553 	reg_val |= para;
554 	writel(reg_val, key_data->reg_base + LRADC_INTC);
555 
556 	reg_val = readl(key_data->reg_base + LRADC_CTRL);
557 	para = FIRST_CONVERT_DLY | LEVELB_VOL | KEY_MODE_SELECT
558 		| LRADC_HOLD_EN | ADC_CHAN_SELECT | LEVELB_CNT
559 		| LRADC_SAMPLE_250HZ | LRADC_EN;
560 	mask = FIRST_CONVERT_DLY_MASK | LEVELB_VOL_MASK | KEY_MODE_SELECT_MASK
561 		| LRADC_HOLD_EN_MASK | LEVELB_CNT_MASK
562 		| LRADC_SAMPLE_250HZ_MASK | LRADC_EN_MASK;
563 	reg_val &= ~mask;
564 	reg_val |= para;
565 	writel(reg_val, key_data->reg_base + LRADC_CTRL);
566 
567 #endif
568 
569 	err = input_register_device(key_data->input_dev);
570 	if (err)
571 		goto fail4;
572 
573 	if (request_irq(key_data->irq_num, sunxi_isr_key, 0,
574 					"sunxikbd", key_data)) {
575 		err = -EBUSY;
576 		pr_err("request irq failure.\n");
577 		goto fail5;
578 	}
579 
580 	/* Clear interrupt register */
581 	reg_val = readl(key_data->reg_base + LRADC_INT_STA);
582 	writel(reg_val, key_data->reg_base + LRADC_INT_STA);
583 
584 	pr_debug("sunxikbd_init end\n");
585 	return 0;
586 fail5:
587 	input_unregister_device(key_data->input_dev);
588 fail4:
589 	input_free_device(key_data->input_dev);
590 fail3:
591 	device_init_wakeup(&pdev->dev, 0);
592 fail2:
593 	clk_disable_unprepare(key_data->mclk);
594 	reset_control_assert(key_data->rst_clk);
595 fail1:
596 	kfree(key_data);
597 	pr_err("sunxikbd_init failed.\n");
598 
599 	return err;
600 }
601 
sunxi_keyboard_remove(struct platform_device * pdev)602 static int sunxi_keyboard_remove(struct platform_device *pdev)
603 {
604 	struct sunxi_key_data *key_data = platform_get_drvdata(pdev);
605 
606 	free_irq(key_data->irq_num, key_data);
607 	input_unregister_device(key_data->input_dev);
608 	input_free_device(key_data->input_dev);
609 	device_init_wakeup(&pdev->dev, 0);
610 	clk_disable_unprepare(key_data->mclk);
611 	reset_control_assert(key_data->rst_clk);
612 	kfree(key_data);
613 	return 0;
614 }
615 
616 #if IS_ENABLED(CONFIG_PM)
617 static const struct dev_pm_ops sunxi_keyboard_pm_ops = {
618 	.suspend = sunxi_keyboard_suspend,
619 	.resume = sunxi_keyboard_resume,
620 };
621 
622 #define SUNXI_KEYBOARD_PM_OPS (&sunxi_keyboard_pm_ops)
623 #endif
624 
625 static struct platform_driver sunxi_keyboard_driver = {
626 	.probe  = sunxi_keyboard_probe,
627 	.remove = sunxi_keyboard_remove,
628 	.driver = {
629 		.name   = "sunxi-keyboard",
630 		.owner  = THIS_MODULE,
631 #if IS_ENABLED(CONFIG_PM)
632 		.pm	= SUNXI_KEYBOARD_PM_OPS,
633 #endif
634 		.of_match_table = of_match_ptr(sunxi_keyboard_of_match),
635 	},
636 };
637 
sunxi_keyboard_init(void)638 static int __init sunxi_keyboard_init(void)
639 {
640 	int ret;
641 
642 	ret = platform_driver_register(&sunxi_keyboard_driver);
643 
644 	return ret;
645 }
646 
sunxi_keyboard_exit(void)647 static void __exit sunxi_keyboard_exit(void)
648 {
649 	platform_driver_unregister(&sunxi_keyboard_driver);
650 }
651 
652 subsys_initcall_sync(sunxi_keyboard_init);
653 module_exit(sunxi_keyboard_exit);
654 
655 MODULE_AUTHOR(" Qin");
656 MODULE_DESCRIPTION("sunxi-keyboard driver");
657 MODULE_LICENSE("GPL");
658 MODULE_VERSION("1.2.0");
659