int main(int argc, char **argv) { unsigned int gpio; unsigned int old_gpio = -1; unsigned int pin; if (argc != 3) { fprintf(stderr, "%s <poll | enable | disable> <pin>\n", argv[0]); exit(1); } pin = atoi(argv[2]); if (!strcmp(argv[1], "poll")) { while (1) { gpio = get_gpio(pin); if (gpio != old_gpio) fprintf(stdout, "%02X\n", gpio); old_gpio = gpio; } } else if (!strcmp(argv[1], "init")) { gpio = get_gpio(pin); } else if (!strcmp(argv[1], "enable")) { gpio = 1; set_gpio(pin, gpio); } else if (!strcmp(argv[1], "disable")) { gpio = 0; set_gpio(pin, gpio); } return 0; }
static inline char spi_tx_rx( spi_connection_t *sc, char tx ) { /* wait for TX FIFO Level to become 0 */ while( (get_ssp2( sc, SSSR_2 ) & TFL) ) ; /* wait for TX FIFO not to be full */ while( !(get_ssp2( sc, SSSR_2 ) & TNF) ) ; /* turn on Chip Select */ set_gpio( sc, GPCR2, get_gpio( sc, GPCR2 ) | PS11 ); /* write TX to data register */ set_ssp2( sc, SSDR_2, tx ); /* turn off Chip Select */ set_gpio( sc, GPSR2, get_gpio( sc, GPSR2 ) | PS11 ); /* wait for TX FIFO not to be full */ while( !(get_ssp2( sc, SSSR_2 ) & TNF) ) ; /* wait for SSP2 port to become idle or RX FIFO not to be empty */ while( (get_ssp2( sc, SSSR_2 ) & BSY) || !(get_ssp2( sc, SSSR_2 ) & RNE) ) ; /* read RX from data register */ return( (char) get_ssp2( sc, SSDR_2 ) ); }
int getbuttonstate() { #if defined(HAVE_EAP3660) || defined(HAVE_EOC2610) || defined(HAVE_EOC1650) || defined(HAVE_ECB3500) int ret = get_gpio(5); return 1 - ret; #elif defined(HAVE_WRT54G2) int ret = get_gpio(7); return 1 - ret; #elif defined(HAVE_RTG32) int ret = get_gpio(6); return ret; #elif defined(HAVE_EOC5610) int ret = get_gpio(6); return 1 - ret; #elif HAVE_WP54G int ret = get_gpio(4); return ret; #elif HAVE_NP28G int ret = get_gpio(4); return ret; #elif HAVE_WPE53G int ret = get_gpio(6); return ret; #elif HAVE_NP25G int ret = get_gpio(4); return ret; #elif HAVE_OPENRISC int ret = get_gpio(0); return ret; #else int ret = get_gpio(6); return ret; #endif }
scheduling_type_t gpio_handler(void){ // send msg with interrupt regs uint32_t irpts[2]; irpts[0] = get_gpio()->GPEDS0; irpts[1] = get_gpio()->GPEDS1; gpio_ack(); // ipc_kernel_send(irpts, 8, driver_irq_get(DRIVER_GPIO)); return RESCHEDULE; }
int make_ack_get_io_status(u8* ackbuf, u8* cmdbuf) { gpio_status gs=GS_LOW; u8 i=0,j=0; CONFIG_SENSOR config_io_out; make_ack_head( ackbuf, PROTOCOL_ACK_GET_IO_STATUS); config_io_out.num = cmdbuf[4]; ackbuf[4]=config_io_out.num; if (config_io_out.num == 0 || config_io_out.num > IO_OUT_NUM){ sys_log(FUNC, LOG_ERR, "config_io_out.num %d\n", config_io_out.num); return; } for (i=0,j=0; j < config_io_out.num; j++, i+=2){ config_io_out.seq_num[j] = cmdbuf[5+j]; ackbuf[5+i] = config_io_out.seq_num[j]; switch(config_io_out.seq_num[j]){ case 1: get_gpio(OUTPUT_1,&gs); ackbuf[6+i]=(u8)gs; break; case 2: get_gpio(OUTPUT_2, &gs); ackbuf[6+i]=(u8)gs; break; case 3: get_gpio(OUTPUT_3, &gs); ackbuf[6+i]=(u8)gs; break; case 4: get_gpio(OUTPUT_4, &gs); ackbuf[6+i]=(u8)gs; break; default: ackbuf[6+i]=0xff; break; } config_io_out.attr[j] = ackbuf[6+i]; } //sys_log(FUNC, LOG_DBG, "%d %d %x\n", buf[4], _buf[4], gs); ackbuf[5+2*j]=make_crc_num(ackbuf, 5+2*j); return 5+2*j+1; }
/* Copy SPD data for on-board memory */ void mainboard_fill_spd_data(struct pei_data *pei_data) { int spd_bits[3] = { SPD_GPIO_BIT0, SPD_GPIO_BIT1, SPD_GPIO_BIT2 }; int spd_gpio[3]; int spd_index; size_t spd_file_len; char *spd_file; spd_gpio[0] = get_gpio(SPD_GPIO_BIT0); spd_gpio[1] = get_gpio(SPD_GPIO_BIT1); spd_gpio[2] = get_gpio(SPD_GPIO_BIT2); spd_index = spd_gpio[2] << 2 | spd_gpio[1] << 1 | spd_gpio[0]; printk(BIOS_DEBUG, "SPD: index %d (GPIO%d=%d GPIO%d=%d GPIO%d=%d)\n", spd_index, spd_bits[2], spd_gpio[2], spd_bits[1], spd_gpio[1], spd_bits[0], spd_gpio[0]); spd_file = cbfs_boot_map_with_leak("spd.bin", 0xab, &spd_file_len); if (!spd_file) die("SPD data not found."); if (spd_file_len < ((spd_index + 1) * SPD_LEN)) { printk(BIOS_ERR, "SPD index override to 0 - old hardware?\n"); spd_index = 0; } if (spd_file_len < SPD_LEN) die("Missing SPD data."); memcpy(pei_data->spd_data[0][0], spd_file + (spd_index * SPD_LEN), SPD_LEN); /* Index 0-2 are 4GB config with both CH0 and CH1. * Index 4-6 are 2GB config with CH0 only. */ if (spd_index > 3) pei_data->dimm_channel1_disabled = 3; else memcpy(pei_data->spd_data[1][0], spd_file + (spd_index * SPD_LEN), SPD_LEN); /* Make sure a valid SPD was found */ if (pei_data->spd_data[0][0][0] == 0) die("Invalid SPD data."); mainboard_print_spd_info(pei_data->spd_data[0][0]); }
/* Copy SPD data for on-board memory */ void mainboard_fill_spd_data(struct pei_data *pei_data) { int spd_bits[4] = { SPD_GPIO_BIT0, SPD_GPIO_BIT1, SPD_GPIO_BIT2, SPD_GPIO_BIT3 }; int spd_gpio[4]; int spd_index; size_t spd_file_len; char *spd_file; spd_gpio[0] = get_gpio(spd_bits[0]); spd_gpio[1] = get_gpio(spd_bits[1]); spd_gpio[2] = get_gpio(spd_bits[2]); spd_gpio[3] = get_gpio(spd_bits[3]); spd_index = (spd_gpio[3] << 3) | (spd_gpio[2] << 2) | (spd_gpio[1] << 1) | spd_gpio[0]; printk(BIOS_DEBUG, "SPD: index %d (GPIO%d=%d GPIO%d=%d " "GPIO%d=%d GPIO%d=%d)\n", spd_index, spd_bits[3], spd_gpio[3], spd_bits[2], spd_gpio[2], spd_bits[1], spd_gpio[1], spd_bits[0], spd_gpio[0]); spd_file = cbfs_boot_map_with_leak("spd.bin", 0xab, &spd_file_len); if (!spd_file) die("SPD data not found."); if (spd_file_len < ((spd_index + 1) * SPD_LEN)) { printk(BIOS_ERR, "SPD index override to 0 - old hardware?\n"); spd_index = 0; } if (spd_file_len < SPD_LEN) die("Missing SPD data."); /* Assume same memory in both channels */ spd_index *= SPD_LEN; memcpy(pei_data->spd_data[0][0], spd_file + spd_index, SPD_LEN); memcpy(pei_data->spd_data[1][0], spd_file + spd_index, SPD_LEN); /* Make sure a valid SPD was found */ if (pei_data->spd_data[0][0][0] == 0) die("Invalid SPD data."); mainboard_print_spd_info(pei_data->spd_data[0][0]); }
int getbuttonstate() { int ret = get_gpio(232); if (ret == 1) return 0; return 1; }
void init_bootmode_straps(void) { u32 flags = 0; /* Write Protect: GPIO58 = GPIO_SPI_WP, active high */ if (get_gpio(GPIO_SPI_WP)) flags |= (1 << FLAG_SPI_WP); /* Recovery: GPIO12 = RECOVERY_L, active low */ if (!get_gpio(GPIO_REC_MODE)) flags |= (1 << FLAG_REC_MODE); /* Developer: Virtual */ pci_write_config32(PCI_DEV(0, 0x1f, 2), SATA_SP, flags); }
int getbuttonstate() { int ret = get_gpio(8); if (ret == 0) return 1; return 0; }
void remove_edge_detect(unsigned int gpio) { struct epoll_event ev; struct gpios *g = get_gpio(gpio); if (g == NULL) return; // delete epoll of fd ev.events = EPOLLIN | EPOLLET | EPOLLPRI; ev.data.fd = g->value_fd; epoll_ctl(epfd_thread, EPOLL_CTL_DEL, g->value_fd, &ev); // delete callbacks for gpio remove_callbacks(gpio); // btc fixme - check return result?? gpio_set_edge(gpio, NO_EDGE); g->edge = NO_EDGE; if (g->value_fd != -1) close(g->value_fd); // btc fixme - check return result?? gpio_unexport(gpio); event_occurred[gpio] = 0; delete_gpio(gpio); }
int getbuttonstate() { int ret = get_gpio(24); // nxp multiplexer connected if (ret == 0) return 1; return 0; }
/* * Is key active */ int get_key_active(enum key_type key) { int gpio_state = get_gpio(device_keys[key].row, device_keys[key].column); if (device_keys[key].active_low) return gpio_state == 0; else return gpio_state == 1; }
void init_bootmode_straps(void) { #ifdef __PRE_RAM__ u32 flags = 0; /* Write Protect: GPIO68 = CHP3_SPI_WP, active high */ if (get_gpio(GPIO_SPI_WP)) flags |= (1 << FLAG_SPI_WP); /* Recovery: GPIO42 = CHP3_REC_MODE#, active low */ if (!get_gpio(GPIO_REC_MODE)) flags |= (1 << FLAG_REC_MODE); /* Developer: GPIO17 = KBC3_DVP_MODE, active high */ if (get_gpio(GPIO_DEV_MODE)) flags |= (1 << FLAG_DEV_MODE); pci_write_config32(PCI_DEV(0, 0x1f, 2), SATA_SP, flags); #endif }
/* * enable/disable the glitch filter; mostly used with IRQ handling. */ int at91_set_deglitch(uint32_t pin, int is_on) { struct at91_gpio *p = get_gpio(pin); if(p == NULL) { return -EINVAL; } __raw_writel(p->mask, p->regbase + (is_on ? PIO_IFER : PIO_IFDR)); return 0; }
/* * enable/disable the multi-driver; This is only valid for output and * allows the output pin to run as an open collector output. */ int at91_set_multi_drive(uint32_t pin, int is_on) { struct at91_gpio *p = get_gpio(pin); if(p == NULL) { return -EINVAL; } __raw_writel(p->mask, p->regbase + (is_on ? PIO_MDER : PIO_MDDR)); return 0; }
/* * assuming the pin is muxed as a gpio output, set its value. */ int at91_set_gpio_value(uint32_t pin, int value) { struct at91_gpio *p = get_gpio(pin); if(p == NULL) { return -EINVAL; } __raw_writel(p->mask, p->regbase + (value ? PIO_SODR : PIO_CODR)); return 0; }
static int at91_get_gpio_reg(uint32_t pin, uint32_t reg_offset) { struct at91_gpio *p = get_gpio(pin); uint32_t reg; if(p == NULL) { return -EINVAL; } reg = __raw_readl(p->regbase); return (reg & p->mask) != 0; }
/* * mux the pin to the "GPIO" peripheral role. */ int at91_set_GPIO_periph(uint32_t pin, int use_pullup) { struct at91_gpio *p = get_gpio(pin); if(p == NULL) { return -EINVAL; } __raw_writel(p->mask, p->regbase + PIO_IDR); __raw_writel(p->mask, p->regbase + (use_pullup ? PIO_PUER : PIO_PUDR)); __raw_writel(p->mask, p->regbase + PIO_PER); return 0; }
static void fill_lb_gpio(struct lb_gpio *gpio, int num, int polarity, const char *name, int force) { memset(gpio, 0, sizeof(*gpio)); gpio->port = num; gpio->polarity = polarity; if (force >= 0) gpio->value = force; else if (num >= 0) gpio->value = get_gpio(num); strncpy((char *)gpio->name, name, GPIO_MAX_NAME_LENGTH); }
void init_bootmode_straps(void) { u32 flags = 0; #ifdef __SIMPLE_DEVICE__ pci_devfn_t dev = PCI_DEV(0, 0x1f, 2); #else struct device *dev = pcidev_on_root(0x1f, 2); #endif /* Write Protect: GPIO58 = GPIO_SPI_WP, active high */ if (get_gpio(GPIO_SPI_WP)) flags |= (1 << FLAG_SPI_WP); /* Recovery: GPIO12 = RECOVERY_L, active low */ if (!get_gpio(GPIO_REC_MODE)) flags |= (1 << FLAG_REC_MODE); /* Developer: Virtual */ pci_write_config32(dev, SATA_SP, flags); }
void fill_lb_gpios(struct lb_gpios *gpios) { struct lb_gpio chromeos_gpios[] = { {GPIO_SPI_WP, ACTIVE_HIGH, get_gpio(GPIO_SPI_WP), "write protect"}, {GPIO_REC_MODE, ACTIVE_LOW, get_recovery_mode_switch(), "recovery"}, {-1, ACTIVE_HIGH, 1, "lid"}, {-1, ACTIVE_HIGH, 0, "power"}, {-1, ACTIVE_HIGH, gfx_get_init_done(), "oprom"}, }; lb_add_gpios(gpios, chromeos_gpios, ARRAY_SIZE(chromeos_gpios)); }
int add_edge_detect(unsigned int gpio, unsigned int edge, int bouncetime) // return values: // 0 - Success // 1 - Edge detection already added // 2 - Other error { pthread_t threads; struct epoll_event ev; long t = 0; struct gpios *g; int i = -1; i = gpio_event_added(gpio); if (i == 0) { // event not already added if ((g = new_gpio(gpio)) == NULL) return 2; gpio_set_edge(gpio, edge); g->edge = edge; g->bouncetime = bouncetime; } else if (i == edge) { // get existing event g = get_gpio(gpio); if ((bouncetime != -666 && g->bouncetime != bouncetime) || // different event bouncetime used (g->thread_added)) // event already added return 1; } else { return 1; } // create epfd_thread if not already open if ((epfd_thread == -1) && ((epfd_thread = epoll_create(1)) == -1)) return 2; // add to epoll fd ev.events = EPOLLIN | EPOLLET | EPOLLPRI; ev.data.fd = g->value_fd; if (epoll_ctl(epfd_thread, EPOLL_CTL_ADD, g->value_fd, &ev) == -1) { remove_edge_detect(gpio); return 2; } g->thread_added = 1; // start poll thread if it is not already running if (!thread_running) { if (pthread_create(&threads, NULL, poll_thread, (void *)t) != 0) { remove_edge_detect(gpio); return 2; } } return 0; }
/* * get a number comprised of multiple GPIO values. gpio_num_array points to * the array of gpio pin numbers to scan, terminated by -1. */ unsigned get_gpios(const int *gpio_num_array) { int gpio; unsigned bitmask = 1; unsigned vector = 0; while (bitmask && ((gpio = *gpio_num_array++) != -1)) { if (get_gpio(gpio)) vector |= bitmask; bitmask <<= 1; } return vector; }
static int hdmi_bind(struct device *dev, struct device *master, void *data) { static struct hdmi_platform_config config = {}; #ifdef CONFIG_OF struct device_node *of_node = dev->of_node; if (of_device_is_compatible(of_node, "qcom,hdmi-tx-8074")) { static const char *hpd_reg_names[] = {"hpd-gdsc", "hpd-5v"}; static const char *pwr_reg_names[] = {"core-vdda", "core-vcc"}; static const char *hpd_clk_names[] = {"iface_clk", "core_clk", "mdp_core_clk"}; static unsigned long hpd_clk_freq[] = {0, 19200000, 0}; static const char *pwr_clk_names[] = {"extp_clk", "alt_iface_clk"}; config.phy_init = hdmi_phy_8x74_init; config.hpd_reg_names = hpd_reg_names; config.hpd_reg_cnt = ARRAY_SIZE(hpd_reg_names); config.pwr_reg_names = pwr_reg_names; config.pwr_reg_cnt = ARRAY_SIZE(pwr_reg_names); config.hpd_clk_names = hpd_clk_names; config.hpd_freq = hpd_clk_freq; config.hpd_clk_cnt = ARRAY_SIZE(hpd_clk_names); config.pwr_clk_names = pwr_clk_names; config.pwr_clk_cnt = ARRAY_SIZE(pwr_clk_names); config.shared_irq = true; } else if (of_device_is_compatible(of_node, "qcom,hdmi-tx-8960")) { static const char *hpd_clk_names[] = {"core_clk", "master_iface_clk", "slave_iface_clk"}; static const char *hpd_reg_names[] = {"core-vdda", "hdmi-mux"}; config.phy_init = hdmi_phy_8960_init; config.hpd_reg_names = hpd_reg_names; config.hpd_reg_cnt = ARRAY_SIZE(hpd_reg_names); config.hpd_clk_names = hpd_clk_names; config.hpd_clk_cnt = ARRAY_SIZE(hpd_clk_names); } else if (of_device_is_compatible(of_node, "qcom,hdmi-tx-8660")) { config.phy_init = hdmi_phy_8x60_init; } else { dev_err(dev, "unknown phy: %s\n", of_node->name); } config.mmio_name = "core_physical"; config.ddc_clk_gpio = get_gpio(dev, of_node, "qcom,hdmi-tx-ddc-clk"); config.ddc_data_gpio = get_gpio(dev, of_node, "qcom,hdmi-tx-ddc-data"); config.hpd_gpio = get_gpio(dev, of_node, "qcom,hdmi-tx-hpd"); config.mux_en_gpio = get_gpio(dev, of_node, "qcom,hdmi-tx-mux-en"); config.mux_sel_gpio = get_gpio(dev, of_node, "qcom,hdmi-tx-mux-sel"); config.mux_lpm_gpio = get_gpio(dev, of_node, "qcom,hdmi-tx-mux-lpm"); #else static const char *hpd_clk_names[] = { "core_clk", "master_iface_clk", "slave_iface_clk", }; #endif dev->platform_data = &config; set_hdmi_pdev(dev_get_drvdata(master), to_platform_device(dev)); return 0; }
int set_gpio(int index, unsigned int value) { #if defined (CONFIG_RALINK_RT6855A) *(volatile u32 *)(RALINK_REG_PIODATA)= cpu_to_le32(value); #elif defined (CONFIG_RALINK_MT7620) if (index == 0) *(volatile u32 *)(RALINK_REG_PIODATA)= cpu_to_le32(value); else if (index == 24) *(volatile u32 *)(RALINK_REG_PIO3924DATA)= cpu_to_le32(value); else if (index == 40) *(volatile u32 *)(RALINK_REG_PIO7140DATA)= cpu_to_le32(value); else return -1; #endif return get_gpio(index); }
static void ftr_gpio_init(struct gpio_runtime *rt) { get_gpio("headphone-mute", NULL, &headphone_mute_gpio, &headphone_mute_gpio_activestate); get_gpio("amp-mute", NULL, &_mute_gpio, &_mute_gpio_activestate); get_gpio("lineout-mute", NULL, &lineout_mute_gpio, &lineout_mute_gpio_activestate); get_gpio("hw-reset", "audio-hw-reset", &hw_reset_gpio, &hw_reset_gpio_activestate); headphone_detect_node = get_gpio("headphone-detect", NULL, &headphone_detect_gpio, &headphone_detect_gpio_activestate); /* go Apple, and thanks for giving these different names * across the board... */ lineout_detect_node = get_gpio("lineout-detect", "line-output-detect", &lineout_detect_gpio, &lineout_detect_gpio_activestate); linein_detect_node = get_gpio("linein-detect", "line-input-detect", &linein_detect_gpio, &linein_detect_gpio_activestate); gpio_enable_dual_edge(headphone_detect_gpio); gpio_enable_dual_edge(lineout_detect_gpio); gpio_enable_dual_edge(linein_detect_gpio); get_irq(headphone_detect_node, &headphone_detect_irq); get_irq(lineout_detect_node, &lineout_detect_irq); get_irq(linein_detect_node, &linein_detect_irq); ftr_gpio_all_amps_off(rt); rt->implementation_private = 0; INIT_WORK(&rt->headphone_notify.work, ftr_handle_notify, &rt->headphone_notify); INIT_WORK(&rt->line_in_notify.work, ftr_handle_notify, &rt->line_in_notify); INIT_WORK(&rt->line_out_notify.work, ftr_handle_notify, &rt->line_out_notify); mutex_init(&rt->headphone_notify.mutex); mutex_init(&rt->line_in_notify.mutex); mutex_init(&rt->line_out_notify.mutex); }
void gpio_jtag_enable(void){ // set gpio4 to alt 5 gpio_t *gpio = get_gpio(); gpio->GPFSEL0 &= ~(7 << 12); // zero out gpio4 gpio->GPFSEL0 |= 2<< 12; //gpio4 to alt5 = ARM_TDI // set other gpios gpio->GPFSEL2 &= ~( (7<<6) //zero gpio22 |(7<<12) // gpio24 |(7<<15) // gpio25 |(7<<21)); // gpio27 gpio->GPFSEL2 |= (3 << 6) // alt4 ARM TRST |(3 << 12) // alt4 ARM_TD0 |(3 << 15) // alt4 ARM_TCK |(3 << 21); // alt4 ARM_TMS return; }
int gpio::configure(pin::direction_t dir, pin::pull_t pulls) { // Mux the pin in the right direction (redundent?) pin::xport(get_gpio(), dir, pulls); // Next, configure the GPIO driver accordingly strcpy(m_dev_append, "/direction"); FILE* fp = fopen(m_dev, "w"); if (fp == NULL) { fprintf(stderr, "ERROR: Cannot configure GPIO %s on pin %s: ", get_fct()->get_name(), get_name()); perror(0); return 0; } if (dir == pin::IN) fprintf(fp, "in"); else fprintf(fp, "out"); fclose(fp); return 1; }
int main(int argc, char **argv) { int count = 0; int state = 0; FILE *pRreco = NULL; FILE *pHw_ver = NULL; struct timeval start,end; printf("monitor-recobtn compile %s--%s\n", __DATE__,__TIME__); pHw_ver = fopen(hw_ver_name, "r"); fscanf(pHw_ver,"%*s%*s%x", &hw_version); printf("hw_version = %#x\n", hw_version); fclose(pHw_ver); while(1) { if(get_gpio(pRreco) == false) { gettimeofday( &start, NULL ); rg_on(); printf("Detect recovery button push off\n"); while(1) { if(get_gpio(pRreco) == true) { rg_off(); break; } gettimeofday( &end, NULL ); //3S if((1000000 * ( end.tv_sec - start.tv_sec ) + end.tv_usec - start.tv_usec) > (1000000 * 3)) { printf("recovery button off over 3S, wait push on\n"); while(get_gpio(pRreco) == false) { rg_on(); sleep(1); rg_off(); sleep(1); } printf("recovery button on\n"); pid_t pid = fork(); if ( pid < 0) /* Èç¹û³ö´í */ printf("error occured.\n"); else if (pid == 0) { rg_off(); //dup2(1, 0); if(argc >= 2) execvp(argv[1], argv+1); else { sleep(1); } exit(0); } else if (pid > 0) { wait(NULL); printf("child complete\n"); for(count = 0; count < 100; count++) { rg_on(); usleep(100*1000); rg_off(); usleep(100*1000); } printf("recovery factory complete\n"); } } else usleep(500*1000); } } else sleep(1); } }