1
0
mirror of git://projects.qi-hardware.com/ben-wpan.git synced 2024-11-26 05:28:25 +02:00

tools/: cleaned up the gross layering violation in atrf-xtal/atben.c

- include/atrf.h (atrf_ben_regs), lib/atrf.c (atrf_ben_regs),
  lib/driver.h (atben_regs), lib/atben.c (atben_regs): new function to
  get the mmap'ed registers in a less disgusting way
- atrf-xtal/atben.c (base, ben_setup): cleaned up the horrible layering
  violation
This commit is contained in:
Werner Almesberger 2011-04-10 07:25:11 -03:00
parent 7ff1a32ccf
commit 1a27e590d9
5 changed files with 25 additions and 18 deletions

View File

@ -78,8 +78,6 @@ static void rf_setup(struct atrf_dsc *dsc, int size, int trim)
/* ----- Ben hardware ------------------------------------------------------ */ /* ----- Ben hardware ------------------------------------------------------ */
static volatile void *base;
static volatile uint32_t *icmr, *icmsr, *icmcr; static volatile uint32_t *icmr, *icmsr, *icmcr;
static uint32_t old_icmr; static uint32_t old_icmr;
@ -129,22 +127,7 @@ static void enable_lcd(void)
static void ben_setup(struct atrf_dsc *dsc) static void ben_setup(struct atrf_dsc *dsc)
{ {
/* volatile void *base = atrf_ben_regs(dsc);
* @@@ Ugly. Should either mmap the registers again here or add some
* proper means to extract the pointer directly.
*/
struct atrf_dsc {
void *driver;
void *handle;
int chip_id;
};
struct atben_dsc {
int fd;
void *mem;
};
base = ((struct atben_dsc *) ((struct atrf_dsc *) dsc)->handle)->mem;
icmr = base+0x1004; icmr = base+0x1004;
icmsr = base+0x1008; icmsr = base+0x1008;

View File

@ -27,6 +27,7 @@ struct atrf_dsc;
void *atrf_usb_handle(struct atrf_dsc *dsc); /* hack for atrf-id */ void *atrf_usb_handle(struct atrf_dsc *dsc); /* hack for atrf-id */
void *atrf_ben_regs(struct atrf_dsc *dsc); /* hack for atrf-xtal */
const char *atrf_default_driver_name(void); const char *atrf_default_driver_name(void);
struct atrf_dsc *atrf_open(const char *arg); struct atrf_dsc *atrf_open(const char *arg);

View File

@ -351,6 +351,17 @@ static int atben_interrupt(void *handle)
} }
/* ----- Driver-specific hacks --------------------------------------------- */
void *atben_regs(void *handle)
{
struct atben_dsc *dsc = handle;
return dsc->mem;
}
/* ----- Driver interface -------------------------------------------------- */ /* ----- Driver interface -------------------------------------------------- */

View File

@ -42,6 +42,16 @@ void *atrf_usb_handle(struct atrf_dsc *dsc)
} }
void *atrf_ben_regs(struct atrf_dsc *dsc)
{
#ifdef HAVE_BEN
return atben_regs(dsc->handle);
#else
return NULL;
#endif
}
int atrf_error(struct atrf_dsc *dsc) int atrf_error(struct atrf_dsc *dsc)
{ {
return dsc->driver->error ? dsc->driver->error(dsc->handle) : 0; return dsc->driver->error ? dsc->driver->error(dsc->handle) : 0;

View File

@ -40,4 +40,6 @@ int atrf_set_clkm_generic(
void (*reg_write)(void *dsc, uint8_t reg, uint8_t value), void (*reg_write)(void *dsc, uint8_t reg, uint8_t value),
void *handle, int mhz); void *handle, int mhz);
void *atben_regs(void *dsc); /* hack for atrf-xtal */
#endif /* !DRIVER_H */ #endif /* !DRIVER_H */