Re: [U-Boot] [PATCH v2 08/28] dm: cros_ec: Convert cros_ec keyboard driver to driver model

2015-10-30 Thread Simon Glass
Applied to u-boot-dm.
___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


[U-Boot] [PATCH v2 08/28] dm: cros_ec: Convert cros_ec keyboard driver to driver model

2015-10-18 Thread Simon Glass
Adjust the cros_ec keyboard driver to support driver model. Make this the
default for all Exynos boards so that those that use a keyboard will build
correctly with this driver.

Signed-off-by: Simon Glass 
---

Changes in v2: None

 README   |   5 --
 arch/arm/Kconfig |   1 +
 arch/sandbox/Kconfig |   3 +
 drivers/input/cros_ec_keyb.c | 148 +--
 4 files changed, 62 insertions(+), 95 deletions(-)

diff --git a/README b/README
index ca49225..d381422 100644
--- a/README
+++ b/README
@@ -1793,11 +1793,6 @@ CBFS (Coreboot Filesystem) support
Export function i8042_kbd_init, i8042_tstc and i8042_getc
for cfb_console. Supports cursor blinking.
 
-   CONFIG_CROS_EC_KEYB
-   Enables a Chrome OS keyboard using the CROS_EC interface.
-   This uses CROS_EC to communicate with a second microcontroller
-   which provides key scans on request.
-
 - Video support:
CONFIG_VIDEO
 
diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
index 7981355..f29febe 100644
--- a/arch/arm/Kconfig
+++ b/arch/arm/Kconfig
@@ -420,6 +420,7 @@ config ARCH_EXYNOS
select DM_SERIAL
select DM_SPI
select DM_GPIO
+   select DM_KEYBOARD
 
 config ARCH_S5PC1XX
bool "Samsung S5PC1XX"
diff --git a/arch/sandbox/Kconfig b/arch/sandbox/Kconfig
index f078c9e..25e316c 100644
--- a/arch/sandbox/Kconfig
+++ b/arch/sandbox/Kconfig
@@ -17,4 +17,7 @@ config PCI
  used on some devices to allow the CPU to communicate with its
  peripherals.
 
+config DM_KEYBOARD
+   default y
+
 endmenu
diff --git a/drivers/input/cros_ec_keyb.c b/drivers/input/cros_ec_keyb.c
index 88397b0..fe5caea 100644
--- a/drivers/input/cros_ec_keyb.c
+++ b/drivers/input/cros_ec_keyb.c
@@ -8,9 +8,11 @@
 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 
@@ -22,31 +24,29 @@ enum {
KBC_REPEAT_DELAY_MS = 240,
 };
 
-static struct keyb {
-   struct cros_ec_dev *dev;/* The CROS_EC device */
-   struct input_config input;  /* The input layer */
+struct cros_ec_keyb_priv {
+   struct input_config *input; /* The input layer */
struct key_matrix matrix;   /* The key matrix layer */
int key_rows;   /* Number of keyboard rows */
int key_cols;   /* Number of keyboard columns */
int ghost_filter;   /* 1 to enable ghost filter, else 0 */
-   int inited; /* 1 if keyboard is ready */
-} config;
+};
 
 
 /**
  * Check the keyboard controller and return a list of key matrix positions
  * for which a key is pressed
  *
- * @param config   Keyboard config
+ * @param dev  Keyboard device
  * @param keys List of keys that we have detected
  * @param max_countMaximum number of keys to return
  * @param samepSet to true if this scan repeats the last, else 
false
  * @return number of pressed keys, 0 for none, -EIO on error
  */
-static int check_for_keys(struct keyb *config,
-  struct key_matrix_key *keys, int max_count,
-  bool *samep)
+static int check_for_keys(struct udevice *dev, struct key_matrix_key *keys,
+ int max_count, bool *samep)
 {
+   struct cros_ec_keyb_priv *priv = dev_get_priv(dev);
struct key_matrix_key *key;
static struct mbkp_keyscan last_scan;
static bool last_scan_valid;
@@ -54,7 +54,7 @@ static int check_for_keys(struct keyb *config,
unsigned int row, col, bit, data;
int num_keys;
 
-   if (cros_ec_scan_keyboard(config->dev->dev, )) {
+   if (cros_ec_scan_keyboard(dev->parent, )) {
debug("%s: keyboard scan failed\n", __func__);
return -EIO;
}
@@ -69,9 +69,9 @@ static int check_for_keys(struct keyb *config,
last_scan_valid = true;
memcpy(_scan, , sizeof(last_scan));
 
-   for (col = num_keys = bit = 0; col < config->matrix.num_cols;
+   for (col = num_keys = bit = 0; col < priv->matrix.num_cols;
col++) {
-   for (row = 0; row < config->matrix.num_rows; row++) {
+   for (row = 0; row < priv->matrix.num_rows; row++) {
unsigned int mask = 1 << (bit & 7);
 
data = scan.data[bit / 8];
@@ -89,28 +89,6 @@ static int check_for_keys(struct keyb *config,
 }
 
 /**
- * Test if keys are available to be read
- *
- * @return 0 if no keys available, 1 if keys are available
- */
-static int kbd_tstc(struct stdio_dev *dev)
-{
-   /* Just get input to do this for us */
-   return config.inited ? input_tstc() : 0;
-}
-
-/**
- * Read a key
- *
- * @return ASCII key code, or 0 if no key, or -1 if error
- */
-static int kbd_getc(struct stdio_dev