Skip to content

Commit 71255c4

Browse files
committed
aspeed/smc: Add default reset values
This simplifies the reset handler and has the benefit to remove some "bad" use of the segments array as an identifier of the controller model. Signed-off-by: Cédric Le Goater <[email protected]>
1 parent f75b533 commit 71255c4

File tree

2 files changed

+28
-25
lines changed

2 files changed

+28
-25
lines changed

hw/ssi/aspeed_smc.c

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -196,12 +196,9 @@
196196
* controller. These can be changed when board is initialized with the
197197
* Segment Address Registers.
198198
*/
199-
static const AspeedSegments aspeed_2400_fmc_segments[];
200199
static const AspeedSegments aspeed_2400_spi1_segments[];
201-
static const AspeedSegments aspeed_2500_fmc_segments[];
202200
static const AspeedSegments aspeed_2500_spi1_segments[];
203201
static const AspeedSegments aspeed_2500_spi2_segments[];
204-
static const AspeedSegments aspeed_2600_fmc_segments[];
205202

206203
#define ASPEED_SMC_FEATURE_DMA 0x1
207204
#define ASPEED_SMC_FEATURE_DMA_GRANT 0x2
@@ -686,7 +683,11 @@ static void aspeed_smc_reset(DeviceState *d)
686683
AspeedSMCClass *asc = ASPEED_SMC_GET_CLASS(s);
687684
int i;
688685

689-
memset(s->regs, 0, sizeof s->regs);
686+
if (asc->resets) {
687+
memcpy(s->regs, asc->resets, sizeof s->regs);
688+
} else {
689+
memset(s->regs, 0, sizeof s->regs);
690+
}
690691

691692
/* Unselect all peripherals */
692693
for (i = 0; i < s->num_cs; ++i) {
@@ -700,27 +701,6 @@ static void aspeed_smc_reset(DeviceState *d)
700701
asc->segment_to_reg(s, &asc->segments[i]));
701702
}
702703

703-
/* HW strapping flash type for the AST2600 controllers */
704-
if (asc->segments == aspeed_2600_fmc_segments) {
705-
/* flash type is fixed to SPI for all */
706-
s->regs[s->r_conf] |= (CONF_FLASH_TYPE_SPI << CONF_FLASH_TYPE0);
707-
s->regs[s->r_conf] |= (CONF_FLASH_TYPE_SPI << CONF_FLASH_TYPE1);
708-
s->regs[s->r_conf] |= (CONF_FLASH_TYPE_SPI << CONF_FLASH_TYPE2);
709-
}
710-
711-
/* HW strapping flash type for FMC controllers */
712-
if (asc->segments == aspeed_2500_fmc_segments) {
713-
/* flash type is fixed to SPI for CE0 and CE1 */
714-
s->regs[s->r_conf] |= (CONF_FLASH_TYPE_SPI << CONF_FLASH_TYPE0);
715-
s->regs[s->r_conf] |= (CONF_FLASH_TYPE_SPI << CONF_FLASH_TYPE1);
716-
}
717-
718-
/* HW strapping for AST2400 FMC controllers (SCU70). Let's use the
719-
* configuration of the palmetto-bmc machine */
720-
if (asc->segments == aspeed_2400_fmc_segments) {
721-
s->regs[s->r_conf] |= (CONF_FLASH_TYPE_SPI << CONF_FLASH_TYPE0);
722-
}
723-
724704
s->snoop_index = SNOOP_OFF;
725705
s->snoop_dummies = 0;
726706
}
@@ -1352,6 +1332,14 @@ static const TypeInfo aspeed_2400_smc_info = {
13521332
.class_init = aspeed_2400_smc_class_init,
13531333
};
13541334

