static void reset_release_wait(void) { int gpio; uint32 gpiomask; int i=0; if ((gpio = nvram_resetgpio_init ((void *)sih)) < 0) return; /* Reset button is active low */ gpiomask = (uint32)1 << gpio; while (1) { if ((i%100000) < 30000) { LEDON(); } else { LEDOFF(); } i++; if (i==0xffffff) { i = 0; } if (si_gpioin(sih) & gpiomask) { OSL_DELAY(RESET_DEBOUNCE_TIME); if (si_gpioin(sih) & gpiomask) break; } } }
static ssize_t gpio_read(struct file *file, char *buf, size_t count, loff_t *ppos) { u32 val; switch (MINOR(file->f_dentry->d_inode->i_rdev)) { case 0: val = si_gpioin(gpio_sih); break; case 1: val = si_gpioout(gpio_sih, 0, 0, GPIO_APP_PRIORITY); break; case 2: val = si_gpioouten(gpio_sih, 0, 0, GPIO_APP_PRIORITY); break; case 3: val = si_gpiocontrol(gpio_sih, 0, 0, GPIO_APP_PRIORITY); break; default: return -ENODEV; } if (put_user(val, (u32 *) buf)) return -EFAULT; return sizeof(val); }
/* for driver-call usage */ uint32 _gpio_ctrl(unsigned int cmd, uint32 mask, uint32 val) { struct gpio_ioctl gpioioc; unsigned long flags; gpioioc.mask = mask; gpioioc.val = val; switch (cmd) { case GPIO_IOC_RESERVE: gpioioc.val = si_gpioreserve(gpio_sih, gpioioc.mask, GPIO_APP_PRIORITY); break; case GPIO_IOC_RELEASE: gpioioc.val = si_gpiorelease(gpio_sih, gpioioc.mask, GPIO_APP_PRIORITY); break; case GPIO_IOC_OUT: gpioioc.val = si_gpioout(gpio_sih, gpioioc.mask, gpioioc.val, GPIO_APP_PRIORITY); break; case GPIO_IOC_OUTEN: gpioioc.val = si_gpioouten(gpio_sih, gpioioc.mask, gpioioc.val, GPIO_APP_PRIORITY); break; case GPIO_IOC_IN: gpioioc.val = si_gpioin(gpio_sih); break; default: break; } return gpioioc.val; }
int gpio_get_value(unsigned int gpio) { uint32 get; get = si_gpioin(gpio_sih); get &= (1<<gpio); return (get ? 1 : 0); }
static void detect_turbo_button(void) { int gpio; uint32 gpiomask; if ((gpio = nvram_wsgpio_init ((void *)sih)) < 0) return; /* active low */ gpiomask = (uint32)1 << gpio; #if defined(RTAC68U) || defined(DSLAC68U) // active high if ((si_gpioin(sih) & gpiomask)) #else if (!(si_gpioin(sih) & gpiomask)) #endif cpu_turbo_mode = 1; }
static long gpio_ioctl(struct file *file, unsigned int cmd, unsigned long arg) { #else static int gpio_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg) { #endif /* linux-2.6.22 */ struct gpio_ioctl gpioioc; if (copy_from_user(&gpioioc, (struct gpio_ioctl *)arg, sizeof(struct gpio_ioctl))) return -EFAULT; switch (cmd) { case GPIO_IOC_RESERVE: gpioioc.val = si_gpioreserve(gpio_sih, gpioioc.mask, GPIO_APP_PRIORITY); break; case GPIO_IOC_RELEASE: /* * releasing the gpio doesn't change the current * value on the GPIO last write value * persists till some one overwrites it */ gpioioc.val = si_gpiorelease(gpio_sih, gpioioc.mask, GPIO_APP_PRIORITY); break; case GPIO_IOC_OUT: gpioioc.val = si_gpioout(gpio_sih, gpioioc.mask, gpioioc.val, GPIO_APP_PRIORITY); break; case GPIO_IOC_OUTEN: gpioioc.val = si_gpioouten(gpio_sih, gpioioc.mask, gpioioc.val, GPIO_APP_PRIORITY); break; case GPIO_IOC_IN: gpioioc.val = si_gpioin(gpio_sih); break; default: break; } if (copy_to_user((struct gpio_ioctl *)arg, &gpioioc, sizeof(struct gpio_ioctl))) return -EFAULT; return 0; } static struct file_operations gpio_fops = { owner: THIS_MODULE, open: gpio_open, release: gpio_release, #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 36) unlocked_ioctl: gpio_ioctl #else ioctl: gpio_ioctl #endif };
static void reset_release_wait(void) { int gpio; uint32 gpiomask; if ((gpio = nvram_resetgpio_init ((void *)sih)) < 0) return; /* Reset button is active low */ gpiomask = (uint32)1 << gpio; while (1) { if (si_gpioin(sih) & gpiomask) { OSL_DELAY(RESET_DEBOUNCE_TIME); if (si_gpioin(sih) & gpiomask) break; } } }
int BCMINITFN(nvram_reset)(void *si) { int gpio; uint msec; si_t * sih = (si_t *)si; if ((gpio = nvram_resetgpio_init((void *)sih)) < 0) return FALSE; /* GPIO reset is asserted low */ for (msec = 0; msec < 5000; msec++) { if (si_gpioin(sih) & ((uint32) 1 << gpio)) return FALSE; OSL_DELAY(1000); } nvram_do_reset = TRUE; return TRUE; }
int recovery_button_status(void) { if (sih == NULL) { xprintf("si attach failed\n"); return -1; } if (si_gpioin(sih) & ((uint32) 1 << RECOVERY_GPIO_BUTTON)) { return 0; } else { /* pressed */ return 1; } return 0; }
void si_gpio_handler_process(si_t *sih) { si_info_t *sii; gpioh_item_t *h; uint32 status; uint32 level = si_gpioin(sih); uint32 edge = si_gpioevent(sih, GPIO_REGEVT, 0, 0); sii = SI_INFO(sih); for (h = sii->gpioh_head; h != NULL; h = h->next) { if (h->handler) { status = (h->level ? level : edge); if (status & h->event) h->handler(status, h->arg); } } si_gpioevent(sih, GPIO_REGEVT, edge, edge); /* clear edge-trigger status */ }
static int gpio_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg) { struct gpio_ioctl gpioioc; if (copy_from_user(&gpioioc, (struct gpio_ioctl *)arg, sizeof(struct gpio_ioctl))) return -EFAULT; switch (cmd) { case GPIO_IOC_RESERVE: gpioioc.val = si_gpioreserve(gpio_sih, gpioioc.mask, GPIO_APP_PRIORITY); break; case GPIO_IOC_RELEASE: /* * releasing the gpio doesn't change the current * value on the GPIO last write value * persists till some one overwrites it */ gpioioc.val = si_gpiorelease(gpio_sih, gpioioc.mask, GPIO_APP_PRIORITY); break; case GPIO_IOC_OUT: gpioioc.val = si_gpioout(gpio_sih, gpioioc.mask, gpioioc.val, GPIO_APP_PRIORITY); break; case GPIO_IOC_OUTEN: gpioioc.val = si_gpioouten(gpio_sih, gpioioc.mask, gpioioc.val, GPIO_APP_PRIORITY); break; case GPIO_IOC_IN: gpioioc.val = si_gpioin(gpio_sih); break; default: break; } if (copy_to_user((struct gpio_ioctl *)arg, &gpioioc, sizeof(struct gpio_ioctl))) return -EFAULT; return 0; }
static int bcmgpio_ioctl(int gpioreg, unsigned int mask , unsigned int val) { #if defined(__ECOS) int value; switch (gpioreg) { case BCMGPIO_REG_IN: value = si_gpioin(gpio_sih); break; case BCMGPIO_REG_OUT: value = si_gpioout(gpio_sih, mask, val,GPIO_APP_PRIORITY); break; case BCMGPIO_REG_OUTEN: value = si_gpioouten(gpio_sih, mask, val,GPIO_APP_PRIORITY); break; case BCMGPIO_REG_RESERVE: value = si_gpioreserve(gpio_sih, mask, GPIO_APP_PRIORITY); break; case BCMGPIO_REG_RELEASE: /* * releasing the gpio doesn't change the current * value on the GPIO last write value * persists till some one overwrites it */ value = si_gpiorelease(gpio_sih, mask, GPIO_APP_PRIORITY); break; default: GPIO_ERROR ("invalid gpioreg %d\n", gpioreg); value = -1; break; } return value; #else struct gpio_ioctl gpio; int type; gpio.val = val; gpio.mask = mask; switch (gpioreg) { case BCMGPIO_REG_IN: type = GPIO_IOC_IN; break; case BCMGPIO_REG_OUT: type = GPIO_IOC_OUT; break; case BCMGPIO_REG_OUTEN: type = GPIO_IOC_OUTEN; break; case BCMGPIO_REG_RESERVE: type = GPIO_IOC_RESERVE; break; case BCMGPIO_REG_RELEASE: type = GPIO_IOC_RELEASE; break; default: GPIO_ERROR ("invalid gpioreg %d\n", gpioreg); return -1; } if (ioctl(bcmgpio_fd, type, &gpio) < 0) { GPIO_ERROR ("invalid gpioreg %d\n", gpioreg); return -1; } return (gpio.val); #endif }