[PATCH 2/4] twl6030: add power button as an input key
Sascha Hauer
s.hauer at pengutronix.de
Mon Mar 11 17:35:27 EDT 2013
On Mon, Mar 11, 2013 at 12:36:05AM +0100, Vicente Bergas wrote:
>
> +
> +static int __init twl6030_pwrbtn_probe(struct device_d *dev)
> +{
> + struct twl6030_pwrbtn_platform_data *pdata;
> + struct console_device *cdev;
> +
> + pdata = dev->platform_data;
> +
> + if (!pdata) {
> + pr_err("missing platform_data\n");
use dev_err and friends for driver messages.
> + return -ENODEV;
> + }
> +
> + pdata->twl6030 = twl6030_get();
> + if (!pdata->fifo_size)
> + pdata->fifo_size = 4;
> +
> + pdata->recv_fifo = kfifo_alloc(pdata->fifo_size);
> +
> + pdata->poller.func = ic2_key_poller;
> +
> + cdev = &pdata->cdev;
> + dev->type_data = cdev;
> + cdev->dev = dev;
> + cdev->f_caps = CONSOLE_STDIN;
> + cdev->tstc = twl6030_pwrbtn_tstc;
> + cdev->getc = twl6030_pwrbtn_getc;
> +
> + console_register(&pdata->cdev);
> +
> + return poller_register(&pdata->poller);
> +}
> +
> +static struct driver_d twl6030_pwrbtn_driver = {
> + .name = "twl6030_pwrbtn",
> + .probe = twl6030_pwrbtn_probe,
> +};
> +device_platform_driver(twl6030_pwrbtn_driver);
> diff --git a/include/twl6030_pwrbtn.h b/include/twl6030_pwrbtn.h
> new file mode 100644
> index 0000000..e7e8383
> --- /dev/null
> +++ b/include/twl6030_pwrbtn.h
> @@ -0,0 +1,23 @@
> +#ifndef _TWL6030_PWRBTN_H
> +#define _TWL6030_PWRBTN_H
> +
> +#include <poller.h>
> +#include <kfifo.h>
> +#include <mfd/twl6030.h>
> +
> +struct twl6030_pwrbtn_platform_data {
> + /* Configuration parameters */
> + int code;
> + /* optional */
> + int fifo_size;
Since this driver handles a single key only, must the fifo size
be configurable?
> +
> + /* internal */
> + u8 previous_state;
> +
> + struct twl6030 *twl6030;
> + struct kfifo *recv_fifo;
> + struct poller_struct poller;
> + struct console_device cdev;
> +};
Please do not abuse platform_data for private driver data use. Allocate
a separate struct for it.
Sascha
--
Pengutronix e.K. | |
Industrial Linux Solutions | http://www.pengutronix.de/ |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
More information about the barebox
mailing list