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