cros_ec: Convert to support live tree
Convert this driver to support the live device tree and remove the old fdtdec support. The keyboard is not yet converted. Signed-off-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
parent
e907bf2dfb
commit
2ec9d171bc
@ -26,6 +26,7 @@
|
||||
#include <asm/io.h>
|
||||
#include <asm-generic/gpio.h>
|
||||
#include <dm/device-internal.h>
|
||||
#include <dm/of_extra.h>
|
||||
#include <dm/uclass-internal.h>
|
||||
|
||||
#ifdef DEBUG_TRACE
|
||||
@ -996,15 +997,12 @@ int cros_ec_get_ldo(struct udevice *dev, uint8_t index, uint8_t *state)
|
||||
int cros_ec_register(struct udevice *dev)
|
||||
{
|
||||
struct cros_ec_dev *cdev = dev_get_uclass_priv(dev);
|
||||
const void *blob = gd->fdt_blob;
|
||||
int node = dev_of_offset(dev);
|
||||
char id[MSG_BYTES];
|
||||
|
||||
cdev->dev = dev;
|
||||
gpio_request_by_name(dev, "ec-interrupt", 0, &cdev->ec_int,
|
||||
GPIOD_IS_IN);
|
||||
cdev->optimise_flash_write = fdtdec_get_bool(blob, node,
|
||||
"optimise-flash-write");
|
||||
cdev->optimise_flash_write = dev_read_bool(dev, "optimise-flash-write");
|
||||
|
||||
if (cros_ec_check_version(cdev)) {
|
||||
debug("%s: Could not detect CROS-EC version\n", __func__);
|
||||
@ -1023,28 +1021,26 @@ int cros_ec_register(struct udevice *dev)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int cros_ec_decode_ec_flash(const void *blob, int node,
|
||||
struct fdt_cros_ec *config)
|
||||
int cros_ec_decode_ec_flash(struct udevice *dev, struct fdt_cros_ec *config)
|
||||
{
|
||||
int flash_node;
|
||||
ofnode flash_node, node;
|
||||
|
||||
flash_node = fdt_subnode_offset(blob, node, "flash");
|
||||
if (flash_node < 0) {
|
||||
flash_node = dev_read_subnode(dev, "flash");
|
||||
if (!ofnode_valid(flash_node)) {
|
||||
debug("Failed to find flash node\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (fdtdec_read_fmap_entry(blob, flash_node, "flash",
|
||||
&config->flash)) {
|
||||
debug("Failed to decode flash node in chrome-ec'\n");
|
||||
if (of_read_fmap_entry(flash_node, "flash", &config->flash)) {
|
||||
debug("Failed to decode flash node in chrome-ec\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
config->flash_erase_value = fdtdec_get_int(blob, flash_node,
|
||||
"erase-value", -1);
|
||||
for (node = fdt_first_subnode(blob, flash_node); node >= 0;
|
||||
node = fdt_next_subnode(blob, node)) {
|
||||
const char *name = fdt_get_name(blob, node, NULL);
|
||||
config->flash_erase_value = ofnode_read_s32_default(flash_node,
|
||||
"erase-value", -1);
|
||||
for (node = ofnode_first_subnode(flash_node); ofnode_valid(node);
|
||||
node = ofnode_next_subnode(node)) {
|
||||
const char *name = ofnode_get_name(node);
|
||||
enum ec_flash_region region;
|
||||
|
||||
if (0 == strcmp(name, "ro")) {
|
||||
@ -1058,8 +1054,7 @@ int cros_ec_decode_ec_flash(const void *blob, int node,
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (fdtdec_read_fmap_entry(blob, node, "reg",
|
||||
&config->region[region])) {
|
||||
if (of_read_fmap_entry(node, "reg", &config->region[region])) {
|
||||
debug("Failed to decode flash region in chrome-ec'\n");
|
||||
return -1;
|
||||
}
|
||||
|
@ -188,18 +188,16 @@ static int get_image_used(struct ec_state *ec, struct fmap_entry *entry)
|
||||
* RR=Row CC=Column KKKK=Key Code
|
||||
*
|
||||
* @param ec Current emulated EC state
|
||||
* @param blob Device tree blob containing keyscan information
|
||||
* @param node Keyboard node of device tree containing keyscan information
|
||||
* @return 0 if ok, -1 on error
|
||||
*/
|
||||
static int keyscan_read_fdt_matrix(struct ec_state *ec, const void *blob,
|
||||
int node)
|
||||
static int keyscan_read_fdt_matrix(struct ec_state *ec, ofnode node)
|
||||
{
|
||||
const u32 *cell;
|
||||
int upto;
|
||||
int len;
|
||||
|
||||
cell = fdt_getprop(blob, node, "linux,keymap", &len);
|
||||
cell = ofnode_read_prop(node, "linux,keymap", &len);
|
||||
ec->matrix_count = len / 4;
|
||||
ec->matrix = calloc(ec->matrix_count, sizeof(*ec->matrix));
|
||||
if (!ec->matrix) {
|
||||
@ -516,28 +514,29 @@ int cros_ec_probe(struct udevice *dev)
|
||||
{
|
||||
struct ec_state *ec = dev->priv;
|
||||
struct cros_ec_dev *cdev = dev->uclass_priv;
|
||||
const void *blob = gd->fdt_blob;
|
||||
struct udevice *keyb_dev;
|
||||
int node;
|
||||
ofnode node;
|
||||
int err;
|
||||
|
||||
memcpy(ec, &s_state, sizeof(*ec));
|
||||
err = cros_ec_decode_ec_flash(blob, dev_of_offset(dev), &ec->ec_config);
|
||||
if (err)
|
||||
err = cros_ec_decode_ec_flash(dev, &ec->ec_config);
|
||||
if (err) {
|
||||
debug("%s: Cannot device EC flash\n", __func__);
|
||||
return err;
|
||||
}
|
||||
|
||||
node = -1;
|
||||
node = ofnode_null();
|
||||
for (device_find_first_child(dev, &keyb_dev);
|
||||
keyb_dev;
|
||||
device_find_next_child(&keyb_dev)) {
|
||||
if (device_get_uclass_id(keyb_dev) == UCLASS_KEYBOARD) {
|
||||
node = dev_of_offset(keyb_dev);
|
||||
node = dev_ofnode(keyb_dev);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (node < 0) {
|
||||
if (!ofnode_valid(node)) {
|
||||
debug("%s: No cros_ec keyboard found\n", __func__);
|
||||
} else if (keyscan_read_fdt_matrix(ec, blob, node)) {
|
||||
} else if (keyscan_read_fdt_matrix(ec, node)) {
|
||||
debug("%s: Could not read key matrix\n", __func__);
|
||||
return -1;
|
||||
}
|
||||
|
@ -11,7 +11,6 @@
|
||||
|
||||
#include <linux/compiler.h>
|
||||
#include <ec_commands.h>
|
||||
#include <fdtdec.h>
|
||||
#include <cros_ec_message.h>
|
||||
#include <asm/gpio.h>
|
||||
#include <dm/of_extra.h>
|
||||
@ -378,12 +377,10 @@ int cros_ec_get_error(void);
|
||||
/**
|
||||
* Returns information from the FDT about the Chrome EC flash
|
||||
*
|
||||
* @param blob FDT blob to use
|
||||
* @param node Node offset to read from
|
||||
* @param dev Device to read from
|
||||
* @param config Structure to use to return information
|
||||
*/
|
||||
int cros_ec_decode_ec_flash(const void *blob, int node,
|
||||
struct fdt_cros_ec *config);
|
||||
int cros_ec_decode_ec_flash(struct udevice *dev, struct fdt_cros_ec *config);
|
||||
|
||||
/**
|
||||
* Check the current keyboard state, in case recovery mode is requested.
|
||||
|
@ -815,19 +815,6 @@ const u8 *fdtdec_locate_byte_array(const void *blob, int node,
|
||||
int fdtdec_decode_region(const void *blob, int node, const char *prop_name,
|
||||
fdt_addr_t *basep, fdt_size_t *sizep);
|
||||
|
||||
struct fmap_entry;
|
||||
/**
|
||||
* Read a flash entry from the fdt
|
||||
*
|
||||
* @param blob FDT blob
|
||||
* @param node Offset of node to read
|
||||
* @param name Name of node being read
|
||||
* @param entry Place to put offset and size of this node
|
||||
* @return 0 if ok, -ve on error
|
||||
*/
|
||||
int fdtdec_read_fmap_entry(const void *blob, int node, const char *name,
|
||||
struct fmap_entry *entry);
|
||||
|
||||
/**
|
||||
* Obtain an indexed resource from a device property.
|
||||
*
|
||||
|
32
lib/fdtdec.c
32
lib/fdtdec.c
@ -941,38 +941,6 @@ int fdtdec_decode_region(const void *blob, int node, const char *prop_name,
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read a flash entry from the fdt
|
||||
*
|
||||
* @param blob FDT blob
|
||||
* @param node Offset of node to read
|
||||
* @param name Name of node being read
|
||||
* @param entry Place to put offset and size of this node
|
||||
* @return 0 if ok, -ve on error
|
||||
*/
|
||||
int fdtdec_read_fmap_entry(const void *blob, int node, const char *name,
|
||||
struct fmap_entry *entry)
|
||||
{
|
||||
const char *prop;
|
||||
u32 reg[2];
|
||||
|
||||
if (fdtdec_get_int_array(blob, node, "reg", reg, 2)) {
|
||||
debug("Node '%s' has bad/missing 'reg' property\n", name);
|
||||
return -FDT_ERR_NOTFOUND;
|
||||
}
|
||||
entry->offset = reg[0];
|
||||
entry->length = reg[1];
|
||||
entry->used = fdtdec_get_int(blob, node, "used", entry->length);
|
||||
prop = fdt_getprop(blob, node, "compress", NULL);
|
||||
entry->compress_algo = prop && !strcmp(prop, "lzo") ?
|
||||
FMAP_COMPRESS_LZO : FMAP_COMPRESS_NONE;
|
||||
prop = fdt_getprop(blob, node, "hash", &entry->hash_size);
|
||||
entry->hash_algo = prop ? FMAP_HASH_SHA256 : FMAP_HASH_NONE;
|
||||
entry->hash = (uint8_t *)prop;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
u64 fdtdec_get_number(const fdt32_t *ptr, unsigned int cells)
|
||||
{
|
||||
u64 number = 0;
|
||||
|
Loading…
Reference in New Issue
Block a user