From: Kees Jongenburger Date: Fri, 29 Nov 2013 13:27:03 +0000 (+0100) Subject: arm:replace ifdef's by runtime checks. X-Git-Tag: v3.3.0~664 X-Git-Url: http://zhaoyanbai.com/repos/%22http:/www.isc.org/icons/index.css?a=commitdiff_plain;h=refs%2Fchanges%2F81%2F1181%2F4;p=minix.git arm:replace ifdef's by runtime checks. Change-Id: Iff966f2214e2d8bb6b72dd0a119085709f2d4a9c --- diff --git a/drivers/gpio/gpio.c b/drivers/gpio/gpio.c index a6924edb6..58cd06b49 100644 --- a/drivers/gpio/gpio.c +++ b/drivers/gpio/gpio.c @@ -11,6 +11,8 @@ #include #include #include +#include +#include /* system headers */ #include @@ -165,43 +167,43 @@ init_hook(void) log_warn(&log, "Failed to init gpio driver\n"); } -#ifdef AM335X + struct machine machine ; + sys_getmachine(&machine); - /* Export GPIO3_19 (P9-27 on BBB) output as LCD_EN */ + if (BOARD_IS_BBXM(machine.board_id)){ + add_gpio_inode("USR0", 149, GPIO_MODE_OUTPUT); + add_gpio_inode("USR1", 150, GPIO_MODE_OUTPUT); + add_gpio_inode("Button", 4, GPIO_MODE_INPUT); - sys_padconf(CONTROL_CONF_MCASP0_FSR, 0xffffffff, - (CONTROL_CONF_PUTYPESEL | CONTROL_CONF_MUXMODE(7))); + /* configure GPIO_144 to be exported */ + sys_padconf(CONTROL_PADCONF_UART2_CTS, 0x0000ffff, + PADCONF_MUXMODE(4) | PADCONF_PULL_MODE_PD_EN | + PADCONF_INPUT_ENABLE(1)); + sys_padconf(CONTROL_PADCONF_MMC2_DAT6, 0xffff0000, + (PADCONF_MUXMODE(4) | PADCONF_PULL_MODE_PD_EN | + PADCONF_INPUT_ENABLE(1)) << 16); - add_gpio_inode("LCD_EN", (32 * 3) + 19, GPIO_MODE_OUTPUT); + /* Added for demo purposes */ + add_gpio_inode("BigRedButton", 144, GPIO_MODE_INPUT); + add_gpio_inode("BigRedButtonLed", 139, GPIO_MODE_OUTPUT); + } else if ( BOARD_IS_BB(machine.board_id)){ - /* Export GPIO1_17 (P9-23 on BBB) input as RIGHT */ + /* Export GPIO3_19 (P9-27 on BBB) output as LCD_EN */ - /* assumes external pull-up resistor (10K) */ - sys_padconf(CONTROL_CONF_SPI0_D0, 0xffffffff, (CONTROL_CONF_RXACTIVE | - CONTROL_CONF_PUDEN | CONTROL_CONF_MUXMODE(7))); - - add_gpio_inode("RIGHT", (32 * 1) + 17, GPIO_MODE_INPUT); + sys_padconf(CONTROL_CONF_MCASP0_FSR, 0xffffffff, + (CONTROL_CONF_PUTYPESEL | CONTROL_CONF_MUXMODE(7))); -#elif DM37XX + add_gpio_inode("LCD_EN", (32 * 3) + 19, GPIO_MODE_OUTPUT); - add_gpio_inode("USR0", 149, GPIO_MODE_OUTPUT); - add_gpio_inode("USR1", 150, GPIO_MODE_OUTPUT); - add_gpio_inode("Button", 4, GPIO_MODE_INPUT); + /* Export GPIO1_17 (P9-23 on BBB) input as RIGHT */ - /* configure GPIO_144 to be exported */ - sys_padconf(CONTROL_PADCONF_UART2_CTS, 0x0000ffff, - PADCONF_MUXMODE(4) | PADCONF_PULL_MODE_PD_EN | - PADCONF_INPUT_ENABLE(1)); - sys_padconf(CONTROL_PADCONF_MMC2_DAT6, 0xffff0000, - (PADCONF_MUXMODE(4) | PADCONF_PULL_MODE_PD_EN | - PADCONF_INPUT_ENABLE(1)) << 16); - - /* Added for demo purposes */ - add_gpio_inode("BigRedButton", 144, GPIO_MODE_INPUT); - add_gpio_inode("BigRedButtonLed", 139, GPIO_MODE_OUTPUT); - -#endif /* DM37XX */ + /* assumes external pull-up resistor (10K) */ + sys_padconf(CONTROL_CONF_SPI0_D0, 0xffffffff, (CONTROL_CONF_RXACTIVE | + CONTROL_CONF_PUDEN | CONTROL_CONF_MUXMODE(7))); + + add_gpio_inode("RIGHT", (32 * 1) + 17, GPIO_MODE_INPUT); + } } static int diff --git a/drivers/i2c/i2c.c b/drivers/i2c/i2c.c index 36d8af324..7f5c34cd5 100644 --- a/drivers/i2c/i2c.c +++ b/drivers/i2c/i2c.c @@ -9,6 +9,7 @@ #include #include #include +#include /* system headers */ #include @@ -455,20 +456,23 @@ sef_cb_init(int type, sef_init_info_t * UNUSED(info)) { int r; char regex[DS_MAX_KEYLEN]; + struct machine machine; + sys_getmachine(&machine); if (type != SEF_INIT_FRESH) { /* Restore a prior state. */ lu_state_restore(); } -#if defined(AM335X) || defined(DM37XX) - /* Set callback and initialize the bus */ - r = omap_interface_setup(&process, i2c_bus_id); - if (r != OK) { - return r; + + if (BOARD_IS_BBXM(machine.board_id) || BOARD_IS_BB(machine.board_id)){ + /* Set callback and initialize the bus */ + r = omap_interface_setup(&process, i2c_bus_id); + if (r != OK) { + return r; + } + } else { + return ENODEV; } -#else -#error /* Unknown SoC or bad configuration */ -#endif /* Announce we are up when necessary. */ if (type != SEF_INIT_LU) { diff --git a/drivers/mmc/mmchost_mmchs.c b/drivers/mmc/mmchost_mmchs.c index bc1f5eadd..e3e4604fe 100644 --- a/drivers/mmc/mmchost_mmchs.c +++ b/drivers/mmc/mmchost_mmchs.c @@ -5,6 +5,8 @@ #include #include #include +#include +#include #include #include @@ -1233,13 +1235,18 @@ host_initialize_host_structure_mmchs(struct mmc_host *host) { /* Initialize the basic data structures host slots and cards */ int i; + mmchs = NULL; -#ifdef AM335X - mmchs = &bone_sdcard; -#endif -#ifdef DM37XX - mmchs = &bbxm_sdcard; -#endif + struct machine machine ; + sys_getmachine(&machine); + + if (BOARD_IS_BBXM(machine.board_id)){ + mmchs = &bbxm_sdcard; + } else if ( BOARD_IS_BB(machine.board_id)){ + mmchs = &bone_sdcard; + } + + assert(mmchs); host->host_set_instance = mmchs_host_set_instance; host->host_init = mmchs_host_init; host->set_log_level = mmchs_set_log_level; diff --git a/drivers/readclock/arch/earm/arch_readclock.c b/drivers/readclock/arch/earm/arch_readclock.c index f0b45fa18..bc535bd5b 100644 --- a/drivers/readclock/arch/earm/arch_readclock.c +++ b/drivers/readclock/arch/earm/arch_readclock.c @@ -1,6 +1,8 @@ #include #include #include +#include +#include #include #include @@ -20,22 +22,24 @@ int arch_setup(struct rtc *r) { -#ifdef AM335X - r->init = omap_rtc_init; - r->get_time = omap_rtc_get_time; - r->set_time = omap_rtc_set_time; - r->pwr_off = omap_rtc_pwr_off; - r->exit = omap_rtc_exit; - return OK; -#elif DM37XX - fwd_set_label("tps65950.1.48"); - r->init = fwd_init; - r->get_time = fwd_get_time; - r->set_time = fwd_set_time; - r->pwr_off = fwd_pwr_off; - r->exit = fwd_exit; - return OK; -#else + struct machine machine ; + sys_getmachine(&machine); + + if (BOARD_IS_BBXM(machine.board_id)){ + fwd_set_label("tps65950.1.48"); + r->init = fwd_init; + r->get_time = fwd_get_time; + r->set_time = fwd_set_time; + r->pwr_off = fwd_pwr_off; + r->exit = fwd_exit; + return OK; + } else if ( BOARD_IS_BB(machine.board_id)){ + r->init = omap_rtc_init; + r->get_time = omap_rtc_get_time; + r->set_time = omap_rtc_set_time; + r->pwr_off = omap_rtc_pwr_off; + r->exit = omap_rtc_exit; + return OK; + } return ENOSYS; -#endif } diff --git a/drivers/tty/arch/earm/rs232.c b/drivers/tty/arch/earm/rs232.c index 432d2d9cf..100f9af57 100644 --- a/drivers/tty/arch/earm/rs232.c +++ b/drivers/tty/arch/earm/rs232.c @@ -1,6 +1,8 @@ #include #include #include +#include +#include #include #include #include @@ -118,24 +120,20 @@ typedef struct uart_port { int irq; } uart_port_t; -#ifdef DM37XX /* OMAP3 UART base addresses. */ -static uart_port_t omap3[] = { +static uart_port_t dm37xx_ports[] = { { OMAP3_UART1_BASE, 72}, /* UART1 */ { OMAP3_UART2_BASE, 73}, /* UART2 */ { OMAP3_UART3_BASE, 74}, /* UART3 */ { 0, 0 } }; -#endif -#ifdef AM335X -static uart_port_t omap3[] = { +static uart_port_t am335x_ports[] = { { 0x44E09000 , 72 }, /* UART0 */ { 0, 0 }, { 0, 0 }, { 0, 0 } }; -#endif static int rs_write(tty_t *tp, int try); @@ -482,6 +480,7 @@ rs_init(tty_t *tp) uart_port_t this_omap3; char l[10]; struct minix_mem_range mr; + struct machine machine; /* Associate RS232 and TTY structures. */ line = tp - &tty_table[NR_CONS]; @@ -502,7 +501,15 @@ rs_init(tty_t *tp) /* Set up input queue. */ rs->ihead = rs->itail = rs->ibuf; - this_omap3 = omap3[line]; + sys_getmachine(&machine); + + if (BOARD_IS_BBXM(machine.board_id)){ + this_omap3 = dm37xx_ports[line]; + } else if (BOARD_IS_BB(machine.board_id)){ + this_omap3 = am335x_ports[line]; + } else { + return; + } if (this_omap3.base_addr == 0) return; /* Configure memory access */ diff --git a/lib/libclkconf/clkconf.c b/lib/libclkconf/clkconf.c index 53f89f44d..86c3e1201 100644 --- a/lib/libclkconf/clkconf.c +++ b/lib/libclkconf/clkconf.c @@ -4,6 +4,8 @@ #include #include #include +#include +#include /* system headers */ #include @@ -24,11 +26,8 @@ static struct log log = { .log_func = default_log }; -#ifdef DM37XX -#define CM_BASE 0x48004000 -#elif AM335X -#define CM_BASE 0x44E00000 -#endif +#define DM37XX_CM_BASE 0x48004000 +#define AM335X_CM_BASE 0x44E00000 static u32_t base = 0; static u32_t use_count = 0; @@ -37,6 +36,10 @@ int clkconf_init() { use_count++; + struct machine machine; + sys_getmachine(&machine); + u32_t cm_base = 0; + if (base != 0) { /* when used in a library we can't guaranty we only call this @@ -44,16 +47,22 @@ clkconf_init() log_trace(&log, "Called %d times\n", use_count); return OK; } + + if (BOARD_IS_BBXM(machine.board_id)){ + cm_base = DM37XX_CM_BASE; + } else if (BOARD_IS_BB(machine.board_id)){ + cm_base = AM335X_CM_BASE; + } struct minix_mem_range mr; - mr.mr_base = CM_BASE; - mr.mr_limit = CM_BASE + 0x1000; + mr.mr_base = cm_base; + mr.mr_limit = cm_base + 0x1000; if (sys_privctl(SELF, SYS_PRIV_ADD_MEM, &mr) != 0) { log_warn(&log, "Unable to request permission to map memory\n"); return EPERM; } - base = (uint32_t) vm_map_phys(SELF, (void *) CM_BASE, 0x1000); + base = (uint32_t) vm_map_phys(SELF, (void *) cm_base, 0x1000); if (base == (uint32_t) MAP_FAILED) { log_warn(&log, "Unable to map GPIO memory\n"); diff --git a/lib/libgpio/gpio_omap.c b/lib/libgpio/gpio_omap.c index b51e60b9a..41e1c36eb 100644 --- a/lib/libgpio/gpio_omap.c +++ b/lib/libgpio/gpio_omap.c @@ -6,6 +6,7 @@ #include #include #include +#include /* system headers */ #include @@ -64,8 +65,9 @@ struct omap_gpio_bank uint32_t inter_values; /* values when the interrupt was called */ }; -static struct omap_gpio_bank omap_gpio_banks[] = { -#ifdef AM335X +static struct omap_gpio_bank *omap_gpio_banks; + +static struct omap_gpio_bank am335x_gpio_banks[] = { { .name = "GPIO0", .register_address = AM335X_GPIO0_BASE, @@ -106,7 +108,10 @@ static struct omap_gpio_bank omap_gpio_banks[] = { .irq_hook_id = AM335X_GPIO3A_IRQ_HOOK_ID, }, -#elif DM37XX + {NULL, 0, 0, 0, 0, 0, 0, 0 } +}; + +static struct omap_gpio_bank dm37xx_gpio_banks[] = { { .name = "GPIO1", .register_address = DM37XX_GPIO1_BASE, @@ -161,11 +166,10 @@ static struct omap_gpio_bank omap_gpio_banks[] = { .irq_id = DM37XX_GPIO6_IRQ_HOOK_ID, .irq_hook_id = DM37XX_GPIO6_IRQ_HOOK_ID, }, -#endif /* DM37XX */ {NULL, 0, 0, 0, 0, 0, 0, 0 } }; -#define NBANKS ((int)((sizeof(omap_gpio_banks)/sizeof(omap_gpio_banks[0])) - 1)) +static int nbanks; /* number of banks */ /* * Defines the set of registers. There is a lot of commonality between the @@ -213,17 +217,14 @@ gpio_omap_regs_t gpio_omap_am335x = { .SETDATAOUT = AM335X_GPIO_SETDATAOUT }; -#ifdef AM335X -static gpio_omap_regs_t *regs = &gpio_omap_am335x; -#elif DM37XX -static gpio_omap_regs_t *regs = &gpio_omap_dm37xx; -#endif /* DM37XX */ +static gpio_omap_regs_t *regs; + static struct omap_gpio_bank * omap_gpio_bank_get(int gpio_nr) { struct omap_gpio_bank *bank; - assert(gpio_nr >= 0 && gpio_nr <= 32 * NBANKS); + assert(gpio_nr >= 0 && gpio_nr <= 32 * nbanks); bank = &omap_gpio_banks[gpio_nr / 32]; return bank; } @@ -233,7 +234,7 @@ omap_gpio_claim(char *owner, int nr, struct gpio **gpio) { log_trace(&log, "%s s claiming %d\n", owner, nr); - if (nr < 0 && nr >= 32 * NBANKS) { + if (nr < 0 && nr >= 32 * nbanks) { log_warn(&log, "%s is claiming unknown GPIO number %d\n", owner, nr); return EINVAL; @@ -284,7 +285,7 @@ omap_gpio_set(struct gpio *gpio, int value) { struct omap_gpio_bank *bank; assert(gpio != NULL); - assert(gpio->nr >= 0 && gpio->nr <= 32 * NBANKS); + assert(gpio->nr >= 0 && gpio->nr <= 32 * nbanks); bank = omap_gpio_bank_get(gpio->nr); if (value == 1) { @@ -302,7 +303,7 @@ omap_gpio_read(struct gpio *gpio, int *value) { struct omap_gpio_bank *bank; assert(gpio != NULL); - assert(gpio->nr >= 0 && gpio->nr <= 32 * NBANKS); + assert(gpio->nr >= 0 && gpio->nr <= 32 * nbanks); bank = omap_gpio_bank_get(gpio->nr); log_trace(&log, "mode=%d OU/IN 0x%08x 0x%08x\n", gpio->mode, @@ -327,7 +328,7 @@ omap_gpio_intr_read(struct gpio *gpio, int *value) { struct omap_gpio_bank *bank; assert(gpio != NULL); - assert(gpio->nr >= 0 && gpio->nr <= 32 * NBANKS); + assert(gpio->nr >= 0 && gpio->nr <= 32 * nbanks); bank = omap_gpio_bank_get(gpio->nr); /* TODO: check if interrupt where enabled?? */ @@ -385,9 +386,22 @@ omap_gpio_init(struct gpio_driver *gpdrv) int i; struct minix_mem_range mr; struct omap_gpio_bank *bank; + struct machine machine; + sys_getmachine(&machine); + + nbanks =0; + omap_gpio_banks = NULL; + if (BOARD_IS_BBXM(machine.board_id)){ + omap_gpio_banks = dm37xx_gpio_banks; + regs = &gpio_omap_dm37xx; + } else if (BOARD_IS_BB(machine.board_id)){ + omap_gpio_banks = am335x_gpio_banks; + regs = &gpio_omap_am335x; + } bank = &omap_gpio_banks[0]; for (i = 0; omap_gpio_banks[i].name != NULL; i++) { + nbanks++; bank = &omap_gpio_banks[i]; mr.mr_base = bank->register_address; mr.mr_limit = bank->register_address + 0x400; @@ -410,15 +424,19 @@ omap_gpio_init(struct gpio_driver *gpdrv) revision = 0; revision = read32(bank->base_address + regs->REVISION); + unsigned int expected_major = 0; + unsigned int expected_minor = 0; + if (BOARD_IS_BBXM(machine.board_id)){ + expected_major = 2; + expected_minor = 5; + } else if (BOARD_IS_BB(machine.board_id)){ + expected_major = 0; + expected_minor = 1; + } /* test if we can access it */ if ( -#ifdef AM335X - AM335X_GPIO_REVISION_MAJOR(revision) != 0 - || AM335X_GPIO_REVISION_MINOR(revision) != 1 -#elif DM37XX - DM37XX_GPIO_REVISION_MAJOR(revision) != 2 - || DM37XX_GPIO_REVISION_MINOR(revision) != 5 -#endif /* DM37XX */ + AM335X_GPIO_REVISION_MAJOR(revision) != expected_major + || AM335X_GPIO_REVISION_MINOR(revision) != expected_minor ) { log_warn(&log, "Failed to read the revision of GPIO bank %s.. disabling\n", @@ -451,13 +469,13 @@ omap_gpio_init(struct gpio_driver *gpdrv) }; clkconf_init(); -#ifdef AM335X - /* Nothing to enable for GPIO on AM335X */ -#elif DM37XX - /* enable the interface and functional clock on GPIO bank 1 */ - clkconf_set(CM_FCLKEN_WKUP, BIT(3), 0xffffffff); - clkconf_set(CM_ICLKEN_WKUP, BIT(3), 0xffffffff); -#endif /* DM37XX */ + + if (BOARD_IS_BBXM(machine.board_id)){ + /* enable the interface and functional clock on GPIO bank 1 , this only + applies to the Beagelboard XM */ + clkconf_set(CM_FCLKEN_WKUP, BIT(3), 0xffffffff); + clkconf_set(CM_ICLKEN_WKUP, BIT(3), 0xffffffff); + } clkconf_release();