Commit 11636258981a083957c19f3979796fde5e7e8080

Authored by Stephen Warren
Committed by Simon Glass
1 parent 6f82fac2f2

Rename reset to sysreset

The current reset API implements a method to reset the entire system.
In the near future, I'd like to introduce code that implements the device
tree reset bindings; i.e. the equivalent of the Linux kernel's reset API.
This controls resets to individual HW blocks or external chips with reset
signals. It doesn't make sense to merge the two APIs into one since they
have different semantic purposes. Resolve the naming conflict by renaming
the existing reset API to sysreset instead, so the new reset API can be
called just reset.

Signed-off-by: Stephen Warren <swarren@nvidia.com>
Acked-by: Simon Glass <sjg@chromium.org>

Showing 28 changed files with 381 additions and 380 deletions Side-by-side Diff

arch/arm/lib/Makefile
... ... @@ -46,7 +46,7 @@
46 46 else
47 47 obj-y += interrupts.o
48 48 endif
49   -ifndef CONFIG_RESET
  49 +ifndef CONFIG_SYSRESET
50 50 obj-y += reset.o
51 51 endif
52 52  
arch/arm/mach-rockchip/rk3036/reset_rk3036.c
... ... @@ -7,24 +7,24 @@
7 7 #include <common.h>
8 8 #include <dm.h>
9 9 #include <errno.h>
10   -#include <reset.h>
  10 +#include <sysreset.h>
11 11 #include <asm/io.h>
12 12 #include <asm/arch/clock.h>
13 13 #include <asm/arch/cru_rk3036.h>
14 14 #include <asm/arch/hardware.h>
15 15 #include <linux/err.h>
16 16  
17   -int rk3036_reset_request(struct udevice *dev, enum reset_t type)
  17 +int rk3036_sysreset_request(struct udevice *dev, enum sysreset_t type)
