static void isp_gpio_exit(struct sensor_pwd_info *spinfo) { DBG_INFO(""); // only free valid gpio, so no need to check its existence. gpio_exit(&spinfo->gpio_front, 1); gpio_exit(&spinfo->gpio_rear, 1); gpio_exit(&spinfo->gpio_reset, 0); }
//------------------------------------------------------------------------------ int main(void) { tOplkError ret = kErrorOk; const UINT8 aMacAddr[] = {MAC_ADDR}; UINT8 nodeid; // Initialize helper modules gpio_init(); lcd_init(); // get node ID from input nodeid = gpio_getNodeid(); // initialize instance memset(&instance_l, 0, sizeof(instance_l)); instance_l.cycleLen = CYCLE_LEN; instance_l.nodeId = (nodeid != 0) ? nodeid : NODEID; instance_l.fShutdown = FALSE; instance_l.fGsOff = FALSE; // set mac address (last byte is set to node ID) memcpy(instance_l.aMacAddr, aMacAddr, sizeof(aMacAddr)); instance_l.aMacAddr[5] = instance_l.nodeId; initEvents(&eventCbPowerlink); arp_init((UINT8)instance_l.nodeId); PRINTF("----------------------------------------------------\n"); PRINTF("openPOWERLINK embedded CN DEMO application\n"); PRINTF("using openPOWERLINK Stack: %s\n", PLK_DEFINED_STRING_VERSION); PRINTF("----------------------------------------------------\n"); PRINTF("NODEID=0x%02X\n", instance_l.nodeId); lcd_printNodeId(instance_l.nodeId); if ((ret = initPowerlink(&instance_l)) != kErrorOk) goto Exit; if ((ret = initApp()) != kErrorOk) goto Exit; if ((ret = oplk_setNonPlkForward(TRUE)) != kErrorOk) goto Exit; loopMain(&instance_l); Exit: arp_exit(); shutdownPowerlink(&instance_l); shutdownApp(); // Shutdown helper modules lcd_exit(); gpio_exit(); return 0; }
static int isp_gpio_init(struct device_node *fdt_node, struct sensor_pwd_info *spinfo) { const char *sensors = NULL; DBG_INFO(""); if (gpio_init(fdt_node, "reset-gpios", &spinfo->gpio_reset, 0)) { goto fail; } if (of_property_read_string(fdt_node, "sensors", &sensors)) { DBG_ERR("get sensors faild"); goto free_reset; } if (!strcmp(sensors, "front")) { // default is power-down if (gpio_init(fdt_node, "pwdn-front-gpios", &spinfo->gpio_front, 1)) { goto free_reset; } spinfo->flag = SENSOR_FRONT; } else if (!strcmp(sensors, "rear")) { if (gpio_init(fdt_node, "pwdn-rear-gpios", &spinfo->gpio_rear, 1)) { goto free_reset; } spinfo->flag = SENSOR_REAR; } else if (!strcmp(sensors, "dual")) { if (gpio_init(fdt_node, "pwdn-front-gpios", &spinfo->gpio_front, 1)) { goto free_reset; } if (gpio_init(fdt_node, "pwdn-rear-gpios", &spinfo->gpio_rear, 1)) { gpio_exit(&spinfo->gpio_front, 1); goto free_reset; } spinfo->flag = SENSOR_DUAL; } else { DBG_ERR("sensors of dts is wrong"); goto free_reset; } return 0; free_reset: gpio_exit(&spinfo->gpio_reset, 0); fail: return -1; }
static void isp_regulator_exit(struct isp_regulators *ir) { DBG_INFO(""); if (ir->dvdd_use_gpio) gpio_exit(&ir->dvdd_gpio, 0); if (ir->dvdd.regul) { regulator_exit(&ir->dvdd); } if (ir->avdd_use_gpio) { gpio_exit(&ir->avdd.gpio, 0); } else { struct dts_regulator *dr = &ir->avdd.regul; if (dr->regul) { regulator_exit(dr); } } }
//------------------------------------------------------------------------------ int main(void) { tOplkError ret = kErrorOk; const UINT8 aMacAddr[] = {MAC_ADDR}; UINT8 nodeid; #if (CONFIG_CDC_ON_SD != FALSE) tCdcBuffInfo cdcBuffInfo; #endif // Initialize helper modules gpio_init(); lcd_init(); // get node ID from input nodeid = gpio_getNodeid(); // initialize instance memset(&instance_l, 0, sizeof(instance_l)); instance_l.cycleLen = CYCLE_LEN; instance_l.nodeId = (nodeid != 0) ? nodeid : NODEID; instance_l.fShutdown = FALSE; instance_l.fGsOff = FALSE; #if (CONFIG_CDC_ON_SD != FALSE) if (sdcard_getCdcOnSd(pszCdcFilename_g, &cdcBuffInfo) != 0) { goto Exit; } instance_l.pCdcBuffer = (unsigned char*)cdcBuffInfo.pCdcBuffer; instance_l.cdcBufferSize = cdcBuffInfo.cdcSize; #else instance_l.pCdcBuffer = (unsigned char*)aCdcBuffer; instance_l.cdcBufferSize = sizeof(aCdcBuffer); #endif // set mac address (last byte is set to node ID) memcpy(instance_l.aMacAddr, aMacAddr, sizeof(aMacAddr)); instance_l.aMacAddr[5] = instance_l.nodeId; initEvents(&instance_l.fGsOff, &eventCbPowerlink); arp_init((UINT8)instance_l.nodeId); PRINTF("----------------------------------------------------\n"); PRINTF("openPOWERLINK console MN DEMO application\n"); PRINTF("using openPOWERLINK Stack: %s\n", PLK_DEFINED_STRING_VERSION); PRINTF("----------------------------------------------------\n"); PRINTF("NODEID=0x%02X\n", instance_l.nodeId); lcd_printNodeId(instance_l.nodeId); if ((ret = initPowerlink(&instance_l)) != kErrorOk) goto Exit; if ((ret = initApp()) != kErrorOk) goto Exit; if ((ret = oplk_setNonPlkForward(TRUE)) != kErrorOk) goto Exit; loopMain(&instance_l); Exit: #if (CONFIG_CDC_ON_SD != FALSE) sdcard_freeCdcBuffer(&cdcBuffInfo); #endif arp_exit(); shutdownPowerlink(&instance_l); shutdownApp(); // Shutdown helper modules lcd_exit(); gpio_exit(); return 0; }
static inline __init int alsa_init(void) { struct snd_kcontrol_new ctl_onoff = { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = "Master Playback Switch", .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, .info = playback_switch_info, .get = playback_switch_get, .put = playback_switch_put }; struct snd_kcontrol_new ctl_volume = { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = "Master Playback Volume", .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, .info = playback_pot_info, .get = playback_pot_get, .put = playback_pot_put, .private_value = 1, }; struct snd_kcontrol_new ctl_tone = { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = "Bass Playback Volume", .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, .info = playback_pot_info, .get = playback_pot_get, .put = playback_pot_put, .private_value = 0, }; int ret; ret = snd_card_create(-1, "Itrigue", THIS_MODULE, 0, &card); if( ret ) return ret; strcpy( card->driver, "I-Trigue" ); strcpy( card->shortname, "I-Trigue 3300" ); sprintf( card->longname, "%s at spi %d.%d (@ %d Hz), gpio %d", card->shortname, pot_spi_bus, pot_spi_cs, speed_hz, onoff_gpio ); /* ALSA controls */ ret = snd_ctl_add( card, snd_ctl_new1( &ctl_onoff, NULL ) ); if( ret ) goto bailout; ret = snd_ctl_add( card, snd_ctl_new1( &ctl_volume, NULL ) ); if( ret ) goto bailout; ret = snd_ctl_add( card, snd_ctl_new1( &ctl_tone, NULL ) ); if( ret ) goto bailout; ret = snd_card_register( card ); if( ret ) goto bailout; return ret; bailout: snd_card_free( card ); return ret; } static inline void alsa_exit(void) { snd_card_free( card ); } /* SETUP MODULE */ static int __init itrigue_init(void) { int ret; ret = gpio_init(); if( ret ) return ret; ret = spi_init(); if( ret ) { gpio_exit(); return ret; } ret = alsa_init(); if( ret ) { spi_exit(); gpio_exit(); return ret; } return ret; } static void __exit itrigue_exit(void) { alsa_exit(); spi_exit(); printk(KERN_INFO "I-Trigue 3300 off.\n"); gpio_exit(); }