/* 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_kernel_api(unsigned int cmd, unsigned int mask, unsigned int val) { if (gpio_init_flag != 1) { if (gpio_init() != 0) return -EFAULT; } switch (cmd) { case 0: si_gpioout(gpio_sih, mask, val, GPIO_HI_PRIORITY); break; case 1: si_gpioouten(gpio_sih, mask, val, GPIO_HI_PRIORITY); break; case 3: si_gpioreserve(gpio_sih, mask, GPIO_HI_PRIORITY); break; default: printk("Unknown gpio_kenerl_api command\n"); break; } return 0; }
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 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; }
int gpio_request(unsigned int gpio, const char *label) { int ret; mask |= (1<<gpio); ret = si_gpioreserve(gpio_sih, (1<<gpio), GPIO_APP_PRIORITY); DBG("%s: gpio %d label %s mask 0x%x reserve 0x%x\n", __FUNCTION__, gpio, label, mask, ret); ret = si_gpiocontrol(gpio_sih, (1<<gpio), 0, GPIO_APP_PRIORITY); DBG("%s: si_gpiocontrol 0x%x\n", __FUNCTION__, ret); /* clear pulldown */ ret = si_gpiopull(gpio_sih, 1/*pulldown*/, (1<<gpio), 0); DBG("%s: si_gpiopull (down) 0x%x\n", __FUNCTION__, ret); /* Set pullup */ ret = si_gpiopull(gpio_sih, 0/*pullup*/, (1<<gpio), (1<<gpio)); DBG("%s: si_gpiopull (up) 0x%x\n", __FUNCTION__, ret); return 0; }
static int __init gpio_init(void) { int i; if (!(gpio_sih = si_kattach(SI_OSH))) return -ENODEV; si_gpiosetcore(gpio_sih); if ((gpio_major = register_chrdev(127, "gpio", &gpio_fops)) < 0) { return gpio_major; } // devfs_mk_cdev(MKDEV(gpio_major, 0), S_IFCHR | S_IRUGO | S_IWUGO, "gpio"); // devfs_mk_dir("gpio"); gpio_class = class_create(THIS_MODULE, "gpio"); for (i = 0; i < ARRAYSIZE(gpio_file); i++) { // register_chrdev(MKDEV(127, i), gpio_file[i].name, &gpio_fops); class_device_create(gpio_class, NULL, MKDEV(127, i), NULL, gpio_file[i].name); // printk("gpio dev %d created\n",dev); // devfs_mk_cdev(MKDEV(127, i), S_IFCHR | S_IRUGO | S_IWUGO, gpio_file[i].name); } gpio_init_flag=1; int gpios = 0; if (iswrt350n) { printk(KERN_EMERG "WRT350N GPIO Init\n"); /* For WRT350N USB LED control */ si_gpioreserve(gpio_sih, 0x400, GPIO_HI_PRIORITY); si_gpioouten(gpio_sih, 0x400, 0x400, GPIO_HI_PRIORITY); si_gpioreserve(gpio_sih, 0x800, GPIO_HI_PRIORITY); si_gpioouten(gpio_sih, 0x800, 0x800, GPIO_HI_PRIORITY); //if (nvram_match("disabled_5397", "1")) { // printk("5397 switch GPIO-Reset \n"); //} USB_SET_LED(USB_DISCONNECT); //2005-02-24 by kanki for USB LED } if (iswrt350n) { si_gpioreserve(gpio_sih, 0x4, GPIO_HI_PRIORITY); si_gpioouten(gpio_sih, 0x4, 0x4, GPIO_HI_PRIORITY); si_gpioout(gpio_sih, 0x4, 0x4, GPIO_HI_PRIORITY); } uint boardnum = bcm_strtoul( nvram_safe_get( "boardnum" ), NULL, 0 ); gpios = 1<<0 | 1<<1 | 1<<2 | 1<<3 | 1<<4 | 1<<5 | 1<<6 | 1<<7 | 1<<8 | 1<<9 | 1<<10 | 1<<11; if ((boardnum == 1 || boardnum == 3500) && nvram_match("boardtype", "0x04CF") && (nvram_match("boardrev", "0x1213") || nvram_match("boardrev", "02"))) { printk(KERN_EMERG "WNR3500V2 GPIO Init\n"); gpios = 1 << 1 | 1 << 2 | 1 << 3 | 1 << 7; } if ((boardnum == 42 || boardnum == 66) && nvram_match("boardtype", "0x04EF") && (nvram_match("boardrev", "0x1304") || nvram_match("boardrev", "0x1305") || nvram_match("boardrev", "0x1307"))) { printk(KERN_EMERG "WRT320N/E2000 GPIO Init\n"); gpios = 1 << 2 | 1 << 3 | 1 << 4; } if (boardnum == 42 && ((nvram_match("boot_hw_model", "WRT160N") && nvram_match("boot_hw_ver", "3.0")) || (nvram_match("boot_hw_model", "M10") && nvram_match("boot_hw_ver", "1.0")) || (nvram_match("boot_hw_model", "E100") && nvram_match("boot_hw_ver", "1.0")) ) ) { printk(KERN_EMERG "WRT160Nv3/M10/E1000 GPIO Init\n"); gpios = 1 << 1 | 1 << 2 | 1 << 4; } if (boardnum == 42 && ((nvram_match("boot_hw_model", "WRT310N") && nvram_match("boot_hw_ver", "2.0")) || (nvram_match("boot_hw_model", "M20") && nvram_match("boot_hw_ver", "1.0")) ) ) { printk(KERN_EMERG "WRT310Nv2/M20 GPIO Init\n"); gpios = 1 << 1 | 1 << 2 | 1 << 4; } if (nvram_match("boardnum", "00") && nvram_match("boardrev", "0x11") && nvram_match("boardtype", "0x048e") && (nvram_match("melco_id", "32093") || nvram_match("melco_id", "32064"))) { printk(KERN_EMERG "WHR-G125 / WHR-HP-G125 GPIO Init\n"); gpios = 1 << 1 | 1 << 6 | 1 << 7; } if (nvram_match("boardnum", "00") && nvram_match("boardrev", "0x13") && nvram_match("boardtype", "0x467")) { printk(KERN_EMERG "WHR-G54S / WHR-HP-G54 GPIO Init\n"); gpios = 1 << 1 | 1 << 6 | 1 << 7; } if (nvram_match("boardtype", "0x04cf") && (nvram_match("boot_hw_model", "WRT610N") || nvram_match("boot_hw_model", "E300"))) { printk(KERN_EMERG "WRT610Nv2/E3000 GPIO Init\n"); gpios = 1 << 0 | 1 << 3 | 1 << 5 | 1 << 7; } if (boardnum == 42 && nvram_match("boardrev", "0x10") && (nvram_match("boardtype", "0x0467") || nvram_match("boardtype", "0x0708") || nvram_match("boardtype", "0x0101"))) { printk(KERN_EMERG "WRT54G/GS/GL/TM GPIO Init\n"); gpios = 1 << 1 | 1 << 2 | 1 << 3 | 1 << 4 | 1 << 7; } if (boardnum == 45 && nvram_match("boardrev", "0x1402") && nvram_match("boardtype", "0x04EC")) { printk(KERN_EMERG "RT-N10 GPIO Init\n"); gpios = 1 << 1; } if (boardnum == 45 && nvram_match("boardrev", "0x1102") && nvram_match("boardtype", "0x0550")) { printk(KERN_EMERG "RT-N10U GPIO Init\n"); gpios = 1 << 5; } if (boardnum == 45 && nvram_match("boardrev", "0x1153") && nvram_match("boardtype", "0x058e")) { printk(KERN_EMERG "RT-N10+ D1 GPIO INIT\n"); gpios = 1 << 6 | 1 << 7 | 1 << 21 | 1 << 20; } if (boardnum == 1 && nvram_match("boardtype", "0xE4CD") && nvram_match("boardrev", "0x1700")) { printk(KERN_EMERG "WNR2000v2 GPIO Init\n"); gpios = 1 << 2 | 1 << 6 | 1 << 7 | 1 << 8; } if (boardnum == 45 && nvram_match("boardrev", "0x1201") && nvram_match("boardtype", "0x04CD")) { printk(KERN_EMERG "RT-N12 GPIO Init\n"); gpios = 1 << 0 | 1 << 2; } if (boardnum == 45 && nvram_match("boardrev", "0x1218") && nvram_match("boardtype", "0x04cf")) { printk(KERN_EMERG "RT-N16 GPIO Init\n"); gpios = 1 << 1; } if (boardnum == 1 && nvram_match("boardrev", "0x23") && nvram_match("boardtype", "0x0472")) { if (nvram_match("cardbus", "1")) { printk(KERN_EMERG "WNR324v2 GPIO Init\n"); gpios = 1 << 2 | 1 << 3 | 1 << 7; } else { printk(KERN_EMERG "WNDR3300 GPIO Init\n"); gpios = 1 << 5 | 1 << 7; } } if (nvram_match("boardnum", "00") && nvram_match("boardtype", "0x0101") && nvram_match("boardrev", "0x10")) { printk(KERN_EMERG "WBR2-G54(S) GPIO Init\n"); gpios = 1 << 1 | 1 << 6; } if (nvram_match("boardtype", "0xd4cf") && nvram_match("boardrev", "0x1204")) { printk(KERN_EMERG "F7D4301v1 GPIO Init\n"); gpios = 1 << 10 | 1 << 11 | 1 << 13; } if (nvram_match("boardtype", "0xa4cf") && (nvram_match("boardrev", "0x1100") || nvram_match("boardrev", "0x1102"))) { printk(KERN_EMERG "F7D3301v1/3302v1/4302v1 - F5D8235v3 GPIO Init\n"); gpios = 1 << 10 | 1 << 11 | 1 << 13; } if (nvram_match("boot_hw_model", "E1000") && (nvram_match("boot_hw_ver", "2.0") || nvram_match("boot_hw_ver", "2.1"))) { printk(KERN_EMERG "E1000v2/v21 GPIO Init\n"); gpios = 1 << 6 | 1 << 7 | 1 << 8; } if (nvram_match("boot_hw_model", "E4200") && nvram_match("boot_hw_ver", "1.0")) { printk(KERN_EMERG "E4200 GPIO Init\n"); gpios = 1 << 3 | 1 << 5; } if (nvram_match("boardnum", "01") && nvram_match("boardtype", "0xb4cf") && nvram_match("boardrev", "0x1100")) { printk(KERN_EMERG "WNDR3400 GPIO Init\n"); gpios = 1 << 0 | 1 << 1 | 1 << 2 | 1 << 3 | 1 << 7; } if (nvram_match("boardnum", "01") && nvram_match("boardtype", "0xF52C") && nvram_match("boardrev", "0x1101")) { printk(KERN_EMERG "WNDR4000 GPIO Init\n"); gpios = 1 << 0 | 1 << 6 | 1 << 7; } /*if (iswrt300n11) { printk(KERN_EMERG "WRT300N v1.1 GPIO Init\n"); int reset = 1 << 8; sb_gpioout(gpio_sbh, reset, 0, GPIO_DRV_PRIORITY); sb_gpioouten(gpio_sbh, reset, reset, GPIO_DRV_PRIORITY); bcm_mdelay(50); sb_gpioout(gpio_sbh, reset, reset, GPIO_DRV_PRIORITY); bcm_mdelay(20); }*/ for (i = 0; i < 16; i++) { if (gpios&1) { si_gpioreserve(gpio_sih, 1 << i, GPIO_APP_PRIORITY); } gpios>>=1; } 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 }
static int __init gpio_init(void) { int i; int gpios = 0; printk(KERN_INFO "init gpio code\n"); if (!(gpio_sih = si_kattach(SI_OSH))) return -ENODEV; si_gpiosetcore(gpio_sih); set_hc595_core(gpio_sih); if ((gpio_major = register_chrdev(127, "gpio", &gpio_fops)) < 0) { return gpio_major; } gpio_class = class_create(THIS_MODULE, "gpio"); for (i = 0; i < ARRAYSIZE(gpio_file); i++) { device_create(gpio_class, NULL, MKDEV(127, i), NULL, gpio_file[i].name); } uint boardnum = bcm_strtoul(nvram_safe_get("boardnum"), NULL, 0); if (boardnum == 00 && nvram_match("boardtype", "0xF646") && nvram_match("boardrev", "0x1100") && nvram_match("melco_id", "RD_BB12068")) { printk(KERN_EMERG "Buffalo WZR-1750DHP\n"); isbuffalo = 1; set_hc595_reset(); gpio_init_flag = 1; return 0; } if (boardnum == 00 && nvram_match("boardtype", "0x0665") && nvram_match("boardrev", "0x1103") && nvram_match("melco_id", "RD_BB13049")) { printk(KERN_EMERG "Buffalo WXR-1900DHP\n"); isbuffalowxr = 1; gpio_init_flag = 1; return 0; } if ((!strncmp(nvram_safe_get("boardnum"),"2013",4) || !strncmp(nvram_safe_get("boardnum"),"2014",4)) && nvram_match("boardtype", "0x0646") && nvram_match("boardrev", "0x1110") && nvram_match("0:rxchain", "7")) { printk(KERN_EMERG "Buffalo WZR-900DHP\n"); isbuffalo = 1; set_hc595_reset(); gpio_init_flag = 1; return 0; } if ((!strncmp(nvram_safe_get("boardnum"),"2013",4) || !strncmp(nvram_safe_get("boardnum"),"2014",4)) && nvram_match("boardtype", "0x0646") && nvram_match("boardrev", "0x1110") && nvram_match("0:rxchain", "3")) { printk(KERN_EMERG "Buffalo WZR-600DHP2\n"); isbuffalo = 1; set_hc595_reset(); gpio_init_flag = 1; return 0; } if ((boardnum == 0) && nvram_match("boardtype", "0x0646") && (nvram_match("boardrev", "0x1100"))) { printk(KERN_EMERG "Asus-RT-AC56U init\n"); isac66 = 1; } if (nvram_match("model","RT-AC68U")) { printk(KERN_EMERG "Asus-RT-AC68U init\n"); isac68 = 1; } else if ((boardnum != 24) && nvram_match("boardtype", "0x0646") && (nvram_match("boardrev", "0x1100"))) { printk(KERN_EMERG "Asus-RT-AC68U init\n"); isac68 = 1; } if ((boardnum == 24) && nvram_match("boardtype", "0x0646") && nvram_match("boardrev", "0x1110") && !nvram_match("gpio6", "wps_led")) { printk(KERN_EMERG "DLink DIR-868 init\n"); isac66 = 1; } if ((boardnum == 679) && nvram_match("boardtype", "0x0646") && (nvram_match("boardrev", "0x1110"))) { printk(KERN_EMERG "Netgear AC1450/R6250/R6300v2/EX6200 init\n"); gpios = 1<<0 | 1<<1 | 1<<2 | 1<<3 | 1<<4 | 1<<5 | 1<<6 | 1<<7 | 1<<8 | 1<<9 | 1<<10 | 1<<11 | 1<<15; } if ((boardnum == 32) && nvram_match("boardtype", "0x0665") && (nvram_match("boardrev", "0x1301"))) { printk(KERN_EMERG "Netgear R7000 init\n"); gpios = 1<<0 | 1<<1 | 1<<2 | 1<<3 | 1<<4 | 1<<5 | 1<<6 | 1<<7 | 1<<8 | 1<<9 | 1<<10 | 1<<11 | 1<<15; } if ((boardnum == 32) && nvram_match("boardtype", "0x0665") && (nvram_match("boardrev", "0x1101"))) { printk(KERN_EMERG "Netgear R8000 init\n"); gpios = 1<<0 | 1<<1 | 1<<2 | 1<<3 | 1<<4 | 1<<5 | 1<<6 | 1<<7 | 1<<8 | 1<<9 | 1<<10 | 1<<11 | 1<<15; } for (i = 0; i < 16; i++) { if (gpios&1) { si_gpioreserve(gpio_sih, 1 << i, GPIO_APP_PRIORITY); } } gpio_init_flag = 1; return 0; }