mirror of
https://xff.cz/git/u-boot/
synced 2025-08-31 08:12:06 +02:00
input: Implemented touchpanel uclass for touchpanel devices
Touchapnel devices are useful in u-boot for implementation of boot menu user interfaces on tablets and other touch based devices. This uclass implements start, stop and get_touches interface methods. Signed-off-by: Ondrej Jirman <megous@megous.com>
This commit is contained in:
committed by
Ondrej Jirman
parent
07bed1ed80
commit
700a8067f2
@@ -100,3 +100,12 @@ config TWL4030_INPUT
|
||||
bool "Enable TWL4030 Input controller"
|
||||
help
|
||||
Enable TWL4030 Input controller
|
||||
|
||||
config DM_TOUCHPANEL
|
||||
bool "Enable driver model for touchpanel support"
|
||||
depends on DM
|
||||
help
|
||||
This adds a uclass for touchpanel input and implements support
|
||||
using driver model. The API is implemented by touchpanel.h and
|
||||
includes methods to start/stop the device and check for available
|
||||
input.
|
||||
|
@@ -14,4 +14,6 @@ obj-$(CONFIG_APPLE_SPI_KEYB) += apple_spi_kbd.o
|
||||
obj-$(CONFIG_I8042_KEYB) += i8042.o
|
||||
obj-$(CONFIG_TEGRA_KEYBOARD) += input.o tegra-kbc.o
|
||||
obj-$(CONFIG_TWL4030_INPUT) += twl4030.o
|
||||
obj-$(CONFIG_DM_TOUCHPANEL) += touchpanel-uclass.o
|
||||
|
||||
endif
|
||||
|
67
drivers/input/touchpanel-uclass.c
Normal file
67
drivers/input/touchpanel-uclass.c
Normal file
@@ -0,0 +1,67 @@
|
||||
// SPDX-License-Identifier: GPL-2.0+
|
||||
/*
|
||||
* Copyright (c) 2018 Ondrej Jirman <megous@megous.com>
|
||||
*/
|
||||
|
||||
#include <common.h>
|
||||
#include <errno.h>
|
||||
#include <dm.h>
|
||||
#include <dm/uclass-internal.h>
|
||||
#include <touchpanel.h>
|
||||
|
||||
int touchpanel_start(struct udevice *dev)
|
||||
{
|
||||
const struct touchpanel_ops *ops = touchpanel_get_ops(dev);
|
||||
|
||||
if (!ops || !ops->start)
|
||||
return -ENOSYS;
|
||||
|
||||
return ops->start(dev);
|
||||
}
|
||||
|
||||
int touchpanel_stop(struct udevice *dev)
|
||||
{
|
||||
const struct touchpanel_ops *ops = touchpanel_get_ops(dev);
|
||||
|
||||
if (!ops || !ops->stop)
|
||||
return -ENOSYS;
|
||||
|
||||
return ops->stop(dev);
|
||||
}
|
||||
|
||||
int touchpanel_get_touches(struct udevice *dev,
|
||||
struct touchpanel_touch* touches, int max_touches)
|
||||
{
|
||||
const struct touchpanel_ops *ops = touchpanel_get_ops(dev);
|
||||
|
||||
if (!ops || !ops->get_touches)
|
||||
return -ENOSYS;
|
||||
|
||||
return ops->get_touches(dev, touches, max_touches);
|
||||
}
|
||||
|
||||
static int touchpanel_pre_probe(struct udevice *dev)
|
||||
{
|
||||
struct touchpanel_priv *uc_priv;
|
||||
|
||||
uc_priv = dev_get_uclass_priv(dev);
|
||||
if (!uc_priv)
|
||||
return -ENXIO;
|
||||
|
||||
uc_priv->size_x = dev_read_u32_default(dev, "touchscreen-size-x",
|
||||
-ENODATA);
|
||||
uc_priv->size_y = dev_read_u32_default(dev, "touchscreen-size-y",
|
||||
-ENODATA);
|
||||
|
||||
if (uc_priv->size_x == -ENODATA || uc_priv->size_y == -ENODATA)
|
||||
uc_priv->size_x = uc_priv->size_y = -ENODATA;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
UCLASS_DRIVER(touchpanel) = {
|
||||
.id = UCLASS_TOUCHPANEL,
|
||||
.name = "touchpanel",
|
||||
.pre_probe = touchpanel_pre_probe,
|
||||
.per_device_auto = sizeof(struct touchpanel_priv),
|
||||
};
|
@@ -142,6 +142,7 @@ enum uclass_id {
|
||||
UCLASS_TEE, /* Trusted Execution Environment device */
|
||||
UCLASS_THERMAL, /* Thermal sensor */
|
||||
UCLASS_TIMER, /* Timer device */
|
||||
UCLASS_TOUCHPANEL, /* Touch panel driver */
|
||||
UCLASS_TPM, /* Trusted Platform Module TIS interface */
|
||||
UCLASS_UFS, /* Universal Flash Storage */
|
||||
UCLASS_USB, /* USB bus */
|
||||
|
61
include/touchpanel.h
Normal file
61
include/touchpanel.h
Normal file
@@ -0,0 +1,61 @@
|
||||
#ifndef __TOUCHPANEL_H
|
||||
#define __TOUCHPANEL_H
|
||||
|
||||
/**
|
||||
* struct touchpanel_priv - information about a touchpanel, for the uclass
|
||||
*
|
||||
* @sdev: stdio device
|
||||
*/
|
||||
struct touchpanel_priv {
|
||||
int size_x;
|
||||
int size_y;
|
||||
};
|
||||
|
||||
struct touchpanel_touch {
|
||||
int id;
|
||||
int x;
|
||||
int y;
|
||||
};
|
||||
|
||||
/**
|
||||
* struct touchpanel_ops - touchpanel device operations
|
||||
*/
|
||||
struct touchpanel_ops {
|
||||
/**
|
||||
* start() - enable the touchpanel to be ready for use
|
||||
*
|
||||
* @dev: Device to enable
|
||||
* @return 0 if OK, -ve on error
|
||||
*/
|
||||
int (*start)(struct udevice *dev);
|
||||
|
||||
/**
|
||||
* stop() - disable the touchpanel when no-longer needed
|
||||
*
|
||||
* @dev: Device to disable
|
||||
* @return 0 if OK, -ve on error
|
||||
*/
|
||||
int (*stop)(struct udevice *dev);
|
||||
|
||||
/**
|
||||
* get_touches() - get list of active touches
|
||||
*
|
||||
* @dev: Device to read from
|
||||
* @touches: Array where to store touches. If NULL, the driver will
|
||||
* only return number of touches available.
|
||||
* @max_touches: Size of an touches array
|
||||
* @return -EAGAIN if no touch is available, otherwise number of touches
|
||||
* available.
|
||||
*/
|
||||
int (*get_touches)(struct udevice *dev,
|
||||
struct touchpanel_touch* touches, int max_touches);
|
||||
};
|
||||
|
||||
#define touchpanel_get_ops(dev) ((struct touchpanel_ops *)(dev)->driver->ops)
|
||||
|
||||
int touchpanel_start(struct udevice *dev);
|
||||
int touchpanel_stop(struct udevice *dev);
|
||||
int touchpanel_get_touches(struct udevice *dev,
|
||||
struct touchpanel_touch* touches, int max_touches);
|
||||
|
||||
#endif /* __TOUCHPANEL_H */
|
Reference in New Issue
Block a user