summaryrefslogtreecommitdiffstats
path: root/pci.c
diff options
context:
space:
mode:
authorSuren A. Chilingaryan <csa@dside.dyndns.org>2011-03-09 14:53:05 +0100
committerSuren A. Chilingaryan <csa@dside.dyndns.org>2011-03-09 14:53:05 +0100
commitb0596cb0f01f885153abffaecfa248920cb8658b (patch)
tree82c024c381a2dfdac3b4d98c9d1251be16a15da2 /pci.c
parent934bcc133abf774947070492a5f31677c9400c0d (diff)
downloadipecamera-b0596cb0f01f885153abffaecfa248920cb8658b.tar.gz
ipecamera-b0596cb0f01f885153abffaecfa248920cb8658b.tar.bz2
ipecamera-b0596cb0f01f885153abffaecfa248920cb8658b.tar.xz
ipecamera-b0596cb0f01f885153abffaecfa248920cb8658b.zip
Support writting and reading of register ranges
Diffstat (limited to 'pci.c')
-rw-r--r--pci.c30
1 files changed, 27 insertions, 3 deletions
diff --git a/pci.c b/pci.c
index 48cc318..9ddc1d6 100644
--- a/pci.c
+++ b/pci.c
@@ -226,6 +226,12 @@ pcilib_register_bank_t pcilib_find_bank(pcilib_t *ctx, const char *bank) {
pcilib_register_bank_t res;
unsigned long addr;
+ if (!bank) {
+ pcilib_register_bank_description_t *banks = pcilib_model[ctx->model].banks;
+ if ((banks)&&(banks[0].access)) return (pcilib_register_bank_t)0;
+ return -1;
+ }
+
if (sscanf(bank,"%lx", &addr) == 1) {
res = pcilib_find_bank_by_addr(ctx, addr);
if (res != PCILIB_REGISTER_BANK_INVALID) return res;
@@ -351,9 +357,15 @@ static int pcilib_read_register_space_internal(pcilib_t *ctx, pcilib_register_ba
return err;
}
-int pcilib_read_register_space(pcilib_t *ctx, pcilib_register_bank_t bank, pcilib_register_addr_t addr, size_t n, pcilib_register_value_t *buf) {
-// pcilib_register_bank_t bank = pcilib_find_bank(ctx, bank_addr);
- return pcilib_read_register_space_internal(ctx, bank, addr, n, 0, buf);
+int pcilib_read_register_space(pcilib_t *ctx, const char *bank, pcilib_register_addr_t addr, size_t n, pcilib_register_value_t *buf) {
+ pcilib_register_bank_t bank_id = pcilib_find_bank(ctx, bank);
+ if (bank_id == PCILIB_REGISTER_BANK_INVALID) {
+ if (bank) pcilib_error("Invalid register bank is specified (%s)", bank);
+ else pcilib_error("Register bank should be specified");
+ return PCILIB_ERROR_INVALID_BANK;
+ }
+
+ return pcilib_read_register_space_internal(ctx, bank_id, addr, n, 0, buf);
}
int pcilib_read_register_by_id(pcilib_t *ctx, pcilib_register_t reg, pcilib_register_value_t *value) {
@@ -439,6 +451,18 @@ static int pcilib_write_register_space_internal(pcilib_t *ctx, pcilib_register_b
return err;
}
+int pcilib_write_register_space(pcilib_t *ctx, const char *bank, pcilib_register_addr_t addr, size_t n, pcilib_register_value_t *buf) {
+ pcilib_register_bank_t bank_id = pcilib_find_bank(ctx, bank);
+ if (bank_id == PCILIB_REGISTER_BANK_INVALID) {
+ if (bank) pcilib_error("Invalid register bank is specified (%s)", bank);
+ else pcilib_error("Register bank should be specified");
+ return PCILIB_ERROR_INVALID_BANK;
+ }
+
+ return pcilib_write_register_space_internal(ctx, bank_id, addr, n, 0, buf);
+}
+
+
int pcilib_write_register_by_id(pcilib_t *ctx, pcilib_register_t reg, pcilib_register_value_t value) {
int err;
size_t i, n, bits;