1335+
static const uint32_t aspeed_2400_fmc_resets[ASPEED_SMC_R_MAX] = {
1336+
/*
1337+
* CE0 and CE1 types are HW strapped in SCU70. Do it here to
1338+
* simplify the model.
1339+
*/
1340+
[R_CONF] = CONF_FLASH_TYPE_SPI << CONF_FLASH_TYPE0,
1341+
};
1342+
13551343
static const AspeedSegments aspeed_2400_fmc_segments[] = {
13561344
{ 0x20000000, 64 * MiB }, /* start address is readonly */
13571345
{ 0x24000000, 32 * MiB },
@@ -1374,6 +1362,7 @@ static void aspeed_2400_fmc_class_init(ObjectClass *klass, void *data)
13741362
asc->conf_enable_w0 = CONF_ENABLE_W0;
13751363
asc->max_peripherals = 5;
13761364
asc->segments = aspeed_2400_fmc_segments;
1365+
asc->resets = aspeed_2400_fmc_resets;
13771366
asc->flash_window_base = 0x20000000;
13781367
asc->flash_window_size = 0x10000000;
13791368
asc->features = ASPEED_SMC_FEATURE_DMA;
@@ -1424,6 +1413,11 @@ static const TypeInfo aspeed_2400_spi1_info = {
14241413
.class_init = aspeed_2400_spi1_class_init,
14251414
};
14261415

1416+
static const uint32_t aspeed_2500_fmc_resets[ASPEED_SMC_R_MAX] = {
1417+
[R_CONF] = (CONF_FLASH_TYPE_SPI << CONF_FLASH_TYPE0 |
1418+
CONF_FLASH_TYPE_SPI << CONF_FLASH_TYPE1),
1419+
};
1420+
14271421
static const AspeedSegments aspeed_2500_fmc_segments[] = {
14281422
{ 0x20000000, 128 * MiB }, /* start address is readonly */
14291423
{ 0x28000000, 32 * MiB },
@@ -1444,6 +1438,7 @@ static void aspeed_2500_fmc_class_init(ObjectClass *klass, void *data)
14441438
asc->conf_enable_w0 = CONF_ENABLE_W0;
14451439
asc->max_peripherals = 3;
14461440
asc->segments = aspeed_2500_fmc_segments;
1441+
asc->resets = aspeed_2500_fmc_resets;
14471442
asc->flash_window_base = 0x20000000;
14481443
asc->flash_window_size = 0x10000000;
14491444
asc->features = ASPEED_SMC_FEATURE_DMA;
@@ -1569,6 +1564,12 @@ static void aspeed_2600_smc_reg_to_segment(const AspeedSMCState *s,
15691564
}
15701565
}
15711566

1567+
static const uint32_t aspeed_2600_fmc_resets[ASPEED_SMC_R_MAX] = {
1568+
[R_CONF] = (CONF_FLASH_TYPE_SPI << CONF_FLASH_TYPE0 |
1569+
CONF_FLASH_TYPE_SPI << CONF_FLASH_TYPE1 |
1570+
CONF_FLASH_TYPE_SPI << CONF_FLASH_TYPE2),
1571+
};
1572+
15721573
static const AspeedSegments aspeed_2600_fmc_segments[] = {
15731574
{ 0x0, 128 * MiB }, /* start address is readonly */
15741575
{ 128 * MiB, 128 * MiB }, /* default is disabled but needed for -kernel */
@@ -1589,6 +1590,7 @@ static void aspeed_2600_fmc_class_init(ObjectClass *klass, void *data)
15891590
asc->conf_enable_w0 = CONF_ENABLE_W0;
15901591
asc->max_peripherals = 3;
15911592
asc->segments = aspeed_2600_fmc_segments;
1593+
asc->resets = aspeed_2600_fmc_resets;
15921594
asc->flash_window_base = 0x20000000;
15931595
asc->flash_window_size = 0x10000000;
15941596
asc->features = ASPEED_SMC_FEATURE_DMA |

include/hw/ssi/aspeed_smc.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ struct AspeedSMCClass {
9898
uint8_t nregs_timings;
9999
uint8_t conf_enable_w0;
100100
uint8_t max_peripherals;
101+
const uint32_t *resets;
101102
const AspeedSegments *segments;
102103
hwaddr flash_window_base;
103104
uint32_t flash_window_size;

0 commit comments

Comments
 (0)