Simon Glass | 53a68b3 | 2019-02-16 20:24:50 -0700 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * Copyright 2018 Google LLC |
| 4 | */ |
| 5 | |
| 6 | #include <common.h> |
| 7 | #include <dm.h> |
| 8 | #include <pch.h> |
| 9 | |
| 10 | struct sandbox_pch_priv { |
| 11 | bool protect; |
| 12 | }; |
| 13 | |
| 14 | int sandbox_get_pch_spi_protect(struct udevice *dev) |
| 15 | { |
| 16 | struct sandbox_pch_priv *priv = dev_get_priv(dev); |
| 17 | |
| 18 | return priv->protect; |
| 19 | } |
| 20 | |
| 21 | static int sandbox_pch_get_spi_base(struct udevice *dev, ulong *sbasep) |
| 22 | { |
| 23 | *sbasep = 0x10; |
| 24 | |
| 25 | return 0; |
| 26 | } |
| 27 | |
| 28 | static int sandbox_pch_set_spi_protect(struct udevice *dev, bool protect) |
| 29 | { |
| 30 | struct sandbox_pch_priv *priv = dev_get_priv(dev); |
| 31 | |
| 32 | priv->protect = protect; |
| 33 | |
| 34 | return 0; |
| 35 | } |
| 36 | |
| 37 | static int sandbox_pch_get_gpio_base(struct udevice *dev, u32 *gbasep) |
| 38 | { |
| 39 | *gbasep = 0x20; |
| 40 | |
| 41 | return 0; |
| 42 | } |
| 43 | |
| 44 | static int sandbox_pch_get_io_base(struct udevice *dev, u32 *iobasep) |
| 45 | { |
| 46 | *iobasep = 0x30; |
| 47 | |
| 48 | return 0; |
| 49 | } |
| 50 | |
Simon Glass | dbadbb7 | 2019-02-16 20:24:51 -0700 | [diff] [blame] | 51 | int sandbox_pch_ioctl(struct udevice *dev, enum pch_req_t req, void *data, |
| 52 | int size) |
| 53 | { |
| 54 | switch (req) { |
| 55 | case PCH_REQ_TEST1: |
| 56 | return -ENOSYS; |
| 57 | case PCH_REQ_TEST2: |
| 58 | return *(char *)data; |
| 59 | case PCH_REQ_TEST3: |
| 60 | *(char *)data = 'x'; |
| 61 | return 1; |
| 62 | default: |
| 63 | return -ENOSYS; |
| 64 | } |
| 65 | } |
| 66 | |
Simon Glass | 53a68b3 | 2019-02-16 20:24:50 -0700 | [diff] [blame] | 67 | static const struct pch_ops sandbox_pch_ops = { |
| 68 | .get_spi_base = sandbox_pch_get_spi_base, |
| 69 | .set_spi_protect = sandbox_pch_set_spi_protect, |
| 70 | .get_gpio_base = sandbox_pch_get_gpio_base, |
| 71 | .get_io_base = sandbox_pch_get_io_base, |
Simon Glass | dbadbb7 | 2019-02-16 20:24:51 -0700 | [diff] [blame] | 72 | .ioctl = sandbox_pch_ioctl, |
Simon Glass | 53a68b3 | 2019-02-16 20:24:50 -0700 | [diff] [blame] | 73 | }; |
| 74 | |
| 75 | static const struct udevice_id sandbox_pch_ids[] = { |
| 76 | { .compatible = "sandbox,pch" }, |
| 77 | { } |
| 78 | }; |
| 79 | |
| 80 | U_BOOT_DRIVER(sandbox_pch_drv) = { |
| 81 | .name = "sandbox-pch", |
| 82 | .id = UCLASS_PCH, |
| 83 | .of_match = sandbox_pch_ids, |
| 84 | .ops = &sandbox_pch_ops, |
Simon Glass | 8a2b47f | 2020-12-03 16:55:17 -0700 | [diff] [blame] | 85 | .priv_auto = sizeof(struct sandbox_pch_priv), |
Simon Glass | 53a68b3 | 2019-02-16 20:24:50 -0700 | [diff] [blame] | 86 | }; |