Changeset View
Changeset View
Standalone View
Standalone View
head/sys/dev/bhnd/bhnd_subr.c
Show First 20 Lines • Show All 828 Lines • ▼ Show 20 Lines | |||||
* @retval 0 success | * @retval 0 success | ||||
* @retval non-zero if the ChipCommon identification data could not be read. | * @retval non-zero if the ChipCommon identification data could not be read. | ||||
*/ | */ | ||||
int | int | ||||
bhnd_read_chipid(device_t dev, struct resource_spec *rs, | bhnd_read_chipid(device_t dev, struct resource_spec *rs, | ||||
bus_size_t chipc_offset, struct bhnd_chipid *result) | bus_size_t chipc_offset, struct bhnd_chipid *result) | ||||
{ | { | ||||
struct resource *res; | struct resource *res; | ||||
bhnd_addr_t enum_addr; | |||||
uint32_t reg; | uint32_t reg; | ||||
uint8_t chip_type; | |||||
int error, rid, rtype; | int error, rid, rtype; | ||||
/* Allocate the ChipCommon window resource and fetch the chipid data */ | |||||
rid = rs->rid; | rid = rs->rid; | ||||
rtype = rs->type; | rtype = rs->type; | ||||
error = 0; | |||||
/* Allocate the ChipCommon window resource and fetch the chipid data */ | |||||
res = bus_alloc_resource_any(dev, rtype, &rid, RF_ACTIVE); | res = bus_alloc_resource_any(dev, rtype, &rid, RF_ACTIVE); | ||||
if (res == NULL) { | if (res == NULL) { | ||||
device_printf(dev, | device_printf(dev, | ||||
"failed to allocate bhnd chipc resource\n"); | "failed to allocate bhnd chipc resource\n"); | ||||
return (ENXIO); | return (ENXIO); | ||||
} | } | ||||
/* Fetch the basic chip info */ | /* Fetch the basic chip info */ | ||||
reg = bus_read_4(res, chipc_offset + CHIPC_ID); | reg = bus_read_4(res, chipc_offset + CHIPC_ID); | ||||
*result = bhnd_parse_chipid(reg, 0x0); | chip_type = CHIPC_GET_BITS(reg, CHIPC_ID_BUS); | ||||
/* Fetch the enum base address */ | /* Fetch the EROMPTR */ | ||||
error = 0; | if (BHND_CHIPTYPE_HAS_EROM(chip_type)) { | ||||
switch (result->chip_type) { | enum_addr = bus_read_4(res, chipc_offset + CHIPC_EROMPTR); | ||||
case BHND_CHIPTYPE_SIBA: | } else if (chip_type == BHND_CHIPTYPE_SIBA) { | ||||
result->enum_addr = BHND_DEFAULT_CHIPC_ADDR; | /* siba(4) uses the ChipCommon base address as the enumeration | ||||
break; | * address */ | ||||
case BHND_CHIPTYPE_BCMA: | enum_addr = rman_get_start(res) + chipc_offset; | ||||
case BHND_CHIPTYPE_BCMA_ALT: | } else { | ||||
result->enum_addr = bus_read_4(res, chipc_offset + | device_printf(dev, "unknown chip type %hhu\n", chip_type); | ||||
CHIPC_EROMPTR); | |||||
break; | |||||
case BHND_CHIPTYPE_UBUS: | |||||
device_printf(dev, "unsupported ubus/bcm63xx chip type"); | |||||
error = ENODEV; | error = ENODEV; | ||||
goto cleanup; | goto cleanup; | ||||
default: | |||||
device_printf(dev, "unknown chip type %hhu\n", | |||||
result->chip_type); | |||||
error = ENODEV; | |||||
goto cleanup; | |||||
} | } | ||||
*result = bhnd_parse_chipid(reg, enum_addr); | |||||
cleanup: | cleanup: | ||||
/* Clean up */ | /* Clean up */ | ||||
bus_release_resource(dev, rtype, rid, res); | bus_release_resource(dev, rtype, rid, res); | ||||
return (error); | return (error); | ||||
} | } | ||||
/** | /** | ||||
▲ Show 20 Lines • Show All 581 Lines • Show Last 20 Lines |