Add cros-ec protocol driver and enable it in smdk5250
Subsystems (7)
v2 cover Add cros-ec protocol driver and enable it in smdk5250
This patch series adds the drivers for the cros-ec protocol that is used to communicate with the ChromeOS Embedded Controller (EC). The series also enables its use in Google Snow based on smdk5250.
The series depends on the following patches:
1) http://patchwork.ozlabs.org/patch/217347 add dts file for Snow
2) mmc series: http://patchwork.ozlabs.org/patch/225008
3) power patches needed by one of the mmc patches
http://patchwork.ozlabs.org/patch/220060 EXYNOS5: Add function to setup set ps hold
http://patchwork.ozlabs.org/patch/220061 SMDK5250: Add PMIC voltage settings (needed by one of the mmc patches)
-----
Changes in v2:
- Moved code from smdk5250.c (non-FDT) to exynos5-dt.c (FDT).
- Moved code from smdk5250.h to exynos5250-dt.h.
- Add gpio node to exynos5250.dtsi.
- Fixed warnings of exceeding 80 chars in a line.
- Added commit messages to each patch.
- Dropped the period from commit subjects.
Hung-ying Tyan (7):
cros: add cros_ec driver
cros: add I2C support for cros_ec
cros: add SPI support for cros_ec
cros: add LPC support for cros_ec
cros: adds cros_ec keyboard driver
cros: exynos: add cros-ec device nodes to exynos5250-snow.dts
cros: enable cros-ec for smdk5250
README | 5 + arch/arm/dts/exynos5250.dtsi | 3 + board/samsung/dts/exynos5250-snow.dts | 82 ++ board/samsung/smdk5250/exynos5-dt.c | 45 + doc/device-tree-bindings/input/cros-ec-keyb.txt | 79 ++ doc/device-tree-bindings/misc/cros-ec.txt | 38 + doc/device-tree-bindings/spi/exynos-spi.txt | 55 + drivers/input/Makefile | 1 + drivers/input/cros_ec_keyb.c | 264 +++++ drivers/misc/Makefile | 4 + drivers/misc/cros_ec.c | 1304 ++++++++++++++++++++ drivers/misc/cros_ec_i2c.c | 199 ++++ drivers/misc/cros_ec_lpc.c | 283 +++++ drivers/misc/cros_ec_spi.c | 166 +++ drivers/spi/exynos_spi.c | 22 + include/configs/exynos5250-dt.h | 10 +- include/cros_ec.h | 449 +++++++ include/cros_ec_message.h | 44 + include/ec_commands.h | 1440 +++++++++++++++++++++++ include/fdtdec.h | 2 + include/spi.h | 16 + lib/fdtdec.c | 2 + 22 files changed, 4512 insertions(+), 1 deletion(-) create mode 100644 doc/device-tree-bindings/input/cros-ec-keyb.txt create mode 100644 doc/device-tree-bindings/misc/cros-ec.txt create mode 100644 doc/device-tree-bindings/spi/exynos-spi.txt create mode 100644 drivers/input/cros_ec_keyb.c create mode 100644 drivers/misc/cros_ec.c create mode 100644 drivers/misc/cros_ec_i2c.c create mode 100644 drivers/misc/cros_ec_lpc.c create mode 100644 drivers/misc/cros_ec_spi.c create mode 100644 include/cros_ec.h create mode 100644 include/cros_ec_message.h create mode 100644 include/ec_commands.h
Signature · 1 line
1.8.1.3
PATCH v2 1/7 cros: add cros_ec driver
This patch adds the cros_ec driver that implements the protocol for communicating with Google's ChromeOS embedded controller.
---
Changes in v2:
- Wrapped lines to comply with the 80-char rule.
doc/device-tree-bindings/input/cros-ec-keyb.txt | 79 ++ doc/device-tree-bindings/misc/cros-ec.txt | 38 + doc/device-tree-bindings/spi/exynos-spi.txt | 55 + drivers/misc/Makefile | 1 + drivers/misc/cros_ec.c | 1304 ++++++++++++++++++++ include/cros_ec.h | 449 +++++++ include/cros_ec_message.h | 44 + include/ec_commands.h | 1440 +++++++++++++++++++++++ include/fdtdec.h | 1 + lib/fdtdec.c | 1 + 10 files changed, 3412 insertions(+) create mode 100644 doc/device-tree-bindings/input/cros-ec-keyb.txt create mode 100644 doc/device-tree-bindings/misc/cros-ec.txt create mode 100644 doc/device-tree-bindings/spi/exynos-spi.txt create mode 100644 drivers/misc/cros_ec.c create mode 100644 include/cros_ec.h create mode 100644 include/cros_ec_message.h create mode 100644 include/ec_commands.h
doc/device-tree-bindings/input/cros-ec-keyb.txt new file +79 -0
@@ -0,0 +1,79 @@ +CROS_EC Keyboard + +The CROS_EC (Matrix Keyboard Protocol) allows communcation with a secondary +micro used for keyboard, and possible other features. + +The CROS_EC keyboard uses this protocol to receive key scans and produce input +in U-Boot. + +Required properties : +- compatible : "google,cros-ec-keyb" +- google,key-rows : Number of key rows +- google,key-columns : Number of key columns + +Optional properties, in addition to those specified by the shared +matrix-keyboard bindings: + +- linux,fn-keymap: a second keymap, same specification as the + matrix-keyboard-controller spec but to be used when the KEY_FN modifier + key is pressed. +- google,repeat-delay-ms : delay in milliseconds before repeat starts +- google,repeat-rate-ms : delay between each subsequent key press +- google,ghost-filter : enable ghost filtering for this device + +Example, taken from daisy: + +cros-ec-keyb { + compatible = "google,cros-ec-keyb"; + google,key-rows = <8>; + google,key-columns = <13>; + google,ghost-filter; + google,repeat-delay-ms = <240>; + google,repeat-rate-ms = <30>; + /* + * Keymap entries take the form of 0xRRCCKKKK where + * RR=Row CC=Column KKKK=Key Code + * The values below are for a US keyboard layout and + * are taken from the Linux driver. Note that the + * 102ND key is not used for US keyboards. + */ + linux,keymap = < + /* CAPSLCK F1 B F10 */ + 0x0001003a 0x0002003c 0x00030030 0x00040044 + /* N = R_ALT ESC */ + 0x00060031 0x0008000d 0x000a0064 0x01010001 + /* F4 G F7 H */ + 0x0102003e 0x01030022 0x01040041 0x01060023 + /* ' F9 BKSPACE L_CTRL */ + 0x01080028 0x01090043 0x010b000e 0x0200001d + /* TAB F3 T F6 */ + 0x0201000f 0x0202003d 0x02030014 0x02040040 + /* ] Y 102ND [ */ + 0x0205001b 0x02060015 0x02070056 0x0208001a + /* F8 GRAVE F2 5 */ + 0x02090042 0x03010029 0x0302003c 0x03030006 + /* F5 6 - \ */ + 0x0304003f 0x03060007 0x0308000c 0x030b002b + /* R_CTRL A D F */ + 0x04000061 0x0401001e 0x04020020 0x04030021 + /* S K J ; */ + 0x0404001f 0x04050025 0x04060024 0x04080027 + /* L ENTER Z C */ + 0x04090026 0x040b001c 0x0501002c 0x0502002e + /* V X , M */ + 0x0503002f 0x0504002d 0x05050033 0x05060032 + /* L_SHIFT / . SPACE */ + 0x0507002a 0x05080035 0x05090034 0x050B0039 + /* 1 3 4 2 */ + 0x06010002 0x06020004 0x06030005 0x06040003 + /* 8 7 0 9 */ + 0x06050009 0x06060008 0x0608000b 0x0609000a + /* L_ALT DOWN RIGHT Q */ + 0x060a0038 0x060b006c 0x060c006a 0x07010010 + /* E R W I */ + 0x07020012 0x07030013 0x07040011 0x07050017 + /* U R_SHIFT P O */ + 0x07060016 0x07070036 0x07080019 0x07090018 + /* UP LEFT */ + 0x070b0067 0x070c0069>; +};
doc/device-tree-bindings/misc/cros-ec.txt new file +38 -0
@@ -0,0 +1,38 @@ +Chrome OS CROS_EC Binding +====================== + +The device tree node which describes the operation of the CROS_EC interface +is as follows: + +Required properties : +- compatible = "google,cros-ec" + +Optional properties : +- spi-max-frequency : Sets the maximum frequency (in Hz) for SPI bus + operation +- i2c-max-frequency : Sets the maximum frequency (in Hz) for I2C bus + operation +- ec-interrupt : Selects the EC interrupt, defined as a GPIO according + to the platform +- optimise-flash-write : Boolean property - if present then flash blocks + containing all 0xff will not be written, since we assume that the EC + uses that pattern for erased blocks + +The CROS_EC node should appear as a subnode of the interrupt that connects it +to the EC (e.g. i2c, spi, lpc). The reg property (as usual) will indicate +the unit address on that bus. + + +Example +======= + + spi at 131b0000 { + cros-ec at 0 { + reg = <0>; + compatible = "google,cros-ec"; + spi-max-frequency = <5000000>; + ec-interrupt = <&gpio 174 1>; + optimise-flash-write; + status = "disabled"; + }; + };
doc/device-tree-bindings/spi/exynos-spi.txt new file +55 -0
55 lines not on this page · raw message
drivers/misc/Makefile +1 -0
@@ -30,6 +30,7 @@ COBJS-$(CONFIG_DS4510) += ds4510.o COBJS-$(CONFIG_CBMEM_CONSOLE) += cbmem_console.o COBJS-$(CONFIG_GPIO_LED) += gpio_led.o COBJS-$(CONFIG_FSL_MC9SDZ60) += mc9sdz60.o +COBJS-$(CONFIG_CROS_EC) += cros_ec.o COBJS-$(CONFIG_NS87308) += ns87308.o COBJS-$(CONFIG_PDSP188x) += pdsp188x.o COBJS-$(CONFIG_STATUS_LED) += status_led.o
drivers/misc/cros_ec.c new file +1304 -0
1,304 lines not on this page · raw message
include/cros_ec.h new file +449 -0
449 lines not on this page · raw message
include/cros_ec_message.h new file +44 -0
44 lines not on this page · raw message
include/ec_commands.h new file +1440 -0
1,024 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
1.8.1.3
Part of the diff is not shown here. View the raw message.
PATCH v2 1/7 cros: add cros_ec driver
Quoted 14 lines · Hung-ying Tyan
This patch adds the
cros_ecdriver that implements the protocol for communicating with Google's ChromeOS embedded controller.Signed-off-by Bernie Thompson <[email protected]>Signed-off-by Bill Richardson <[email protected]>Signed-off-by Che-Liang Chiou <[email protected]>Signed-off-by Doug Anderson <[email protected]>Signed-off-by Gabe Black <[email protected]>Signed-off-by Hung-ying Tyan <[email protected]>Signed-off-by Louis Yung-Chieh Lo <[email protected]>Signed-off-by Randall Spangler <[email protected]>Signed-off-by Sean Paul <[email protected]>Signed-off-by Simon Glass <[email protected]>Signed-off-by Vincent Palatin <[email protected]>
PATCH v2 2/7 cros: add I2C support for cros_ec
In reply to Hung-ying TyanThis patch adds I2C support for carrying out the cros_ec protocol.
---
Changes in v2:
- Wrapped lines to comply with the 80-char rule.
drivers/misc/Makefile | 1 + drivers/misc/cros_ec_i2c.c | 199 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 200 insertions(+) create mode 100644 drivers/misc/cros_ec_i2c.c
drivers/misc/Makefile +1 -0
@@ -31,6 +31,7 @@ COBJS-$(CONFIG_CBMEM_CONSOLE) += cbmem_console.o COBJS-$(CONFIG_GPIO_LED) += gpio_led.o COBJS-$(CONFIG_FSL_MC9SDZ60) += mc9sdz60.o COBJS-$(CONFIG_CROS_EC) += cros_ec.o +COBJS-$(CONFIG_CROS_EC_I2C) += cros_ec_i2c.o COBJS-$(CONFIG_NS87308) += ns87308.o COBJS-$(CONFIG_PDSP188x) += pdsp188x.o COBJS-$(CONFIG_STATUS_LED) += status_led.o
drivers/misc/cros_ec_i2c.c new file +199 -0
199 lines not on this page · raw message
Signature · 1 line
1.8.1.3
PATCH v2 2/7 cros: add I2C support for cros_ec
Quoted 6 lines · Hung-ying Tyan
This patch adds I2C support for carrying out the
cros_ecprotocol.Signed-off-by Randall Spangler <[email protected]>Signed-off-by Simon Glass <[email protected]>Signed-off-by Hung-ying Tyan <[email protected]>
Quoted 8 lines
---
Changes in v2:
- Wrapped lines to comply with the 80-char rule.drivers/misc/Makefile | 1 + drivers/misc/cros_ec_i2c.c | 199 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 200 insertions(+) create mode 100644 drivers/misc/cros_ec_i2c.c
PATCH v2 3/7 cros: add SPI support for cros_ec
In reply to Hung-ying TyanThis patch adds SPI support for carrying out the cros_ec protocol.
---
Changes in v2:
- Wrapped lines to comply with the 80-char rule.
drivers/misc/Makefile | 1 + drivers/misc/cros_ec_spi.c | 166 +++++++++++++++++++++++++++++++++++++++++++++ drivers/spi/exynos_spi.c | 22 ++++++ include/spi.h | 16 +++++ 4 files changed, 205 insertions(+) create mode 100644 drivers/misc/cros_ec_spi.c
drivers/misc/Makefile +1 -0
@@ -32,6 +32,7 @@ COBJS-$(CONFIG_GPIO_LED) += gpio_led.o COBJS-$(CONFIG_FSL_MC9SDZ60) += mc9sdz60.o COBJS-$(CONFIG_CROS_EC) += cros_ec.o COBJS-$(CONFIG_CROS_EC_I2C) += cros_ec_i2c.o +COBJS-$(CONFIG_CROS_EC_SPI) += cros_ec_spi.o COBJS-$(CONFIG_NS87308) += ns87308.o COBJS-$(CONFIG_PDSP188x) += pdsp188x.o COBJS-$(CONFIG_STATUS_LED) += status_led.o
drivers/misc/cros_ec_spi.c new file +166 -0
166 lines not on this page · raw message
drivers/spi/exynos_spi.c +22 -0
@@ -416,6 +416,28 @@ static int process_nodes(const void *blob, int node_list[], int count)return 0 ; } +/** +* Set up a new SPI slave for an fdt node +* +* @param blob Device tree blob +* @param node SPI peripheral node to use +* @return 0 if ok, -1 on error +*/ +struct spi_slave *spi_setup_slave_fdt (const void *blob,int node, +unsigned int cs,unsigned int max_hz,unsigned int mode) +{ +struct spi_bus *bus; +unsigned int i; + +for (i =0 , bus = spi_bus; i < bus_count; i++, bus++) { +if (bus->node == node) +return spi_setup_slave (i, cs, max_hz, mode); + } + +debug ("%s: Failed to find bus node %d\n" , __func__, node); +return NULL ; +} +/* Sadly there is no error return from this function */ void spi_init (void ) {
include/spi.h +16 -0
@@ -198,4 +198,20 @@ static inline int spi_w8r8(struct spi_slave *slave, unsigned char byte) return ret < 0 ? ret : din[1]; } +/** +* Set up a SPI slave for a particular device tree node +* +* This calls spi_setup_slave() with the correct bus number. Call +* spi_free_slave() to free it later. +* +* @param blob Device tree blob +* @param node SPI peripheral node to use +* @param cs Chip select to use +* @param max_hz Maximum SCK rate in Hz (0 for default) +* @param mode Clock polarity, clock phase and other parameters +* @return pointer to new spi_slave structure +*/ +struct spi_slave *spi_setup_slave_fdt (const void *blob,int node, +unsigned int cs,unsigned int max_hz,unsigned int mode); +#endif /* _SPI_H_ */
Signature · 1 line
1.8.1.3
PATCH v2 3/7 cros: add SPI support for cros_ec
Quoted 9 lines · Hung-ying Tyan
This patch adds SPI support for carrying out the
cros_ecprotocol.Signed-off-by Hung-ying Tyan <[email protected]>Signed-off-by Randall Spangler <[email protected]>Signed-off-by Simon Glass <[email protected]>---
Changes in v2:
- Wrapped lines to comply with the 80-char rule.
PATCH v2 4/7 cros: add LPC support for cros_ec
In reply to Hung-ying TyanThis patch adds LPC support for carrying out the cros_ec protocol.
---
Changes in v2:
- Wrapped lines to comply with the 80-char rule.
drivers/misc/Makefile | 1 + drivers/misc/cros_ec_lpc.c | 283 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 284 insertions(+) create mode 100644 drivers/misc/cros_ec_lpc.c
drivers/misc/Makefile +1 -0
@@ -31,6 +31,7 @@ COBJS-$(CONFIG_CBMEM_CONSOLE) += cbmem_console.o COBJS-$(CONFIG_GPIO_LED) += gpio_led.o COBJS-$(CONFIG_FSL_MC9SDZ60) += mc9sdz60.o COBJS-$(CONFIG_CROS_EC) += cros_ec.o +COBJS-$(CONFIG_CROS_EC_LPC) += cros_ec_lpc.o COBJS-$(CONFIG_CROS_EC_I2C) += cros_ec_i2c.o COBJS-$(CONFIG_CROS_EC_SPI) += cros_ec_spi.o COBJS-$(CONFIG_NS87308) += ns87308.o
drivers/misc/cros_ec_lpc.c new file +283 -0
283 lines not on this page · raw message
Signature · 1 line
1.8.1.3
PATCH v2 4/7 cros: add LPC support for cros_ec
Quoted 9 lines · Hung-ying Tyan
This patch adds LPC support for carrying out the
cros_ecprotocol.Signed-off-by Randall Spangler <[email protected]>Signed-off-by Simon Glass <[email protected]>Signed-off-by Hung-ying Tyan <[email protected]>---
Changes in v2:
- Wrapped lines to comply with the 80-char rule.
PATCH v2 5/7 cros: adds cros_ec keyboard driver
In reply to Hung-ying TyanThis patch adds the driver for keyboard that's controlled by ChromeOS EC.
---
Changes in v2:
- Wrapped lines to comply with the 80-char rule.
README | 5 + drivers/input/Makefile | 1 + drivers/input/cros_ec_keyb.c | 264 +++++++++++++++++++++++++++++++++++++++++++ include/fdtdec.h | 1 + lib/fdtdec.c | 1 + 5 files changed, 272 insertions(+) create mode 100644 drivers/input/cros_ec_keyb.c
README +5 -0
@@ -1371,6 +1371,11 @@ 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
drivers/input/Makefile +1 -0
@@ -27,6 +27,7 @@ LIB := $(obj)libinput.o COBJS-$(CONFIG_I8042_KBD) += i8042.o COBJS-$(CONFIG_TEGRA_KEYBOARD) += tegra-kbc.o +COBJS-$(CONFIG_CROS_EC_KEYB) += cros_ec_keyb.o ifdef CONFIG_PS2KBD COBJS-y += keyboard.o pc_keyb.o COBJS-$(CONFIG_PS2MULT) += ps2mult.o ps2ser.o
drivers/input/cros_ec_keyb.c new file +264 -0
264 lines not on this page · raw message
include/fdtdec.h +1 -0
@@ -79,6 +79,7 @@ enum fdt_compat_id {COMPAT_WOLFSON_WM8994_CODEC ,/* Wolfson WM8994 Sound Codec */ COMPAT_SAMSUNG_EXYNOS_SPI ,/* Exynos SPI */ COMPAT_GOOGLE_CROS_EC ,/* Google CROS_EC Protocol */ +COMPAT_GOOGLE_CROS_EC_KEYB ,/* Google CROS_EC Keyboard */ COMPAT_SAMSUNG_EXYNOS_EHCI ,/* Exynos EHCI controller */ COMPAT_SAMSUNG_EXYNOS_USB_PHY ,/* Exynos phy controller for usb2.0 */ COMPAT_MAXIM_MAX77686_PMIC, /* MAX77686 PMIC */
lib/fdtdec.c +1 -0
@@ -54,6 +54,7 @@ static const char * const compat_names[COMPAT_COUNT] = {COMPAT (WOLFSON_WM8994_CODEC ,"wolfson,wm8994-codec" ),COMPAT (SAMSUNG_EXYNOS_SPI ,"samsung,exynos-spi" ),COMPAT (GOOGLE_CROS_EC ,"google,cros-ec" ), +COMPAT (GOOGLE_CROS_EC_KEYB ,"google,cros-ec-keyb" ),COMPAT (SAMSUNG_EXYNOS_EHCI ,"samsung,exynos-ehci" ),COMPAT (SAMSUNG_EXYNOS_USB_PHY ,"samsung,exynos-usb-phy" ), COMPAT(MAXIM_MAX77686_PMIC, "maxim,max77686_pmic"),
Signature · 1 line
1.8.1.3
PATCH v2 5/7 cros: adds cros_ec keyboard driver
Hi Hung-ying,
Quoted 71 lines · Hung-ying Tyan
This patch adds the driver for keyboard that's controlled by ChromeOS EC.
Signed-off-by Randall Spangler <[email protected]>Signed-off-by Simon Glass <[email protected]>Signed-off-by Vincent Palatin <[email protected]>Signed-off-by Hung-ying Tyan <[email protected]>---
Changes in v2:
- Wrapped lines to comply with the 80-char rule.README | 5 + drivers/input/Makefile | 1 + drivers/input/cros_ec_keyb.c | 264 +++++++++++++++++++++++++++++++++++++++++++ include/fdtdec.h | 1 + lib/fdtdec.c | 1 + 5 files changed, 272 insertions(+) create mode 100644 drivers/input/cros_ec_keyb.cREADME +5
-0@@ -1371,6 +1371,11 @@ 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_VIDEOdrivers/input/Makefile +1
-0@@ -27,6 +27,7 @@ LIB := $(obj)libinput.o COBJS-$(CONFIG_I8042_KBD) += i8042.o COBJS-$(CONFIG_TEGRA_KEYBOARD) += tegra-kbc.o +COBJS-$(CONFIG_CROS_EC_KEYB) += cros_ec_keyb.o ifdef CONFIG_PS2KBD COBJS-y += keyboard.o pc_keyb.o COBJS-$(CONFIG_PS2MULT) += ps2mult.o ps2ser.odrivers/input/cros_ec_keyb.c new file +18
-0@@ -0,0 +1,264 @@ +/* +* Chromium OS Matrix Keyboard +* +* Copyright (c) 2012 The Chromium OS Authors. +* See file CREDITS for list of people who contributed to this +* project. +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License as +* published by the Free Software Foundation; either version 2 of +* the License, or (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License
drivers/input/cros_ec_keyb.c line 28
Quoted 10 lines
drivers/input/cros_ec_keyb.c new file +10
-0+* along with this program; if not, write to the Free Software +* Foundation, Inc., 59 Temple Place, Suite 330, Boston, +* MA 02111-1307 USA +*/ + +#include <common.h> +#include <fdtdec.h> +#include <input.h> +#include <key_matrix.h> +#include <cros_ec.h>
Please put this after common.h so it is in alphabetical order.
Quoted 34 lines
drivers/input/cros_ec_keyb.c new file +34
-0+#include <stdio_dev.h> + +DECLARE_GLOBAL_DATA_PTR ; + +enum { +KBC_MAX_KEYS =8 ,/* Maximum keys held down at once */ +}; + +static struct keyb { +struct cros_ec_dev *dev;/* The CROS_EC device */ +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 */ +unsigned int repeat_delay_ms;/* Time before autorepeat starts */ +unsigned int repeat_rate_ms;/* Autorepeat rate in ms */ +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 keys List of keys that we have detected +* @param max_count Maximum number of keys to return +* @return number of pressed keys, 0 for none +*/ +static int check_for_keys (struct keyb *config, +struct key_matrix_key *keys,int max_count) +{ +struct key_matrix_key *key;
drivers/input/cros_ec_keyb.c line 72
Quoted 10 lines
drivers/input/cros_ec_keyb.c new file +10
-0+struct mbkp_keyscan scan; +unsigned int row, col, bit, data; +int num_keys; + +if (cros_ec_scan_keyboard (config->dev, &scan)) { +debug ("%s: keyboard scan failed\n" , __func__); +return -1 ; + } + +/* TODO(sjg at chromium,org): Should perhaps optimize this algorithm */
I think we can remove this TODO now.
Quoted 51 lines
drivers/input/cros_ec_keyb.c new file +51
-0+for (col = num_keys = bit =0 ; col < config->matrix.num_cols; + col++) { +for (row =0 ; row < config->matrix.num_rows; row++) { +unsigned int mask =1 << (bit &7 ); + + data = scan.data[bit /8 ]; +if ((data & mask) && num_keys < max_count) { + key = keys + num_keys++; + key->row = row; + key->col = col; + key->valid =1 ; + } + bit++; + } + } + +return num_keys; +} + +/** +* Test if keys are available to be read +* +* @return 0 if no keys available, 1 if keys are available +*/ +static int kbd_tstc (void ) +{ +/* Just get input to do this for us */ +return config.inited ?input_tstc (&config.input) :0 ; +} + +/** +* Read a key +* +* @return ASCII key code, or 0 if no key, or -1 if error +*/ +static int kbd_getc (void ) +{ +/* Just get input to do this for us */ +return config.inited ?input_getc (&config.input) :0 ; +} + +/** +* Check the keyboard, and send any keys that are pressed. +* +* This is called by input_tstc() and input_getc() when they need more +* characters +* +* @param input Input configuration +* @return 1, to indicate that we have something to look at +*/ +int cros_ec_kbc_check (struct input_config *input)
drivers/input/cros_ec_keyb.c line 133
Quoted 10 lines
drivers/input/cros_ec_keyb.c new file +10
-0+{ +static struct key_matrix_key last_keys[KBC_MAX_KEYS ]; +static int last_num_keys; +struct key_matrix_key keys[KBC_MAX_KEYS ]; +int keycodes[KBC_MAX_KEYS ]; +int num_keys, num_keycodes; +int irq_pending, sent; + +/* +* crosbug.com/p/13864
You can remove this bug reference as it is not relevant.
Quoted 156 lines
drivers/input/cros_ec_keyb.c new file +131
-0+* +* Loop until the EC has no more keyscan records, or we have +* received at least one character. This means we know that tstc() +* will always return non-zero if keys have been pressed. +* +* Without this loop, a key release (which generates no new ascii +* characters) will cause us to exit this function, and just tstc() +* may return 0 before all keys have been read from the EC. +*/ +do { + irq_pending =cros_ec_interrupt_pending (config.dev); +if (irq_pending) { + num_keys =check_for_keys (&config, keys,KBC_MAX_KEYS ); + last_num_keys = num_keys; +memcpy (last_keys, keys,sizeof (keys)); + }else { +/* +* EC doesn't want to be asked, so use keys from last +* time. +*/ + num_keys = last_num_keys; +memcpy (keys, last_keys,sizeof (keys)); + } + +if (num_keys <0 ) +return -1 ; + num_keycodes =key_matrix_decode (&config.matrix, keys, + num_keys, keycodes,KBC_MAX_KEYS ); + sent =input_send_keycodes (input, keycodes, num_keycodes); + }while (irq_pending && !sent); + +return 1 ; +} + +/** +* Decode MBKP keyboard details from the device tree +* +* @param blob Device tree blob +* @param node Node to decode from +* @param config Configuration data read from fdt +* @return 0 if ok, -1 on error +*/ +static int cros_ec_keyb_decode_fdt (const void *blob,int node, +struct keyb *config) +{ +/* +* Get keyboard rows and columns - at present we are limited to +* 8 columns by the protocol (one byte per row scan) +*/ + config->key_rows =fdtdec_get_int (blob, node,"google,key-rows" ,0 ); + config->key_cols =fdtdec_get_int (blob, node,"google,key-columns" ,0 ); +if (!config->key_rows || !config->key_cols || + config->key_rows * config->key_cols /8 + >CROS_EC_KEYSCAN_COLS ) { +debug ("%s: Invalid key matrix size %d x %d\n" , __func__, + config->key_rows, config->key_cols); +return -1 ; + } + config->repeat_delay_ms =fdtdec_get_int (blob, node, +"google,repeat-delay-ms" ,0 ); + config->repeat_rate_ms =fdtdec_get_int (blob, node, +"google,repeat-rate-ms" ,0 ); + config->ghost_filter =fdtdec_get_bool (blob, node, +"google,ghost-filter" ); +return 0 ; +} + +/** +* Set up the keyboard. This is called by the stdio device handler. +* +* We want to do this init when the keyboard is actually used rather than +* at start-up, since keyboard input may not currently be selected. +* +* @return 0 if ok, -1 on error +*/ +static int cros_ec_init_keyboard (void ) +{ +const void *blob = gd->fdt_blob; +int node; + + config.dev =board_get_cros_ec_dev (); +if (!config.dev) { +debug ("%s: no cros_ec device: cannot init keyboard\n" , + __func__); +return -1 ; + } + node =fdtdec_next_compatible (blob,0 ,COMPAT_GOOGLE_CROS_EC_KEYB ); +if (node <0 ) { +debug ("%s: Node not found\n" , __func__); +return -1 ; + } +if (cros_ec_keyb_decode_fdt (blob, node, &config)) +return -1 ; +input_set_delays (&config.input, config.repeat_delay_ms, + config.repeat_rate_ms); +if (key_matrix_init (&config.matrix, config.key_rows, + config.key_cols, config.ghost_filter)) { +debug ("%s: cannot init key matrix\n" , __func__); +return -1 ; + } +if (key_matrix_decode_fdt (&config.matrix, gd->fdt_blob, node)) { +debug ("%s: Could not decode key matrix from fdt\n" , __func__); +return -1 ; + } + config.inited =1 ; +debug ("%s: Matrix keyboard %dx%d ready\n" , __func__, config.key_rows, + config.key_cols); + +return 0 ; +} + +int drv_keyboard_init (void ) +{ +struct stdio_dev dev; + +if (input_init (&config.input,0 )) { +debug ("%s: Cannot set up input\n" , __func__); +return -1 ; + } + config.input.read_keys = cros_ec_kbc_check; + +memset (&dev,'\0' ,sizeof (dev)); +strcpy (dev.name,"cros-ec-keyb" ); + dev.flags =DEV_FLAGS_INPUT |DEV_FLAGS_SYSTEM ; + dev.getc = kbd_getc; + dev.tstc = kbd_tstc; + dev.start = cros_ec_init_keyboard; + +/* Register the device. cros_ec_init_keyboard() will be called soon */ +return input_stdio_register (&dev); +}include/fdtdec.h +1
-0@@ -79,6 +79,7 @@ enum fdt_compat_id {COMPAT_WOLFSON_WM8994_CODEC ,/* Wolfson WM8994 Sound Codec */ COMPAT_SAMSUNG_EXYNOS_SPI ,/* Exynos SPI */ COMPAT_GOOGLE_CROS_EC ,/* Google CROS_EC Protocol */ +COMPAT_GOOGLE_CROS_EC_KEYB ,/* Google CROS_EC Keyboard */ COMPAT_SAMSUNG_EXYNOS_EHCI ,/* Exynos EHCI controller */ COMPAT_SAMSUNG_EXYNOS_USB_PHY ,/* Exynos phy controller for usb2.0 */ COMPAT_MAXIM_MAX77686_PMIC, /* MAX77686 PMIC */lib/fdtdec.c +1
-1@@ -54,6 +54,7 @@ static const char * const compat_names[COMPAT_COUNT] = {COMPAT (WOLFSON_WM8994_CODEC ,"wolfson,wm8994-codec" ),COMPAT (SAMSUNG_EXYNOS_SPI ,"samsung,exynos-spi" ),COMPAT (GOOGLE_CROS_EC ,"google,cros-ec" ), +COMPAT (GOOGLE_CROS_EC_KEYB ,"google,cros-ec-keyb" ),COMPAT (SAMSUNG_EXYNOS_EHCI ,"samsung,exynos-ehci" ),COMPAT (SAMSUNG_EXYNOS_USB_PHY ,"samsung,exynos-usb-phy" ), COMPAT(MAXIM_MAX77686_PMIC, "maxim,max77686_pmic"), --
Quoted 2 lines
1.8.1.3
Otherwise looks good to me.
Regards,
Simon
PATCH v2 6/7 cros: exynos: add cros-ec device nodes to exynos5250-snow.dts
In reply to Hung-ying Tyan---
Changes in v2:
- Add gpio node to exynos5250.dtsi.
arch/arm/dts/exynos5250.dtsi | 3 ++ board/samsung/dts/exynos5250-snow.dts | 82 +++++++++++++++++++++++++++++++++++ 2 files changed, 85 insertions(+)
arch/arm/dts/exynos5250.dtsi +3 -0
@@ -182,4 +182,7 @@ reg = <0x12230000 0x1000>; interrupts = <0 78 0>; }; + + gpio: gpio { + }; };
board/samsung/dts/exynos5250-snow.dts +82 -0
92 lines not on this page · raw message
Signature · 1 line
1.8.1.3
PATCH v2 6/7 cros: exynos: add cros-ec device nodes to exynos5250-snow.dts
Hi Hung-ying,
Quoted 6 lines · Hung-ying Tyan
Signed-off-by Hung-ying Tyan <[email protected]>---
Changes in v2:
- Add gpio node toexynos5250.dtsi.
This looks right to me. I think we will need to revisit the GPIO numbers when the exynos GPIO numbering series lands, but for now it looks right.
Quoted 4 lines
arch/arm/dts/exynos5250.dtsi | 3 ++ board/samsung/dts/exynos5250-snow.dts | 82 +++++++++++++++++++++++++++++++++++ 2 files changed, 85 insertions(+)
Regards,
Simon
PATCH v2 7/7 cros: enable cros-ec for smdk5250
In reply to Hung-ying TyanThis patch initiates cros-ec in board_init() to enable it for smdk5250.
---
Changes in v2:
- Code moved from smdk5250.c (non-FDT) to exynos5-dt.c (FDT).
- Code moved from smdk5250.h to exynos5250-dt.h.
board/samsung/smdk5250/exynos5-dt.c | 45 +++++++++++++++++++++++++++++++++++++ include/configs/exynos5250-dt.h | 10 ++++++++- 2 files changed, 54 insertions(+), 1 deletion(-)
board/samsung/smdk5250/exynos5-dt.c +45 -0
@@ -21,6 +21,7 @@*/ #include <common.h> +#include <cros_ec.h> #include <fdtdec.h> #include <asm/io.h> #include <errno.h>
@@ -39,6 +40,13 @@DECLARE_GLOBAL_DATA_PTR ; +struct local_info { +struct cros_ec_dev *cros_ec_dev;/* Pointer to cros_ec device */ +int cros_ec_err;/* Error for cros_ec, 0 if ok */ +}; + +static struct local_info local; +#ifdef CONFIG_USB_EHCI_EXYNOS int board_usb_vbus_init (void ) {
@@ -55,12 +63,30 @@ int board_usb_vbus_init(void) }#endif +struct cros_ec_dev *board_get_cros_ec_dev (void ) +{ +return local.cros_ec_dev; +} + +static int board_init_cros_ec_devices (const void *blob) +{ + local.cros_ec_err =cros_ec_init (blob, &local.cros_ec_dev); +if (local.cros_ec_err) +return -1 ;/* Will report in board_late_init() */ + +return 0 ; +} +int board_init (void ) { gd->bd->bi_boot_params = (PHYS_SDRAM_1 +0x100UL );#ifdef CONFIG_EXYNOS_SPI spi_init ();#endif + +if (board_init_cros_ec_devices (gd->fdt_blob)) +return -1 ; +#ifdef CONFIG_USB_EHCI_EXYNOS board_usb_vbus_init ();#endif
@@ -337,3 +363,22 @@ int board_early_init_f(void) return err; }#endif + +#ifdef CONFIG_BOARD_LATE_INIT +int board_late_init (void ) +{ +stdio_print_current_devices (); + +if (local.cros_ec_err) { +/* Force console on */ + gd->flags &= ~GD_FLG_SILENT ; + +printf ("cros-ec communications failure %d\n" , + local.cros_ec_err); +puts ("\nPlease reset with Power+Refresh\n\n" ); +panic ("Cannot init cros-ec device" ); +return -1 ; + } +return 0 ; +} +#endif
include/configs/exynos5250-dt.h +9 -1
@@ -77,11 +77,19 @@#define CONFIG_BAUDRATE 115200#define EXYNOS5_DEFAULT_UART_OFFSET 0x010000 +/* Enable keyboard */ +#define CONFIG_CROS_EC /* CROS_EC protocol */ +#define CONFIG_CROS_EC_SPI /* Support CROS_EC over SPI */ +#define CONFIG_CROS_EC_I2C /* Support CROS_EC over I2C */ +#define CONFIG_CROS_EC_KEYB /* CROS_EC keyboard input */ +#define CONFIG_CMD_CROS_EC +#define CONFIG_KEYBOARD +/* Console configuration */ #define CONFIG_CONSOLE_MUX #define CONFIG_SYS_CONSOLE_IS_IN_ENV #define EXYNOS_DEVICE_SETTINGS \ - "stdin=serial\0" \ + "stdin=serial,cros-ec-keyb\0" \ "stdout=serial,lcd\0" \ "stderr=serial,lcd\0"
Signature · 1 line
1.8.1.3
PATCH v2 7/7 cros: enable cros-ec for smdk5250
Quoted 5 lines · Hung-ying Tyan
This patch initiates cros-ec in
board_init()to enable it for smdk5250.Signed-off-by Simon Glass <[email protected]>Signed-off-by Vincent Palatin <[email protected]>Signed-off-by Hung-ying Tyan <[email protected]>