18 18 {
19 19 struct rk3036_cru *cru = rockchip_get_cru();
20 20  
21 21 if (IS_ERR(cru))
22 22 return PTR_ERR(cru);
23 23 switch (type) {
24   - case RESET_WARM:
  24 + case SYSRESET_WARM:
25 25 writel(0xeca8, &cru->cru_glb_srst_snd_value);
26 26 break;
27   - case RESET_COLD:
  27 + case SYSRESET_COLD:
28 28 writel(0xfdb9, &cru->cru_glb_srst_fst_value);
29 29 break;
30 30 default:
31 31  
... ... @@ -34,13 +34,13 @@
34 34 return -EINPROGRESS;
35 35 }
36 36  
37   -static struct reset_ops rk3036_reset = {
38   - .request = rk3036_reset_request,
  37 +static struct sysreset_ops rk3036_sysreset = {
  38 + .request = rk3036_sysreset_request,
39 39 };
40 40  
41   -U_BOOT_DRIVER(reset_rk3036) = {
42   - .name = "rk3036_reset",
43   - .id = UCLASS_RESET,
44   - .ops = &rk3036_reset,
  41 +U_BOOT_DRIVER(sysreset_rk3036) = {
  42 + .name = "rk3036_sysreset",
  43 + .id = UCLASS_SYSRESET,
  44 + .ops = &rk3036_sysreset,
45 45 };
arch/arm/mach-rockchip/rk3288/reset_rk3288.c
... ... @@ -7,25 +7,25 @@
7 7 #include <common.h>
8 8 #include <dm.h>
9 9 #include <errno.h>
10   -#include <reset.h>
  10 +#include <sysreset.h>
11 11 #include <asm/io.h>
12 12 #include <asm/arch/clock.h>
13 13 #include <asm/arch/cru_rk3288.h>
14 14 #include <asm/arch/hardware.h>
15 15 #include <linux/err.h>
16 16  
17   -int rk3288_reset_request(struct udevice *dev, enum reset_t type)
  17 +int rk3288_sysreset_request(struct udevice *dev, enum sysreset_t type)
18 18 {
19 19 struct rk3288_cru *cru = rockchip_get_cru();
20 20  
21 21 if (IS_ERR(cru))
22 22 return PTR_ERR(cru);
23 23 switch (type) {
24   - case RESET_WARM:
  24 + case SYSRESET_WARM:
25 25 rk_clrreg(&cru->cru_mode_con, 0xffff);
26 26 writel(0xeca8, &cru->cru_glb_srst_snd_value);
27 27 break;
28   - case RESET_COLD:
  28 + case SYSRESET_COLD:
29 29 rk_clrreg(&cru->cru_mode_con, 0xffff);
30 30 writel(0xfdb9, &cru->cru_glb_srst_fst_value);
31 31 break;
32 32  
... ... @@ -36,13 +36,13 @@
36 36 return -EINPROGRESS;
37 37 }
38 38  
39   -static struct reset_ops rk3288_reset = {
40   - .request = rk3288_reset_request,
  39 +static struct sysreset_ops rk3288_sysreset = {
  40 + .request = rk3288_sysreset_request,
41 41 };
42 42  
43   -U_BOOT_DRIVER(reset_rk3288) = {
44   - .name = "rk3288_reset",
45   - .id = UCLASS_RESET,
46   - .ops = &rk3288_reset,
  43 +U_BOOT_DRIVER(sysreset_rk3288) = {
  44 + .name = "rk3288_sysreset",
  45 + .id = UCLASS_SYSRESET,
  46 + .ops = &rk3288_sysreset,
47 47 };
arch/arm/mach-snapdragon/reset.c
... ... @@ -9,12 +9,12 @@
9 9 #include <common.h>
10 10 #include <dm.h>
11 11 #include <errno.h>
12   -#include <reset.h>
  12 +#include <sysreset.h>
13 13 #include <asm/io.h>
14 14  
15 15 DECLARE_GLOBAL_DATA_PTR;
16 16  
17   -static int msm_reset_request(struct udevice *dev, enum reset_t type)
  17 +static int msm_sysreset_request(struct udevice *dev, enum sysreset_t type)
18 18 {
19 19 phys_addr_t addr = dev_get_addr(dev);
20 20 if (!addr)
21 21  
22 22  
... ... @@ -23,19 +23,19 @@
23 23 return -EINPROGRESS;
24 24 }
25 25  
26   -static struct reset_ops msm_reset_ops = {
27   - .request = msm_reset_request,
  26 +static struct sysreset_ops msm_sysreset_ops = {
  27 + .request = msm_sysreset_request,
28 28 };
29 29  
30   -static const struct udevice_id msm_reset_ids[] = {
  30 +static const struct udevice_id msm_sysreset_ids[] = {
31 31 { .compatible = "qcom,pshold" },
32 32 { }
33 33 };
34 34  
35 35 U_BOOT_DRIVER(msm_reset) = {
36   - .name = "msm_reset",
37   - .id = UCLASS_RESET,
38   - .of_match = msm_reset_ids,
39   - .ops = &msm_reset_ops,
  36 + .name = "msm_sysreset",
  37 + .id = UCLASS_SYSRESET,
  38 + .of_match = msm_sysreset_ids,
  39 + .ops = &msm_sysreset_ops,
40 40 };
arch/sandbox/cpu/state.c
... ... @@ -360,8 +360,8 @@
360 360 assert(state->ram_buf);
361 361  
362 362 /* No reset yet, so mark it as such. Always allow power reset */
363   - state->last_reset = RESET_COUNT;
364   - state->reset_allowed[RESET_POWER] = true;
  363 + state->last_sysreset = SYSRESET_COUNT;
  364 + state->sysreset_allowed[SYSRESET_POWER] = true;
365 365  
366 366 /*
367 367 * Example of how to use GPIOs:
arch/sandbox/include/asm/state.h
... ... @@ -7,7 +7,7 @@
7 7 #define __SANDBOX_STATE_H
8 8  
9 9 #include <config.h>
10   -#include <reset.h>
  10 +#include <sysreset.h>
11 11 #include <stdbool.h>
12 12 #include <linux/stringify.h>
13 13  
... ... @@ -60,8 +60,8 @@
60 60 bool write_state; /* Write sandbox state on exit */
61 61 bool ignore_missing_state_on_read; /* No error if state missing */
62 62 bool show_lcd; /* Show LCD on start-up */
63   - enum reset_t last_reset; /* Last reset type */
64   - bool reset_allowed[RESET_COUNT]; /* Allowed reset types */
  63 + enum sysreset_t last_sysreset; /* Last system reset type */
  64 + bool sysreset_allowed[SYSRESET_COUNT]; /* Allowed system reset types */
65 65 enum state_terminal_raw term_raw; /* Terminal raw/cooked */
66 66 bool skip_delays; /* Ignore any time delays (for test) */
67 67 bool show_test_output; /* Don't suppress stdout in tests */
configs/chromebook_jerry_defconfig
... ... @@ -47,7 +47,7 @@
47 47 CONFIG_CROS_EC=y
48 48 CONFIG_CROS_EC_SPI=y
49 49 CONFIG_PWRSEQ=y
50   -CONFIG_RESET=y
  50 +CONFIG_SYSRESET=y
51 51 CONFIG_DM_MMC=y
52 52 CONFIG_ROCKCHIP_DWMMC=y
53 53 CONFIG_PINCTRL=y
configs/dragonboard410c_defconfig
... ... @@ -23,7 +23,7 @@
23 23 CONFIG_PM8916_GPIO=y
24 24 CONFIG_LED=y
25 25 CONFIG_LED_GPIO=y
26   -CONFIG_RESET=y
  26 +CONFIG_SYSRESET=y
27 27 CONFIG_DM_MMC=y
28 28 CONFIG_MSM_SDHCI=y
29 29 CONFIG_DM_PMIC=y
configs/evb-rk3036_defconfig
... ... @@ -28,7 +28,7 @@
28 28 CONFIG_ROCKCHIP_GPIO=y
29 29 CONFIG_SYS_I2C_ROCKCHIP=y
30 30 CONFIG_LED=y
31   -CONFIG_RESET=y
  31 +CONFIG_SYSRESET=y
32 32 CONFIG_DM_MMC=y
33 33 CONFIG_ROCKCHIP_DWMMC=y
34 34 CONFIG_PINCTRL=y
configs/firefly-rk3288_defconfig
... ... @@ -40,7 +40,7 @@
40 40 CONFIG_SYS_I2C_ROCKCHIP=y
41 41 CONFIG_LED=y
42 42 CONFIG_LED_GPIO=y
43   -CONFIG_RESET=y
  43 +CONFIG_SYSRESET=y
44 44 CONFIG_DM_MMC=y
45 45 CONFIG_ROCKCHIP_DWMMC=y
46 46 CONFIG_PINCTRL=y
configs/kylin-rk3036_defconfig
... ... @@ -28,7 +28,7 @@
28 28 CONFIG_ROCKCHIP_GPIO=y
29 29 CONFIG_SYS_I2C_ROCKCHIP=y
30 30 CONFIG_LED=y
31   -CONFIG_RESET=y
  31 +CONFIG_SYSRESET=y
32 32 CONFIG_DM_MMC=y
33 33 CONFIG_ROCKCHIP_DWMMC=y
34 34 CONFIG_PINCTRL=y
configs/rock2_defconfig
... ... @@ -38,7 +38,7 @@
38 38 CONFIG_SPL_CLK=y
39 39 CONFIG_ROCKCHIP_GPIO=y
40 40 CONFIG_SYS_I2C_ROCKCHIP=y
41   -CONFIG_RESET=y
  41 +CONFIG_SYSRESET=y
42 42 CONFIG_DM_MMC=y
43 43 CONFIG_ROCKCHIP_DWMMC=y
44 44 CONFIG_PINCTRL=y
configs/sandbox_defconfig
... ... @@ -97,7 +97,7 @@
97 97 CONFIG_CROS_EC_SPI=y
98 98 CONFIG_PWRSEQ=y
99 99 CONFIG_SPL_PWRSEQ=y
100   -CONFIG_RESET=y
  100 +CONFIG_SYSRESET=y
101 101 CONFIG_DM_MMC=y
102 102 CONFIG_SANDBOX_MMC=y
103 103 CONFIG_SPI_FLASH_SANDBOX=y
configs/sandbox_noblk_defconfig
... ... @@ -94,7 +94,7 @@
94 94 CONFIG_CROS_EC_SPI=y
95 95 CONFIG_PWRSEQ=y
96 96 CONFIG_SPL_PWRSEQ=y
97   -CONFIG_RESET=y
  97 +CONFIG_SYSRESET=y
98 98 CONFIG_DM_MMC=y
99 99 CONFIG_SPI_FLASH_SANDBOX=y
100 100 CONFIG_SPI_FLASH=y
drivers/clk/clk_rk3036.c
... ... @@ -407,7 +407,7 @@
407 407 }
408 408  
409 409 /* The reset driver does not have a device node, so bind it here */
410   - ret = device_bind_driver(gd->dm_root, "rk3036_reset", "reset", &dev);
  410 + ret = device_bind_driver(gd->dm_root, "rk3036_sysreset", "reset", &dev);
411 411 if (ret)
412 412 debug("Warning: No RK3036 reset driver: ret=%d\n", ret);
413 413  
drivers/clk/clk_rk3288.c
... ... @@ -877,7 +877,7 @@
877 877 }
878 878  
879 879 /* The reset driver does not have a device node, so bind it here */
880   - ret = device_bind_driver(gd->dm_root, "rk3288_reset", "reset", &dev);
  880 + ret = device_bind_driver(gd->dm_root, "rk3288_sysreset", "reset", &dev);
881 881 if (ret)
882 882 debug("Warning: No RK3288 reset driver: ret=%d\n", ret);
883 883  
drivers/misc/Kconfig
... ... @@ -121,13 +121,13 @@
121 121 help
122 122 The I2C address of the PCA9551 LED controller.
123 123  
124   -config RESET
125   - bool "Enable support for reset drivers"
  124 +config SYSRESET
  125 + bool "Enable support for system reset drivers"
126 126 depends on DM
127 127 help
128   - Enable reset drivers which can be used to reset the CPU or board.
129   - Each driver can provide a reset method which will be called to
130   - effect a reset. The uclass will try all available drivers when
  128 + Enable system reset drivers which can be used to reset the CPU or
  129 + board. Each driver can provide a reset method which will be called
  130 + to effect a reset. The uclass will try all available drivers when
131 131 reset_walk() is called.
132 132  
133 133 config WINBOND_W83627
drivers/misc/Makefile
... ... @@ -27,7 +27,7 @@
27 27 obj-$(CONFIG_NS87308) += ns87308.o
28 28 obj-$(CONFIG_PDSP188x) += pdsp188x.o
29 29 obj-$(CONFIG_$(SPL_)PWRSEQ) += pwrseq-uclass.o
30   -obj-$(CONFIG_SANDBOX) += reset_sandbox.o
  30 +obj-$(CONFIG_SANDBOX) += sysreset_sandbox.o
31 31 ifdef CONFIG_DM_I2C
32 32 obj-$(CONFIG_SANDBOX) += i2c_eeprom_emul.o
33 33 endif
... ... @@ -40,7 +40,7 @@
40 40 obj-$(CONFIG_FSL_IFC) += fsl_ifc.o
41 41 obj-$(CONFIG_FSL_SEC_MON) += fsl_sec_mon.o
42 42 obj-$(CONFIG_PCA9551_LED) += pca9551_led.o
43   -obj-$(CONFIG_RESET) += reset-uclass.o
  43 +obj-$(CONFIG_SYSRESET) += sysreset-uclass.o
44 44 obj-$(CONFIG_FSL_DEVICE_DISABLE) += fsl_devdis.o
45 45 obj-$(CONFIG_WINBOND_W83627) += winbond_w83627.o
46 46 obj-$(CONFIG_QFW) += qfw.o
drivers/misc/reset-uclass.c
1   -/*
2   - * Copyright (C) 2015 Google, Inc
3   - * Written by Simon Glass <sjg@chromium.org>
4   - *
5   - * SPDX-License-Identifier: GPL-2.0+
6   - */
7   -
8   -#include <common.h>
9   -#include <reset.h>
10   -#include <dm.h>
11   -#include <errno.h>
12   -#include <regmap.h>
13   -#include <dm/device-internal.h>
14   -#include <dm/lists.h>
15   -#include <dm/root.h>
16   -#include <linux/err.h>
17   -
18   -int reset_request(struct udevice *dev, enum reset_t type)
19   -{
20   - struct reset_ops *ops = reset_get_ops(dev);
21   -
22   - if (!ops->request)
23   - return -ENOSYS;
24   -
25   - return ops->request(dev, type);
26   -}
27   -
28   -int reset_walk(enum reset_t type)
29   -{
30   - struct udevice *dev;
31   - int ret = -ENOSYS;
32   -
33   - while (ret != -EINPROGRESS && type < RESET_COUNT) {
34   - for (uclass_first_device(UCLASS_RESET, &dev);
35   - dev;
36   - uclass_next_device(&dev)) {
37   - ret = reset_request(dev, type);
38   - if (ret == -EINPROGRESS)
39   - break;
40   - }
41   - type++;
42   - }
43   -
44   - return ret;
45   -}
46   -
47   -void reset_walk_halt(enum reset_t type)
48   -{
49   - int ret;
50   -
51   - ret = reset_walk(type);
52   -
53   - /* Wait for the reset to take effect */
54   - if (ret == -EINPROGRESS)
55   - mdelay(100);
56   -
57   - /* Still no reset? Give up */
58   - printf("Reset not supported on this platform\n");
59   - hang();
60   -}
61   -
62   -/**
63   - * reset_cpu() - calls reset_walk(RESET_WARM)
64   - */
65   -void reset_cpu(ulong addr)
66   -{
67   - reset_walk_halt(RESET_WARM);
68   -}
69   -
70   -
71   -int do_reset(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
72   -{
73   - reset_walk_halt(RESET_WARM);
74   -
75   - return 0;
76   -}
77   -
78   -UCLASS_DRIVER(reset) = {
79   - .id = UCLASS_RESET,
80   - .name = "reset",
81   -};
drivers/misc/reset_sandbox.c
1   -/*
2   - * Copyright (c) 2015 Google, Inc
3   - * Written by Simon Glass <sjg@chromium.org>
4   - *
5   - * SPDX-License-Identifier: GPL-2.0+
6   - */
7   -
8   -#include <common.h>
9   -#include <dm.h>
10   -#include <errno.h>
11   -#include <reset.h>
12   -#include <asm/state.h>
13   -#include <asm/test.h>
14   -
15   -DECLARE_GLOBAL_DATA_PTR;
16   -
17   -static int sandbox_warm_reset_request(struct udevice *dev, enum reset_t type)
18   -{
19   - struct sandbox_state *state = state_get_current();
20   -
21   - switch (type) {
22   - case RESET_WARM:
23   - state->last_reset = type;
24   - break;
25   - default:
26   - return -ENOSYS;
27   - }
28   - if (!state->reset_allowed[type])
29   - return -EACCES;
30   -
31   - return -EINPROGRESS;
32   -}
33   -
34   -static int sandbox_reset_request(struct udevice *dev, enum reset_t type)
35   -{
36   - struct sandbox_state *state = state_get_current();
37   -
38   - /*
39   - * If we have a device tree, the device we created from platform data
40   - * (see the U_BOOT_DEVICE() declaration below) should not do anything.
41   - * If we are that device, return an error.
42   - */
43   - if (state->fdt_fname && dev->of_offset == -1)
44   - return -ENODEV;
45   -
46   - switch (type) {
47   - case RESET_COLD:
48   - state->last_reset = type;
49   - break;
50   - case RESET_POWER:
51   - state->last_reset = type;
52   - if (!state->reset_allowed[type])
53   - return -EACCES;
54   - sandbox_exit();
55   - break;
56   - default:
57   - return -ENOSYS;
58   - }
59   - if (!state->reset_allowed[type])
60   - return -EACCES;
61   -
62   - return -EINPROGRESS;
63   -}
64   -
65   -static struct reset_ops sandbox_reset_ops = {
66   - .request = sandbox_reset_request,
67   -};
68   -
69   -static const struct udevice_id sandbox_reset_ids[] = {
70   - { .compatible = "sandbox,reset" },
71   - { }
72   -};
73   -
74   -U_BOOT_DRIVER(reset_sandbox) = {
75   - .name = "reset_sandbox",
76   - .id = UCLASS_RESET,
77   - .of_match = sandbox_reset_ids,
78   - .ops = &sandbox_reset_ops,
79   -};
80   -
81   -static struct reset_ops sandbox_warm_reset_ops = {
82   - .request = sandbox_warm_reset_request,
83   -};
84   -
85   -static const struct udevice_id sandbox_warm_reset_ids[] = {
86   - { .compatible = "sandbox,warm-reset" },
87   - { }
88   -};
89   -
90   -U_BOOT_DRIVER(warm_reset_sandbox) = {
91   - .name = "warm_reset_sandbox",
92   - .id = UCLASS_RESET,
93   - .of_match = sandbox_warm_reset_ids,
94   - .ops = &sandbox_warm_reset_ops,
95   -};
96   -
97   -/* This is here in case we don't have a device tree */
98   -U_BOOT_DEVICE(reset_sandbox_non_fdt) = {
99   - .name = "reset_sandbox",
100   -};
drivers/misc/sysreset-uclass.c
  1 +/*
  2 + * Copyright (C) 2015 Google, Inc
  3 + * Written by Simon Glass <sjg@chromium.org>
  4 + *
  5 + * SPDX-License-Identifier: GPL-2.0+
  6 + */
  7 +
  8 +#include <common.h>
  9 +#include <sysreset.h>
  10 +#include <dm.h>
  11 +#include <errno.h>
  12 +#include <regmap.h>
  13 +#include <dm/device-internal.h>
  14 +#include <dm/lists.h>
  15 +#include <dm/root.h>
  16 +#include <linux/err.h>
  17 +
  18 +int sysreset_request(struct udevice *dev, enum sysreset_t type)
  19 +{
  20 + struct sysreset_ops *ops = sysreset_get_ops(dev);
  21 +
  22 + if (!ops->request)
  23 + return -ENOSYS;
  24 +
  25 + return ops->request(dev, type);
  26 +}
  27 +
  28 +int sysreset_walk(enum sysreset_t type)
  29 +{
  30 + struct udevice *dev;
  31 + int ret = -ENOSYS;
  32 +
  33 + while (ret != -EINPROGRESS && type < SYSRESET_COUNT) {
  34 + for (uclass_first_device(UCLASS_SYSRESET, &dev);
  35 + dev;
  36 + uclass_next_device(&dev)) {
  37 + ret = sysreset_request(dev, type);
  38 + if (ret == -EINPROGRESS)
  39 + break;
  40 + }
  41 + type++;
  42 + }
  43 +
  44 + return ret;
  45 +}
  46 +
  47 +void sysreset_walk_halt(enum sysreset_t type)
  48 +{
  49 + int ret;
  50 +
  51 + ret = sysreset_walk(type);
  52 +
  53 + /* Wait for the reset to take effect */
  54 + if (ret == -EINPROGRESS)
  55 + mdelay(100);
  56 +
  57 + /* Still no reset? Give up */
  58 + printf("System reset not supported on this platform\n");
  59 + hang();
  60 +}
  61 +
  62 +/**
  63 + * reset_cpu() - calls sysreset_walk(SYSRESET_WARM)
  64 + */
  65 +void reset_cpu(ulong addr)
  66 +{
  67 + sysreset_walk_halt(SYSRESET_WARM);
  68 +}
  69 +
  70 +
  71 +int do_reset(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  72 +{
  73 + sysreset_walk_halt(SYSRESET_WARM);
  74 +
  75 + return 0;
  76 +}
  77 +
  78 +UCLASS_DRIVER(sysreset) = {
  79 + .id = UCLASS_SYSRESET,
  80 + .name = "sysreset",
  81 +};
drivers/misc/sysreset_sandbox.c
  1 +/*
  2 + * Copyright (c) 2015 Google, Inc
  3 + * Written by Simon Glass <sjg@chromium.org>
  4 + *
  5 + * SPDX-License-Identifier: GPL-2.0+
  6 + */
  7 +
  8 +#include <common.h>
  9 +#include <dm.h>
  10 +#include <errno.h>
  11 +#include <sysreset.h>
  12 +#include <asm/state.h>
  13 +#include <asm/test.h>
  14 +
  15 +DECLARE_GLOBAL_DATA_PTR;
  16 +
  17 +static int sandbox_warm_sysreset_request(struct udevice *dev,
  18 + enum sysreset_t type)
  19 +{
  20 + struct sandbox_state *state = state_get_current();
  21 +
  22 + switch (type) {
  23 + case SYSRESET_WARM:
  24 + state->last_sysreset = type;
  25 + break;
  26 + default:
  27 + return -ENOSYS;
  28 + }
  29 + if (!state->sysreset_allowed[type])
  30 + return -EACCES;
  31 +
  32 + return -EINPROGRESS;
  33 +}
  34 +
  35 +static int sandbox_sysreset_request(struct udevice *dev, enum sysreset_t type)
  36 +{
  37 + struct sandbox_state *state = state_get_current();
  38 +
  39 + /*
  40 + * If we have a device tree, the device we created from platform data
  41 + * (see the U_BOOT_DEVICE() declaration below) should not do anything.
  42 + * If we are that device, return an error.
  43 + */
  44 + if (state->fdt_fname && dev->of_offset == -1)
  45 + return -ENODEV;
  46 +
  47 + switch (type) {
  48 + case SYSRESET_COLD:
  49 + state->last_sysreset = type;
  50 + break;
  51 + case SYSRESET_POWER:
  52 + state->last_sysreset = type;
  53 + if (!state->sysreset_allowed[type])
  54 + return -EACCES;
  55 + sandbox_exit();
  56 + break;
  57 + default:
  58 + return -ENOSYS;
  59 + }
  60 + if (!state->sysreset_allowed[type])
  61 + return -EACCES;
  62 +
  63 + return -EINPROGRESS;
  64 +}
  65 +
  66 +static struct sysreset_ops sandbox_sysreset_ops = {
  67 + .request = sandbox_sysreset_request,
  68 +};
  69 +
  70 +static const struct udevice_id sandbox_sysreset_ids[] = {
  71 + { .compatible = "sandbox,reset" },
  72 + { }
  73 +};
  74 +
  75 +U_BOOT_DRIVER(sysreset_sandbox) = {
  76 + .name = "sysreset_sandbox",
  77 + .id = UCLASS_SYSRESET,
  78 + .of_match = sandbox_sysreset_ids,
  79 + .ops = &sandbox_sysreset_ops,
  80 +};
  81 +
  82 +static struct sysreset_ops sandbox_warm_sysreset_ops = {
  83 + .request = sandbox_warm_sysreset_request,
  84 +};
  85 +
  86 +static const struct udevice_id sandbox_warm_sysreset_ids[] = {
  87 + { .compatible = "sandbox,warm-reset" },
  88 + { }
  89 +};
  90 +
  91 +U_BOOT_DRIVER(warm_sysreset_sandbox) = {
  92 + .name = "warm_sysreset_sandbox",
  93 + .id = UCLASS_SYSRESET,
  94 + .of_match = sandbox_warm_sysreset_ids,
  95 + .ops = &sandbox_warm_sysreset_ops,
  96 +};
  97 +
  98 +/* This is here in case we don't have a device tree */
  99 +U_BOOT_DEVICE(sysreset_sandbox_non_fdt) = {
  100 + .name = "sysreset_sandbox",
  101 +};
include/dm/uclass-id.h
... ... @@ -61,7 +61,6 @@
61 61 UCLASS_PWM, /* Pulse-width modulator */
62 62 UCLASS_PWRSEQ, /* Power sequence device */
63 63 UCLASS_REGULATOR, /* Regulator device */
64   - UCLASS_RESET, /* Reset device */
65 64 UCLASS_REMOTEPROC, /* Remote Processor device */
66 65 UCLASS_RTC, /* Real time clock device */
67 66 UCLASS_SERIAL, /* Serial UART */
... ... @@ -70,6 +69,7 @@
70 69 UCLASS_SPI_FLASH, /* SPI flash */
71 70 UCLASS_SPI_GENERIC, /* Generic SPI flash target */
72 71 UCLASS_SYSCON, /* System configuration device */
  72 + UCLASS_SYSRESET, /* System reset device */
73 73 UCLASS_THERMAL, /* Thermal sensor */
74 74 UCLASS_TIMER, /* Timer device */
75 75 UCLASS_TPM, /* Trusted Platform Module TIS interface */
include/reset.h
1   -/*
2   - * Copyright (c) 2015 Google, Inc
3   - * Written by Simon Glass <sjg@chromium.org>
4   - *
5   - * SPDX-License-Identifier: GPL-2.0+
6   - */
7   -
8   -#ifndef __RESET_H
9   -#define __RESET_H
10   -
11   -enum reset_t {
12   - RESET_WARM, /* Reset CPU, keep GPIOs active */
13   - RESET_COLD, /* Reset CPU and GPIOs */
14   - RESET_POWER, /* Reset PMIC (remove and restore power) */
15   -
16   - RESET_COUNT,
17   -};
18   -
19   -struct reset_ops {
20   - /**
21   - * request() - request a reset of the given type
22   - *
23   - * Note that this function may return before the reset takes effect.
24   - *
25   - * @type: Reset type to request
26   - * @return -EINPROGRESS if the reset has been started and
27   - * will complete soon, -EPROTONOSUPPORT if not supported
28   - * by this device, 0 if the reset has already happened
29   - * (in which case this method will not actually return)
30   - */
31   - int (*request)(struct udevice *dev, enum reset_t type);
32   -};
33   -
34   -#define reset_get_ops(dev) ((struct reset_ops *)(dev)->driver->ops)
35   -
36   -/**
37   - * reset_request() - request a reset
38   - *
39   - * @type: Reset type to request
40   - * @return 0 if OK, -EPROTONOSUPPORT if not supported by this device
41   - */
42   -int reset_request(struct udevice *dev, enum reset_t type);
43   -
44   -/**
45   - * reset_walk() - cause a reset
46   - *
47   - * This works through the available reset devices until it finds one that can
48   - * perform a reset. If the provided reset type is not available, the next one
49   - * will be tried.
50   - *
51   - * If this function fails to reset, it will display a message and halt
52   - *
53   - * @type: Reset type to request
54   - * @return -EINPROGRESS if a reset is in progress, -ENOSYS if not available
55   - */
56   -int reset_walk(enum reset_t type);
57   -
58   -/**
59   - * reset_walk_halt() - try to reset, otherwise halt
60   - *
61   - * This calls reset_walk(). If it returns, indicating that reset is not
62   - * supported, it prints a message and halts.
63   - */
64   -void reset_walk_halt(enum reset_t type);
65   -
66   -/**
67   - * reset_cpu() - calls reset_walk(RESET_WARM)
68   - */
69   -void reset_cpu(ulong addr);
70   -
71   -#endif
  1 +/*
  2 + * Copyright (c) 2015 Google, Inc
  3 + * Written by Simon Glass <sjg@chromium.org>
  4 + *
  5 + * SPDX-License-Identifier: GPL-2.0+
  6 + */
  7 +
  8 +#ifndef __SYSRESET_H
  9 +#define __SYSRESET_H
  10 +
  11 +enum sysreset_t {
  12 + SYSRESET_WARM, /* Reset CPU, keep GPIOs active */
  13 + SYSRESET_COLD, /* Reset CPU and GPIOs */
  14 + SYSRESET_POWER, /* Reset PMIC (remove and restore power) */
  15 +
  16 + SYSRESET_COUNT,
  17 +};
  18 +
  19 +struct sysreset_ops {
  20 + /**
  21 + * request() - request a sysreset of the given type
  22 + *
  23 + * Note that this function may return before the reset takes effect.
  24 + *
  25 + * @type: Reset type to request
  26 + * @return -EINPROGRESS if the reset has been started and
  27 + * will complete soon, -EPROTONOSUPPORT if not supported
  28 + * by this device, 0 if the reset has already happened
  29 + * (in which case this method will not actually return)
  30 + */
  31 + int (*request)(struct udevice *dev, enum sysreset_t type);
  32 +};
  33 +
  34 +#define sysreset_get_ops(dev) ((struct sysreset_ops *)(dev)->driver->ops)
  35 +
  36 +/**
  37 + * sysreset_request() - request a sysreset
  38 + *
  39 + * @type: Reset type to request
  40 + * @return 0 if OK, -EPROTONOSUPPORT if not supported by this device
  41 + */
  42 +int sysreset_request(struct udevice *dev, enum sysreset_t type);
  43 +
  44 +/**
  45 + * sysreset_walk() - cause a system reset
  46 + *
  47 + * This works through the available sysreset devices until it finds one that can
  48 + * perform a reset. If the provided sysreset type is not available, the next one
  49 + * will be tried.
  50 + *
  51 + * If this function fails to reset, it will display a message and halt
  52 + *
  53 + * @type: Reset type to request
  54 + * @return -EINPROGRESS if a reset is in progress, -ENOSYS if not available
  55 + */
  56 +int sysreset_walk(enum sysreset_t type);
  57 +
  58 +/**
  59 + * sysreset_walk_halt() - try to reset, otherwise halt
  60 + *
  61 + * This calls sysreset_walk(). If it returns, indicating that reset is not
  62 + * supported, it prints a message and halts.
  63 + */
  64 +void sysreset_walk_halt(enum sysreset_t type);
  65 +
  66 +/**
  67 + * reset_cpu() - calls sysreset_walk(SYSRESET_WARM)
  68 + */
  69 +void reset_cpu(ulong addr);
  70 +
  71 +#endif
... ... @@ -26,7 +26,7 @@
26 26 obj-$(CONFIG_RAM) += ram.o
27 27 obj-y += regmap.o
28 28 obj-$(CONFIG_REMOTEPROC) += remoteproc.o
29   -obj-$(CONFIG_RESET) += reset.o
  29 +obj-$(CONFIG_SYSRESET) += sysreset.o
30 30 obj-$(CONFIG_DM_RTC) += rtc.o
31 31 obj-$(CONFIG_DM_SPI_FLASH) += sf.o
32 32 obj-$(CONFIG_DM_SPI) += spi.o
test/dm/reset.c
1   -/*
2   - * Copyright (C) 2015 Google, Inc
3   - *
4   - * SPDX-License-Identifier: GPL-2.0+
5   - */
6   -
7   -#include <common.h>
8   -#include <dm.h>
9   -#include <reset.h>
10   -#include <asm/state.h>
11   -#include <asm/test.h>
12   -#include <dm/test.h>
13   -#include <test/ut.h>
14   -
15   -/* Test that we can use particular reset devices */
16   -static int dm_test_reset_base(struct unit_test_state *uts)
17   -{
18   - struct sandbox_state *state = state_get_current();
19   - struct udevice *dev;
20   -
21   - /* Device 0 is the platform data device - it should never respond */
22   - ut_assertok(uclass_get_device(UCLASS_RESET, 0, &dev));
23   - ut_asserteq(-ENODEV, reset_request(dev, RESET_WARM));
24   - ut_asserteq(-ENODEV, reset_request(dev, RESET_COLD));
25   - ut_asserteq(-ENODEV, reset_request(dev, RESET_POWER));
26   -
27   - /* Device 1 is the warm reset device */
28   - ut_assertok(uclass_get_device(UCLASS_RESET, 1, &dev));
29   - ut_asserteq(-EACCES, reset_request(dev, RESET_WARM));
30   - ut_asserteq(-ENOSYS, reset_request(dev, RESET_COLD));
31   - ut_asserteq(-ENOSYS, reset_request(dev, RESET_POWER));
32   -
33   - state->reset_allowed[RESET_WARM] = true;
34   - ut_asserteq(-EINPROGRESS, reset_request(dev, RESET_WARM));
35   - state->reset_allowed[RESET_WARM] = false;
36   -
37   - /* Device 2 is the cold reset device */
38   - ut_assertok(uclass_get_device(UCLASS_RESET, 2, &dev));
39   - ut_asserteq(-ENOSYS, reset_request(dev, RESET_WARM));
40   - ut_asserteq(-EACCES, reset_request(dev, RESET_COLD));
41   - state->reset_allowed[RESET_POWER] = false;
42   - ut_asserteq(-EACCES, reset_request(dev, RESET_POWER));
43   - state->reset_allowed[RESET_POWER] = true;
44   -
45   - return 0;
46   -}
47   -DM_TEST(dm_test_reset_base, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
48   -
49   -/* Test that we can walk through the reset devices */
50   -static int dm_test_reset_walk(struct unit_test_state *uts)
51   -{
52   - struct sandbox_state *state = state_get_current();
53   -
54   - /* If we generate a power reset, we will exit sandbox! */
55   - state->reset_allowed[RESET_POWER] = false;
56   - ut_asserteq(-EACCES, reset_walk(RESET_WARM));
57   - ut_asserteq(-EACCES, reset_walk(RESET_COLD));
58   - ut_asserteq(-EACCES, reset_walk(RESET_POWER));
59   -
60   - /*
61   - * Enable cold reset - this should make cold reset work, plus a warm
62   - * reset should be promoted to cold, since this is the next step
63   - * along.
64   - */
65   - state->reset_allowed[RESET_COLD] = true;
66   - ut_asserteq(-EINPROGRESS, reset_walk(RESET_WARM));
67   - ut_asserteq(-EINPROGRESS, reset_walk(RESET_COLD));
68   - ut_asserteq(-EACCES, reset_walk(RESET_POWER));
69   - state->reset_allowed[RESET_COLD] = false;
70   - state->reset_allowed[RESET_POWER] = true;
71   -
72   - return 0;
73   -}
74   -DM_TEST(dm_test_reset_walk, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
  1 +/*
  2 + * Copyright (C) 2015 Google, Inc
  3 + *
  4 + * SPDX-License-Identifier: GPL-2.0+
  5 + */
  6 +
  7 +#include <common.h>
  8 +#include <dm.h>
  9 +#include <sysreset.h>
  10 +#include <asm/state.h>
  11 +#include <asm/test.h>
  12 +#include <dm/test.h>
  13 +#include <test/ut.h>
  14 +
  15 +/* Test that we can use particular sysreset devices */
  16 +static int dm_test_sysreset_base(struct unit_test_state *uts)
  17 +{
  18 + struct sandbox_state *state = state_get_current();
  19 + struct udevice *dev;
  20 +
  21 + /* Device 0 is the platform data device - it should never respond */
  22 + ut_assertok(uclass_get_device(UCLASS_SYSRESET, 0, &dev));
  23 + ut_asserteq(-ENODEV, sysreset_request(dev, SYSRESET_WARM));
  24 + ut_asserteq(-ENODEV, sysreset_request(dev, SYSRESET_COLD));
  25 + ut_asserteq(-ENODEV, sysreset_request(dev, SYSRESET_POWER));
  26 +
  27 + /* Device 1 is the warm sysreset device */
  28 + ut_assertok(uclass_get_device(UCLASS_SYSRESET, 1, &dev));
  29 + ut_asserteq(-EACCES, sysreset_request(dev, SYSRESET_WARM));
  30 + ut_asserteq(-ENOSYS, sysreset_request(dev, SYSRESET_COLD));
  31 + ut_asserteq(-ENOSYS, sysreset_request(dev, SYSRESET_POWER));
  32 +
  33 + state->sysreset_allowed[SYSRESET_WARM] = true;
  34 + ut_asserteq(-EINPROGRESS, sysreset_request(dev, SYSRESET_WARM));
  35 + state->sysreset_allowed[SYSRESET_WARM] = false;
  36 +
  37 + /* Device 2 is the cold sysreset device */
  38 + ut_assertok(uclass_get_device(UCLASS_SYSRESET, 2, &dev));
  39 + ut_asserteq(-ENOSYS, sysreset_request(dev, SYSRESET_WARM));
  40 + ut_asserteq(-EACCES, sysreset_request(dev, SYSRESET_COLD));
  41 + state->sysreset_allowed[SYSRESET_POWER] = false;
  42 + ut_asserteq(-EACCES, sysreset_request(dev, SYSRESET_POWER));
  43 + state->sysreset_allowed[SYSRESET_POWER] = true;
  44 +
  45 + return 0;
  46 +}
  47 +DM_TEST(dm_test_sysreset_base, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
  48 +
  49 +/* Test that we can walk through the sysreset devices */
  50 +static int dm_test_sysreset_walk(struct unit_test_state *uts)
  51 +{
  52 + struct sandbox_state *state = state_get_current();
  53 +
  54 + /* If we generate a power sysreset, we will exit sandbox! */
  55 + state->sysreset_allowed[SYSRESET_POWER] = false;
  56 + ut_asserteq(-EACCES, sysreset_walk(SYSRESET_WARM));
  57 + ut_asserteq(-EACCES, sysreset_walk(SYSRESET_COLD));
  58 + ut_asserteq(-EACCES, sysreset_walk(SYSRESET_POWER));
  59 +
  60 + /*
  61 + * Enable cold system reset - this should make cold system reset work,
  62 + * plus a warm system reset should be promoted to cold, since this is
  63 + * the next step along.
  64 + */
  65 + state->sysreset_allowed[SYSRESET_COLD] = true;
  66 + ut_asserteq(-EINPROGRESS, sysreset_walk(SYSRESET_WARM));
  67 + ut_asserteq(-EINPROGRESS, sysreset_walk(SYSRESET_COLD));
  68 + ut_asserteq(-EACCES, sysreset_walk(SYSRESET_POWER));
  69 + state->sysreset_allowed[SYSRESET_COLD] = false;
  70 + state->sysreset_allowed[SYSRESET_POWER] = true;
  71 +
  72 + return 0;
  73 +}
  74 +DM_TEST(dm_test_sysreset_walk, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);