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>master
parent
6f82fac2f2
commit
1163625898
@ -1,100 +0,0 @@ |
||||
/*
|
||||
* Copyright (c) 2015 Google, Inc |
||||
* Written by Simon Glass <sjg@chromium.org> |
||||
* |
||||
* SPDX-License-Identifier: GPL-2.0+ |
||||
*/ |
||||
|
||||
#include <common.h> |
||||
#include <dm.h> |
||||
#include <errno.h> |
||||
#include <reset.h> |
||||
#include <asm/state.h> |
||||
#include <asm/test.h> |
||||
|
||||
DECLARE_GLOBAL_DATA_PTR; |
||||
|
||||
static int sandbox_warm_reset_request(struct udevice *dev, enum reset_t type) |
||||
{ |
||||
struct sandbox_state *state = state_get_current(); |
||||
|
||||
switch (type) { |
||||
case RESET_WARM: |
||||
state->last_reset = type; |
||||
break; |
||||
default: |
||||
return -ENOSYS; |
||||
} |
||||
if (!state->reset_allowed[type]) |
||||
return -EACCES; |
||||
|
||||
return -EINPROGRESS; |
||||
} |
||||
|
||||
static int sandbox_reset_request(struct udevice *dev, enum reset_t type) |
||||
{ |
||||
struct sandbox_state *state = state_get_current(); |
||||
|
||||
/*
|
||||
* If we have a device tree, the device we created from platform data |
||||
* (see the U_BOOT_DEVICE() declaration below) should not do anything. |
||||
* If we are that device, return an error. |
||||
*/ |
||||
if (state->fdt_fname && dev->of_offset == -1) |
||||
return -ENODEV; |
||||
|
||||
switch (type) { |
||||
case RESET_COLD: |
||||
state->last_reset = type; |
||||
break; |
||||
case RESET_POWER: |
||||
state->last_reset = type; |
||||
if (!state->reset_allowed[type]) |
||||
return -EACCES; |
||||
sandbox_exit(); |
||||
break; |
||||
default: |
||||
return -ENOSYS; |
||||
} |
||||
if (!state->reset_allowed[type]) |
||||
return -EACCES; |
||||
|
||||
return -EINPROGRESS; |
||||
} |
||||
|
||||
static struct reset_ops sandbox_reset_ops = { |
||||
.request = sandbox_reset_request, |
||||
}; |
||||
|
||||
static const struct udevice_id sandbox_reset_ids[] = { |
||||
{ .compatible = "sandbox,reset" }, |
||||
{ } |
||||
}; |
||||
|
||||
U_BOOT_DRIVER(reset_sandbox) = { |
||||
.name = "reset_sandbox", |
||||
.id = UCLASS_RESET, |
||||
.of_match = sandbox_reset_ids, |
||||
.ops = &sandbox_reset_ops, |
||||
}; |
||||
|
||||
static struct reset_ops sandbox_warm_reset_ops = { |
||||
.request = sandbox_warm_reset_request, |
||||
}; |
||||
|
||||
static const struct udevice_id sandbox_warm_reset_ids[] = { |
||||
{ .compatible = "sandbox,warm-reset" }, |
||||
{ } |
||||
}; |
||||
|
||||
U_BOOT_DRIVER(warm_reset_sandbox) = { |
||||
.name = "warm_reset_sandbox", |
||||
.id = UCLASS_RESET, |
||||
.of_match = sandbox_warm_reset_ids, |
||||
.ops = &sandbox_warm_reset_ops, |
||||
}; |
||||
|
||||
/* This is here in case we don't have a device tree */ |
||||
U_BOOT_DEVICE(reset_sandbox_non_fdt) = { |
||||
.name = "reset_sandbox", |
||||
}; |
@ -0,0 +1,101 @@ |
||||
/*
|
||||
* Copyright (c) 2015 Google, Inc |
||||
* Written by Simon Glass <sjg@chromium.org> |
||||
* |
||||
* SPDX-License-Identifier: GPL-2.0+ |
||||
*/ |
||||
|
||||
#include <common.h> |
||||
#include <dm.h> |
||||
#include <errno.h> |
||||
#include <sysreset.h> |
||||
#include <asm/state.h> |
||||
#include <asm/test.h> |
||||
|
||||
DECLARE_GLOBAL_DATA_PTR; |
||||
|
||||
static int sandbox_warm_sysreset_request(struct udevice *dev, |
||||
enum sysreset_t type) |
||||
{ |
||||
struct sandbox_state *state = state_get_current(); |
||||
|
||||
switch (type) { |
||||
case SYSRESET_WARM: |
||||
state->last_sysreset = type; |
||||
break; |
||||
default: |
||||
return -ENOSYS; |
||||
} |
||||
if (!state->sysreset_allowed[type]) |
||||
return -EACCES; |
||||
|
||||
return -EINPROGRESS; |
||||
} |
||||
|
||||
static int sandbox_sysreset_request(struct udevice *dev, enum sysreset_t type) |
||||
{ |
||||
struct sandbox_state *state = state_get_current(); |
||||
|
||||
/*
|
||||
* If we have a device tree, the device we created from platform data |
||||
* (see the U_BOOT_DEVICE() declaration below) should not do anything. |
||||
* If we are that device, return an error. |
||||
*/ |
||||
if (state->fdt_fname && dev->of_offset == -1) |
||||
return -ENODEV; |
||||
|
||||
switch (type) { |
||||
case SYSRESET_COLD: |
||||
state->last_sysreset = type; |
||||
break; |
||||
case SYSRESET_POWER: |
||||
state->last_sysreset = type; |
||||
if (!state->sysreset_allowed[type]) |
||||
return -EACCES; |
||||
sandbox_exit(); |
||||
break; |
||||
default: |
||||
return -ENOSYS; |
||||
} |
||||
if (!state->sysreset_allowed[type]) |
||||
return -EACCES; |
||||
|
||||
return -EINPROGRESS; |
||||
} |
||||
|
||||
static struct sysreset_ops sandbox_sysreset_ops = { |
||||
.request = sandbox_sysreset_request, |
||||
}; |
||||
|
||||
static const struct udevice_id sandbox_sysreset_ids[] = { |
||||
{ .compatible = "sandbox,reset" }, |
||||
{ } |
||||
}; |
||||
|
||||
U_BOOT_DRIVER(sysreset_sandbox) = { |
||||
.name = "sysreset_sandbox", |
||||
.id = UCLASS_SYSRESET, |
||||
.of_match = sandbox_sysreset_ids, |
||||
.ops = &sandbox_sysreset_ops, |
||||
}; |
||||
|
||||
static struct sysreset_ops sandbox_warm_sysreset_ops = { |
||||
.request = sandbox_warm_sysreset_request, |
||||
}; |
||||
|
||||
static const struct udevice_id sandbox_warm_sysreset_ids[] = { |
||||
{ .compatible = "sandbox,warm-reset" }, |
||||
{ } |
||||
}; |
||||
|
||||
U_BOOT_DRIVER(warm_sysreset_sandbox) = { |
||||
.name = "warm_sysreset_sandbox", |
||||
.id = UCLASS_SYSRESET, |
||||
.of_match = sandbox_warm_sysreset_ids, |
||||
.ops = &sandbox_warm_sysreset_ops, |
||||
}; |
||||
|
||||
/* This is here in case we don't have a device tree */ |
||||
U_BOOT_DEVICE(sysreset_sandbox_non_fdt) = { |
||||
.name = "sysreset_sandbox", |
||||
}; |
@ -1,71 +0,0 @@ |
||||
/*
|
||||
* Copyright (c) 2015 Google, Inc |
||||
* Written by Simon Glass <sjg@chromium.org> |
||||
* |
||||
* SPDX-License-Identifier: GPL-2.0+ |
||||
*/ |
||||
|
||||
#ifndef __RESET_H |
||||
#define __RESET_H |
||||
|
||||
enum reset_t { |
||||
RESET_WARM, /* Reset CPU, keep GPIOs active */ |
||||
RESET_COLD, /* Reset CPU and GPIOs */ |
||||
RESET_POWER, /* Reset PMIC (remove and restore power) */ |
||||
|
||||
RESET_COUNT, |
||||
}; |
||||
|
||||
struct reset_ops { |
||||
/**
|
||||
* request() - request a reset of the given type |
||||
* |
||||
* Note that this function may return before the reset takes effect. |
||||
* |
||||
* @type: Reset type to request |
||||
* @return -EINPROGRESS if the reset has been started and |
||||
* will complete soon, -EPROTONOSUPPORT if not supported |
||||
* by this device, 0 if the reset has already happened |
||||
* (in which case this method will not actually return) |
||||
*/ |
||||
int (*request)(struct udevice *dev, enum reset_t type); |
||||
}; |
||||
|
||||
#define reset_get_ops(dev) ((struct reset_ops *)(dev)->driver->ops) |
||||
|
||||
/**
|
||||
* reset_request() - request a reset |
||||
* |
||||
* @type: Reset type to request |
||||
* @return 0 if OK, -EPROTONOSUPPORT if not supported by this device |
||||
*/ |
||||
int reset_request(struct udevice *dev, enum reset_t type); |
||||
|
||||
/**
|
||||
* reset_walk() - cause a reset |
||||
* |
||||
* This works through the available reset devices until it finds one that can |
||||
* perform a reset. If the provided reset type is not available, the next one |
||||
* will be tried. |
||||
* |
||||
* If this function fails to reset, it will display a message and halt |
||||
* |
||||
* @type: Reset type to request |
||||
* @return -EINPROGRESS if a reset is in progress, -ENOSYS if not available |
||||
*/ |
||||
int reset_walk(enum reset_t type); |
||||
|
||||
/**
|
||||
* reset_walk_halt() - try to reset, otherwise halt |
||||
* |
||||
* This calls reset_walk(). If it returns, indicating that reset is not |
||||
* supported, it prints a message and halts. |
||||
*/ |
||||
void reset_walk_halt(enum reset_t type); |
||||
|
||||
/**
|
||||
* reset_cpu() - calls reset_walk(RESET_WARM) |
||||
*/ |
||||
void reset_cpu(ulong addr); |
||||
|
||||
#endif |
@ -0,0 +1,71 @@ |
||||
/*
|
||||
* Copyright (c) 2015 Google, Inc |
||||
* Written by Simon Glass <sjg@chromium.org> |
||||
* |
||||
* SPDX-License-Identifier: GPL-2.0+ |
||||
*/ |
||||
|
||||
#ifndef __SYSRESET_H |
||||
#define __SYSRESET_H |
||||
|
||||
enum sysreset_t { |
||||
SYSRESET_WARM, /* Reset CPU, keep GPIOs active */ |
||||
SYSRESET_COLD, /* Reset CPU and GPIOs */ |
||||
SYSRESET_POWER, /* Reset PMIC (remove and restore power) */ |
||||
|
||||
SYSRESET_COUNT, |
||||
}; |
||||
|
||||
struct sysreset_ops { |
||||
/**
|
||||
* request() - request a sysreset of the given type |
||||
* |
||||
* Note that this function may return before the reset takes effect. |
||||
* |
||||
* @type: Reset type to request |
||||
* @return -EINPROGRESS if the reset has been started and |
||||
* will complete soon, -EPROTONOSUPPORT if not supported |
||||
* by this device, 0 if the reset has already happened |
||||
* (in which case this method will not actually return) |
||||
*/ |
||||
int (*request)(struct udevice *dev, enum sysreset_t type); |
||||
}; |
||||
|
||||
#define sysreset_get_ops(dev) ((struct sysreset_ops *)(dev)->driver->ops) |
||||
|
||||
/**
|
||||
* sysreset_request() - request a sysreset |
||||
* |
||||
* @type: Reset type to request |
||||
* @return 0 if OK, -EPROTONOSUPPORT if not supported by this device |
||||
*/ |
||||
int sysreset_request(struct udevice *dev, enum sysreset_t type); |
||||
|
||||
/**
|
||||
* sysreset_walk() - cause a system reset |
||||
* |
||||
* This works through the available sysreset devices until it finds one that can |
||||
* perform a reset. If the provided sysreset type is not available, the next one |
||||
* will be tried. |
||||
* |
||||
* If this function fails to reset, it will display a message and halt |
||||
* |
||||
* @type: Reset type to request |
||||
* @return -EINPROGRESS if a reset is in progress, -ENOSYS if not available |
||||
*/ |
||||
int sysreset_walk(enum sysreset_t type); |
||||
|
||||
/**
|
||||
* sysreset_walk_halt() - try to reset, otherwise halt |
||||
* |
||||
* This calls sysreset_walk(). If it returns, indicating that reset is not |
||||
* supported, it prints a message and halts. |
||||
*/ |
||||
void sysreset_walk_halt(enum sysreset_t type); |
||||
|
||||
/**
|
||||
* reset_cpu() - calls sysreset_walk(SYSRESET_WARM) |
||||
*/ |
||||
void reset_cpu(ulong addr); |
||||
|
||||
#endif |
@ -1,74 +0,0 @@ |
||||
/*
|
||||
* Copyright (C) 2015 Google, Inc |
||||
* |
||||
* SPDX-License-Identifier: GPL-2.0+ |
||||
*/ |
||||
|
||||
#include <common.h> |
||||
#include <dm.h> |
||||
#include <reset.h> |
||||
#include <asm/state.h> |
||||
#include <asm/test.h> |
||||
#include <dm/test.h> |
||||
#include <test/ut.h> |
||||
|
||||
/* Test that we can use particular reset devices */ |
||||
static int dm_test_reset_base(struct unit_test_state *uts) |
||||
{ |
||||
struct sandbox_state *state = state_get_current(); |
||||
struct udevice *dev; |
||||
|
||||
/* Device 0 is the platform data device - it should never respond */ |
||||
ut_assertok(uclass_get_device(UCLASS_RESET, 0, &dev)); |
||||
ut_asserteq(-ENODEV, reset_request(dev, RESET_WARM)); |
||||
ut_asserteq(-ENODEV, reset_request(dev, RESET_COLD)); |
||||
ut_asserteq(-ENODEV, reset_request(dev, RESET_POWER)); |
||||
|
||||
/* Device 1 is the warm reset device */ |
||||
ut_assertok(uclass_get_device(UCLASS_RESET, 1, &dev)); |
||||
ut_asserteq(-EACCES, reset_request(dev, RESET_WARM)); |
||||
ut_asserteq(-ENOSYS, reset_request(dev, RESET_COLD)); |
||||
ut_asserteq(-ENOSYS, reset_request(dev, RESET_POWER)); |
||||
|
||||
state->reset_allowed[RESET_WARM] = true; |
||||
ut_asserteq(-EINPROGRESS, reset_request(dev, RESET_WARM)); |
||||
state->reset_allowed[RESET_WARM] = false; |
||||
|
||||
/* Device 2 is the cold reset device */ |
||||
ut_assertok(uclass_get_device(UCLASS_RESET, 2, &dev)); |
||||
ut_asserteq(-ENOSYS, reset_request(dev, RESET_WARM)); |
||||
ut_asserteq(-EACCES, reset_request(dev, RESET_COLD)); |
||||
state->reset_allowed[RESET_POWER] = false; |
||||
ut_asserteq(-EACCES, reset_request(dev, RESET_POWER)); |
||||
state->reset_allowed[RESET_POWER] = true; |
||||
|
||||
return 0; |
||||
} |
||||
DM_TEST(dm_test_reset_base, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT); |
||||
|
||||
/* Test that we can walk through the reset devices */ |
||||
static int dm_test_reset_walk(struct unit_test_state *uts) |
||||
{ |
||||
struct sandbox_state *state = state_get_current(); |
||||
|
||||
/* If we generate a power reset, we will exit sandbox! */ |
||||
state->reset_allowed[RESET_POWER] = false; |
||||
ut_asserteq(-EACCES, reset_walk(RESET_WARM)); |
||||
ut_asserteq(-EACCES, reset_walk(RESET_COLD)); |
||||
ut_asserteq(-EACCES, reset_walk(RESET_POWER)); |
||||
|
||||
/*
|
||||
* Enable cold reset - this should make cold reset work, plus a warm |
||||
* reset should be promoted to cold, since this is the next step |
||||
* along. |
||||
*/ |
||||
state->reset_allowed[RESET_COLD] = true; |
||||
ut_asserteq(-EINPROGRESS, reset_walk(RESET_WARM)); |
||||
ut_asserteq(-EINPROGRESS, reset_walk(RESET_COLD)); |
||||
ut_asserteq(-EACCES, reset_walk(RESET_POWER)); |
||||
state->reset_allowed[RESET_COLD] = false; |
||||
state->reset_allowed[RESET_POWER] = true; |
||||
|
||||
return 0; |
||||
} |
||||
DM_TEST(dm_test_reset_walk, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT); |
@ -0,0 +1,74 @@ |
||||
/*
|
||||
* Copyright (C) 2015 Google, Inc |
||||
* |
||||
* SPDX-License-Identifier: GPL-2.0+ |
||||
*/ |
||||
|
||||
#include <common.h> |
||||
#include <dm.h> |
||||
#include <sysreset.h> |
||||
#include <asm/state.h> |
||||
#include <asm/test.h> |
||||
#include <dm/test.h> |
||||
#include <test/ut.h> |
||||
|
||||
/* Test that we can use particular sysreset devices */ |
||||
static int dm_test_sysreset_base(struct unit_test_state *uts) |
||||
{ |
||||
struct sandbox_state *state = state_get_current(); |
||||
struct udevice *dev; |
||||
|
||||
/* Device 0 is the platform data device - it should never respond */ |
||||
ut_assertok(uclass_get_device(UCLASS_SYSRESET, 0, &dev)); |
||||
ut_asserteq(-ENODEV, sysreset_request(dev, SYSRESET_WARM)); |
||||
ut_asserteq(-ENODEV, sysreset_request(dev, SYSRESET_COLD)); |
||||
ut_asserteq(-ENODEV, sysreset_request(dev, SYSRESET_POWER)); |
||||
|
||||
/* Device 1 is the warm sysreset device */ |
||||
ut_assertok(uclass_get_device(UCLASS_SYSRESET, 1, &dev)); |
||||
ut_asserteq(-EACCES, sysreset_request(dev, SYSRESET_WARM)); |
||||
ut_asserteq(-ENOSYS, sysreset_request(dev, SYSRESET_COLD)); |
||||
ut_asserteq(-ENOSYS, sysreset_request(dev, SYSRESET_POWER)); |
||||
|
||||
state->sysreset_allowed[SYSRESET_WARM] = true; |
||||
ut_asserteq(-EINPROGRESS, sysreset_request(dev, SYSRESET_WARM)); |
||||
state->sysreset_allowed[SYSRESET_WARM] = false; |
||||
|
||||
/* Device 2 is the cold sysreset device */ |
||||
ut_assertok(uclass_get_device(UCLASS_SYSRESET, 2, &dev)); |
||||
ut_asserteq(-ENOSYS, sysreset_request(dev, SYSRESET_WARM)); |
||||
ut_asserteq(-EACCES, sysreset_request(dev, SYSRESET_COLD)); |
||||
state->sysreset_allowed[SYSRESET_POWER] = false; |
||||
ut_asserteq(-EACCES, sysreset_request(dev, SYSRESET_POWER)); |
||||
state->sysreset_allowed[SYSRESET_POWER] = true; |
||||
|
||||
return 0; |
||||
} |
||||
DM_TEST(dm_test_sysreset_base, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT); |
||||
|
||||
/* Test that we can walk through the sysreset devices */ |
||||
static int dm_test_sysreset_walk(struct unit_test_state *uts) |
||||
{ |
||||
struct sandbox_state *state = state_get_current(); |
||||
|
||||
/* If we generate a power sysreset, we will exit sandbox! */ |
||||
state->sysreset_allowed[SYSRESET_POWER] = false; |
||||
ut_asserteq(-EACCES, sysreset_walk(SYSRESET_WARM)); |
||||
ut_asserteq(-EACCES, sysreset_walk(SYSRESET_COLD)); |
||||
ut_asserteq(-EACCES, sysreset_walk(SYSRESET_POWER)); |
||||
|
||||
/*
|
||||
* Enable cold system reset - this should make cold system reset work, |
||||
* plus a warm system reset should be promoted to cold, since this is |
||||
* the next step along. |
||||
*/ |
||||
state->sysreset_allowed[SYSRESET_COLD] = true; |
||||
ut_asserteq(-EINPROGRESS, sysreset_walk(SYSRESET_WARM)); |
||||
ut_asserteq(-EINPROGRESS, sysreset_walk(SYSRESET_COLD)); |
||||
ut_asserteq(-EACCES, sysreset_walk(SYSRESET_POWER)); |
||||
state->sysreset_allowed[SYSRESET_COLD] = false; |
||||
state->sysreset_allowed[SYSRESET_POWER] = true; |
||||
|
||||
return 0; |
||||
} |
||||
DM_TEST(dm_test_sysreset_walk, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT); |
Loading…
Reference in new issue