Vadim Bendebury | 41364f0 | 2014-02-27 13:26:02 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2012 The Chromium OS Authors. All rights reserved. |
| 3 | * Use of this source code is governed by a BSD-style license that can be |
| 4 | * found in the LICENSE file. |
| 5 | * |
| 6 | * Alternatively, this software may be distributed under the terms of the |
| 7 | * GNU General Public License ("GPL") version 2 as published by the Free |
| 8 | * Software Foundation. |
| 9 | */ |
| 10 | |
| 11 | #include <common.h> |
| 12 | #include <cros_ec.h> |
Simon Glass | 84d6cbd | 2014-10-13 23:42:14 -0600 | [diff] [blame] | 13 | #include <dm.h> |
| 14 | #include <errno.h> |
| 15 | |
Vadim Bendebury | 41364f0 | 2014-02-27 13:26:02 -0700 | [diff] [blame] | 16 | DECLARE_GLOBAL_DATA_PTR; |
| 17 | |
Simon Glass | 84d6cbd | 2014-10-13 23:42:14 -0600 | [diff] [blame] | 18 | #ifndef CONFIG_DM_CROS_EC |
Vadim Bendebury | 41364f0 | 2014-02-27 13:26:02 -0700 | [diff] [blame] | 19 | struct local_info { |
| 20 | struct cros_ec_dev *cros_ec_dev; /* Pointer to cros_ec device */ |
| 21 | int cros_ec_err; /* Error for cros_ec, 0 if ok */ |
| 22 | }; |
| 23 | |
| 24 | static struct local_info local; |
Simon Glass | 84d6cbd | 2014-10-13 23:42:14 -0600 | [diff] [blame] | 25 | #endif |
Vadim Bendebury | 41364f0 | 2014-02-27 13:26:02 -0700 | [diff] [blame] | 26 | |
| 27 | struct cros_ec_dev *board_get_cros_ec_dev(void) |
| 28 | { |
Simon Glass | 84d6cbd | 2014-10-13 23:42:14 -0600 | [diff] [blame] | 29 | #ifdef CONFIG_DM_CROS_EC |
| 30 | struct udevice *dev; |
| 31 | int ret; |
| 32 | |
| 33 | ret = uclass_get_device(UCLASS_CROS_EC, 0, &dev); |
| 34 | if (ret) { |
| 35 | debug("%s: Error %d\n", __func__, ret); |
| 36 | return NULL; |
| 37 | } |
| 38 | return dev->uclass_priv; |
| 39 | #else |
Vadim Bendebury | 41364f0 | 2014-02-27 13:26:02 -0700 | [diff] [blame] | 40 | return local.cros_ec_dev; |
Simon Glass | 84d6cbd | 2014-10-13 23:42:14 -0600 | [diff] [blame] | 41 | #endif |
Vadim Bendebury | 41364f0 | 2014-02-27 13:26:02 -0700 | [diff] [blame] | 42 | } |
| 43 | |
| 44 | static int board_init_cros_ec_devices(const void *blob) |
| 45 | { |
Simon Glass | 84d6cbd | 2014-10-13 23:42:14 -0600 | [diff] [blame] | 46 | #ifndef CONFIG_DM_CROS_EC |
Vadim Bendebury | 41364f0 | 2014-02-27 13:26:02 -0700 | [diff] [blame] | 47 | local.cros_ec_err = cros_ec_init(blob, &local.cros_ec_dev); |
| 48 | if (local.cros_ec_err) |
| 49 | return -1; /* Will report in board_late_init() */ |
Simon Glass | 84d6cbd | 2014-10-13 23:42:14 -0600 | [diff] [blame] | 50 | #endif |
Vadim Bendebury | 41364f0 | 2014-02-27 13:26:02 -0700 | [diff] [blame] | 51 | |
| 52 | return 0; |
| 53 | } |
| 54 | |
| 55 | int cros_ec_board_init(void) |
| 56 | { |
| 57 | return board_init_cros_ec_devices(gd->fdt_blob); |
| 58 | } |
| 59 | |
| 60 | int cros_ec_get_error(void) |
| 61 | { |
Simon Glass | 84d6cbd | 2014-10-13 23:42:14 -0600 | [diff] [blame] | 62 | #ifdef CONFIG_DM_CROS_EC |
| 63 | struct udevice *dev; |
| 64 | int ret; |
| 65 | |
| 66 | ret = uclass_get_device(UCLASS_CROS_EC, 0, &dev); |
| 67 | if (ret && ret != -ENODEV) |
| 68 | return ret; |
| 69 | |
| 70 | return 0; |
| 71 | #else |
Vadim Bendebury | 41364f0 | 2014-02-27 13:26:02 -0700 | [diff] [blame] | 72 | return local.cros_ec_err; |
Simon Glass | 84d6cbd | 2014-10-13 23:42:14 -0600 | [diff] [blame] | 73 | #endif |
Vadim Bendebury | 41364f0 | 2014-02-27 13:26:02 -0700 | [diff] [blame] | 74 | } |