Example #1
0
static int local_clk_enable(struct clk *clk)
{
	int ret = 0;

	if (clk->usecount == 0) {
		if (clk->parent) {
			ret = local_clk_enable(clk->parent);
			if (ret != 0)
				goto out;
		}

		if (clk->enable)
			ret = clk->enable(clk);
		else if (!(clk->flags & FIXED_RATE) && !clk->rate && clk->set_rate
			    && clk->user_rate)
			ret = clk->set_rate(clk, clk->user_rate);

		if (ret != 0 && clk->parent) {
			local_clk_disable(clk->parent);
			goto out;
		}

		clk->usecount++;
	}
out:
	return ret;
}
Example #2
0
int initialize_espeak(struct synth_t *s)
{
	int rate;

	/* initialize espeak */
	rate = espeak_Initialize(AUDIO_OUTPUT_PLAYBACK, 50, NULL, 0);
	if (rate < 0) {
		fprintf(stderr, "Unable to initialize espeak.\n");
		return -1;
	}

	/* We need a callback in acsint mode, but not in speakup mode. */
	if (espeakup_mode == ESPEAKUP_MODE_ACSINT)
		espeak_SetSynthCallback(acsint_callback);

	/* Setup initial voice parameters */
	if (defaultVoice) {
		set_voice(s, defaultVoice);
		free(defaultVoice);
		defaultVoice = NULL;
	}
	set_frequency(s, defaultFrequency, ADJ_SET);
	set_pitch(s, defaultPitch, ADJ_SET);
	set_rate(s, defaultRate, ADJ_SET);
	set_volume(s, defaultVolume, ADJ_SET);
	espeak_SetParameter(espeakCAPITALS, 0, 0);
	return 0;
}
Example #3
0
void sb_device::device_reset()
{
	m_dsp.prot_value = 0xaa;
	m_dsp.prot_count = 0;
	m_dack_out = 0;
	m_dsp.fifo_ptr = 0;
	m_dsp.fifo_r_ptr = 0;
	m_dsp.wbuf_status = 0;
	m_dsp.rbuf_status = 0;
	m_dsp.frequency = 8000; // per stereo-fx
	m_dsp.irq_active = 0;
	m_dsp.dma_no_irq = false;
	mixer_reset();

	m_onebyte_midi = false;
	m_uart_midi = false;
	m_uart_irq = false;
	m_mpu_midi = false;
	m_tx_busy = false;
	m_xmit_read = m_xmit_write = 0;
	m_recv_read = m_recv_write = 0;
	m_rx_waiting = m_tx_waiting = 0;

	// MIDI is 31250 baud, 8-N-1
	set_data_frame(1, 8, PARITY_NONE, STOP_BITS_1);
	set_rate(31250);
}
Example #4
0
void AnimatedSprite::init( double _rate, int _start_index, int _end_index, bool _repeat )
{
    set_rate( _rate );
    set_start_index( _start_index );
    set_end_index( _end_index );
    set_repeat( _repeat );
}
Example #5
0
NFP::model::Rating::Rating(int const& m, int const& u, int const& r, std::string const& d)
{
    set_movie_id((uint16_t)m);
    set_user_id((uint32_t)u);
    set_rate((uint8_t)r);
    set_date(utils::DateS2US(d));
}
Example #6
0
void lk201_device::device_reset()
{
	m_beeper->adjust(attotime::never);

	m_speaker->set_state(0);
	m_speaker->set_output_gain(0, 0);

	ddrs[0] = ddrs[1] = ddrs[2] = 0;
	ports[0] = ports[1] = ports[2] = 0;

	set_data_frame(1, 8, PARITY_NONE, STOP_BITS_1);
	set_rate(4800);
	m_count->adjust(attotime::from_hz(1200), 0, attotime::from_hz(1200));
	memset(m_timer.regs, 0, sizeof(m_timer.regs));

	sci_status = (SCSR_TC | SCSR_TDRE);

	spi_status = 0;
	spi_data = 0;

	kbd_data = 0;
	led_data = 0;

	transmit_register_reset();
	receive_register_reset();
}
Example #7
0
NFP::model::Rating::Rating(uint16_t const& m, uint32_t const& u, uint8_t const& r, uint16_t const& d)
{
    set_movie_id(m);
    set_user_id(u);
    set_rate(r);
    set_date(d);
}
Example #8
0
static int
lis331_ioctl(struct file *filp, int cmd, unsigned long arg)
{
	int	result = ERROR;

	switch (cmd) {
	case LIS331_SETRATE:
		if ((arg & REG1_RATE_MASK) == arg) {
			set_rate(arg);
			result = 0;
			lis331_dev.rate = arg;
		}
		break;

	case LIS331_SETRANGE:
		if ((arg & REG4_RANGE_MASK) == arg) {
			set_range(arg);
			result = 0;
		}
		break;

	case LIS331_SETBUFFER:
		lis331_dev.buffer = (struct lis331_buffer *)arg;
		result = 0;
		break;
	}

	if (result)
		errno = EINVAL;
	return result;
}
Example #9
0
int
lis331_attach(struct spi_dev_s *spi, int spi_id)
{
	int	result = ERROR;
	
	lis331_dev.spi = spi;

	SPI_LOCK(lis331_dev.spi, true);

	/* verify that the device is attached and functioning */
	if (read_reg(ADDR_WHO_AM_I) == WHO_I_AM) {

		/* set default configuration */
		write_reg(ADDR_CTRL_REG2, 0);	/* disable interrupt-generating high-pass filters */
		write_reg(ADDR_CTRL_REG3, 0);	/* no interrupts - we don't use them */
		write_reg(ADDR_CTRL_REG5, 0);	/* disable wake-on-interrupt */

		set_range(LIS331_RANGE_4G);
		set_rate(LIS331_RATE_400Hz);	/* takes device out of low-power mode */

		/* make ourselves available */
		register_driver("/dev/lis331", &lis331_fops, 0666, NULL);

		result = 0;
	} else {
		errno = EIO;
	}

	SPI_LOCK(lis331_dev.spi, false);

	return result;
}
Example #10
0
static gboolean gst_devsound_src_setcaps(GstBaseSrc *bsrc, GstCaps *caps)
    {
    GstDevsoundSrc *devsoundsrc;
    GstStructure *structure;
    const gchar *mimetype;
    int rate;
    int channel;

    devsoundsrc = GST_DEVSOUND_SRC (bsrc);
    //gst_debug_log(devsound_debug, GST_LEVEL_LOG, "", "", 0, (GObject *) devsoundsrc, "gst_devsound_src_setcaps ENTER ",NULL);
    structure = gst_caps_get_structure(caps, 0);
    mimetype = gst_structure_get_name(structure);

    gst_structure_get_int(structure, "rate", &rate);
    gst_structure_get_int(structure, "channels", &channel);

    devsoundsrc->rate = gst_devsound_src_get_rate(rate);
    devsoundsrc->channels = channel;

    set_channels(devsoundsrc->handle, devsoundsrc->channels);

    set_rate(devsoundsrc->handle, devsoundsrc->rate);

    if (!strncmp(mimetype, "audio/x-raw-int", 15))
        {
        devsoundsrc->fourcc = 0x36315020; //KMMFFourCCCodePCM16
        }
    else if (!strncmp(mimetype, "audio/amr", 9))
        {
        devsoundsrc->fourcc = 0x524d4120; //KMMFFourCCCodeAMR
        }
    else if (!strncmp(mimetype, "audio/x-mulaw", 13)||
             !strncmp(mimetype,"audio/x-alaw", 12))
        {
        devsoundsrc->fourcc = 0x31313747; //KMccFourCCIdG711
        }
    else if (!strncmp(mimetype, "audio/ilbc", 10))
        {
        devsoundsrc->fourcc = 0x43424c49; //KMccFourCCIdILBC
        }
    else if (!strncmp(mimetype, "audio/g729", 10))
        {
        devsoundsrc->fourcc = 0x39323747; //KMccFourCCIdG729
        }
    else
        {
        devsoundsrc->fourcc = 0x36315020; //KMMFFourCCCodePCM16
        }

    set_fourcc(devsoundsrc->handle, devsoundsrc->fourcc);
    //gst_debug_log(devsound_debug, GST_LEVEL_LOG, "", "", 0, (GObject *) devsoundsrc, "Before Signal DevSound from STOP",NULL);
    pthread_mutex_lock(&(create_mutex1));
    pthread_cond_signal(&(create_condition1));
    pthread_mutex_unlock(&(create_mutex1));
    //gst_debug_log(devsound_debug, GST_LEVEL_LOG, "", "", 0, (GObject *) devsoundsrc, "After Signal DevSound from STOP ",NULL);
    //gst_debug_log(devsound_debug, GST_LEVEL_LOG, "", "", 0, (GObject *) devsoundsrc, "gst_devsound_src_setcaps EXIT ",NULL);
    return TRUE;
    }
Example #11
0
static int reset_parameters(out123_handle *ao)
{
	int ret;
	ret = ioctl(ao->fn,AIOCRESET,NULL);
	if(ret >= 0) ret = set_format(ai);
	if(ret >= 0) ret = set_channels(ai);
	if(ret >= 0) ret = set_rate(ai);
	return ret;
}
Example #12
0
static void queue_process_entry(struct synth_t *s)
{
	espeak_ERROR error;
	static struct espeak_entry_t *current = NULL;

	if (current != queue_peek(synth_queue)) {
		if (current)
			free_espeak_entry(current);
		current = (struct espeak_entry_t *) queue_remove(synth_queue);
	}
	pthread_mutex_unlock(&queue_guard);

	if (current->cmd != CMD_PAUSE && paused_espeak) {
		reinitialize_espeak(s);
	}

	switch (current->cmd) {
	case CMD_SET_FREQUENCY:
		error = set_frequency(s, current->value, current->adjust);
		break;
	case CMD_SET_PITCH:
		error = set_pitch(s, current->value, current->adjust);
		break;
	case CMD_SET_PUNCTUATION:
		error = set_punctuation(s, current->value, current->adjust);
		break;
	case CMD_SET_RATE:
		error = set_rate(s, current->value, current->adjust);
		break;
	case CMD_SET_VOICE:
		error = EE_OK;
		break;
	case CMD_SET_VOLUME:
		error = set_volume(s, current->value, current->adjust);
		break;
	case CMD_SPEAK_TEXT:
		s->buf = current->buf;
		s->len = current->len;
		error = speak_text(s);
		break;
	case CMD_PAUSE:
		if (!paused_espeak) {
			espeak_Cancel();
			espeak_Terminate();
			paused_espeak = 1;
		}
		break;
	default:
		break;
	}

	if (error == EE_OK) {
		free_espeak_entry(current);
		current = NULL;
	}
}
Example #13
0
void graph_link_hle_device::device_reset()
{
	set_data_frame(1, 8, PARITY_NONE, STOP_BITS_1);
	set_rate(9600);
	receive_register_reset();
	transmit_register_reset();

	m_head = m_tail = 0;
	m_empty = true;
	m_ready = true;
}
Example #14
0
stream_config::stream_config(
    std::size_t max_packet_size,
    double rate,
    std::size_t burst_size,
    std::size_t max_heaps,
    double burst_rate_ratio)
{
    set_max_packet_size(max_packet_size);
    set_rate(rate);
    set_burst_size(burst_size);
    set_max_heaps(max_heaps);
    set_burst_rate_ratio(burst_rate_ratio);
}
Example #15
0
void
Meter::deserialize(std::istream *in) {
  auto lock = unique_lock();
  (*in) >> configured;
  if (configured) {
    for (size_t i = 0; i < rates.size(); i++) {
      rate_config_t config;
      (*in) >> config.info_rate;
      (*in) >> config.burst_size;
      set_rate(i, config);
    }
  }
}
Example #16
0
static void local_clk_disable(struct clk *clk)
{
	if (WARN_ON(clk->usecount == 0))
		return;

	if (!(--clk->usecount)) {
		if (clk->disable)
			clk->disable(clk);
		else if (!(clk->flags & FIXED_RATE) && clk->rate && clk->set_rate)
			clk->set_rate(clk, 0);
		if (clk->parent)
			local_clk_disable(clk->parent);
	}
}
Example #17
0
void
sample_rate::set_rate( const std::string &r )
{
	std::size_t ep = 0;
	double rn = std::stod( r, &ep );
	bool rt = false;
	if ( ep < r.size() )
	{
		std::string ss = base::trim( r.substr( ep ) );
		if ( ss == "DF" || ss == "df" )
			rt = true;
	}
	set_rate( rn, rt );
}
Example #18
0
static int local_set_rate(struct clk *clk, u32 rate)
{
	int ret = -EINVAL;
	if (clk->set_rate) {

		if (clk->user_rate == clk->rate && clk->parent->rate) {
			/* if clock enabled or rate not set */
			clk->user_rate = clk->round_rate(clk, rate);
			ret = clk->set_rate(clk, clk->user_rate);
		} else
			clk->user_rate = clk->round_rate(clk, rate);
		ret = 0;
	}
	return ret;
}
Example #19
0
static int set_stream_format(struct snd_oxfw *oxfw, struct amdtp_stream *s,
			     unsigned int rate, unsigned int pcm_channels)
{
	u8 **formats;
	struct snd_oxfw_stream_formation formation;
	enum avc_general_plug_dir dir;
	unsigned int len;
	int i, err;

	if (s == &oxfw->tx_stream) {
		formats = oxfw->tx_stream_formats;
		dir = AVC_GENERAL_PLUG_DIR_OUT;
	} else {
		formats = oxfw->rx_stream_formats;
		dir = AVC_GENERAL_PLUG_DIR_IN;
	}

	/* Seek stream format for requirements. */
	for (i = 0; i < SND_OXFW_STREAM_FORMAT_ENTRIES; i++) {
		err = snd_oxfw_stream_parse_format(formats[i], &formation);
		if (err < 0)
			return err;

		if ((formation.rate == rate) && (formation.pcm == pcm_channels))
			break;
	}
	if (i == SND_OXFW_STREAM_FORMAT_ENTRIES)
		return -EINVAL;

	/* If assumed, just change rate. */
	if (oxfw->assumed)
		return set_rate(oxfw, rate);

	/* Calculate format length. */
	len = 5 + formats[i][4] * 2;

	err = avc_stream_set_format(oxfw->unit, dir, 0, formats[i], len);
	if (err < 0)
		return err;

	/* Some requests just after changing format causes freezing. */
	msleep(100);

	return 0;
}
Example #20
0
void m20_keyboard_device::device_reset()
{
	buffered_rs232_device::device_reset();

	reset_key_state();
	clear_fifo();

	set_data_frame(1, 8, PARITY_NONE, STOP_BITS_2);
	set_rate(1'200);
	receive_register_reset();
	transmit_register_reset();

	output_dcd(0);
	output_dsr(0);
	output_cts(0);
	output_rxd(1);

	start_processing(attotime::from_hz(1'200));
}
Example #21
0
void x68k_keyboard_device::device_reset()
{
	buffered_rs232_device::device_reset();

	set_data_frame(1, 8, PARITY_NONE, STOP_BITS_1);
	set_rate(38'400); // TODO: Should be 2400 but MC68901 doesn't support divide by 16
	receive_register_reset();
	transmit_register_reset();

	m_enabled = 0;
	m_delay = 500;  // 3*100+200
	m_repeat = 110;  // 4^2*5+30

	stop_processing();
	reset_key_state();
	typematic_stop();
	clear_fifo();

	output_dcd(0);
	output_dsr(0);
	output_cts(0);
	output_rxd(1);
}
Example #22
0
static int open_sgi(audio_output_t *ao)
{
	int current_dev;
	ALport port = NULL;
	ALconfig config = alNewConfig();

	ao->userptr = NULL;

	/* Test for correct completion */
	if(config == 0)
	{
		error1("open_sgi: %s", alGetErrorString(oserror()));
		return -1;
	}

	/* Setup output device to specified device name. If there is no device name
	specified in ao structure, use the default for output */
	if((ao->device) != NULL)
	{
		current_dev = alGetResourceByName(AL_SYSTEM, ao->device, AL_OUTPUT_DEVICE_TYPE);

		debug2("Dev: %s %i", ao->device, current_dev);

		if(!current_dev)
		{
			int i, numOut;
			char devname[32];
			ALpv pv[1];
			ALvalue *alvalues;

			error2("Invalid audio resource: %s (%s)", ao->device, alGetErrorString(oserror()));

			if((numOut= alQueryValues(AL_SYSTEM,AL_DEFAULT_OUTPUT,0,0,0,0))>=0)
			fprintf(stderr, "There are %d output devices on this system.\n", numOut);
			else
			{
				fprintf(stderr, "Can't find output devices. alQueryValues failed: %s\n", alGetErrorString(oserror()));
				goto open_sgi_bad;
			}

			alvalues = malloc(sizeof(ALvalue) * numOut);
			i = alQueryValues(AL_SYSTEM, AL_DEFAULT_OUTPUT, alvalues, numOut, pv, 0);
			if(i == -1)
			error1("alQueryValues: %s", alGetErrorString(oserror()));
			else
			{
				for(i=0; i < numOut; i++)
				{
					pv[0].param = AL_NAME;
					pv[0].value.ptr = devname;
					pv[0].sizeIn = 32;
					alGetParams(alvalues[i].i, pv, 1);

					fprintf(stderr, "%i: %s\n", i, devname);
				}
			}
			free(alvalues);

			goto open_sgi_bad;
		}

		if(alSetDevice(config, current_dev) < 0)
		{
			error1("open: alSetDevice : %s",alGetErrorString(oserror()));
			goto open_sgi_bad;
		}
	} else
	current_dev = AL_DEFAULT_OUTPUT;

	/* Set the device */
	if(alSetDevice(config, current_dev) < 0)
	{
		error1("open_sgi: %s", alGetErrorString(oserror()));
		goto open_sgi_bad;
	}

	/* Set port parameters */

	if(alSetQueueSize(config, 131069) < 0)
	{
		error1("open_sgi: setting audio buffer failed: %s", alGetErrorString(oserror()));
		goto open_sgi_bad;
	}
	
	if(   set_format(ao, config) < 0
	   || set_rate(ao, config) < 0
	   || set_channels(ao, config) < 0 )
	goto open_sgi_bad;
	
	/* Open the audio port */
	port = alOpenPort("mpg123-VSC", "w", config);
	if(port == NULL)
	{
		error1("Unable to open audio channel: %s", alGetErrorString(oserror()));
		goto open_sgi_bad;
	}

	ao->userptr = (void*)port;

	alFreeConfig(config);
	return 1;

open_sgi_bad:
	/* clean up and return error */
	alFreeConfig(config);
	return -1;
}
Example #23
0
static void Wav_handler(Instance *pi, void *data)
{
  ALSAio_private *priv = (ALSAio_private *)pi;
  Wav_buffer *wav_in = data;
  int state;
  int dir = 0;
  int rc;
  //int i;
  snd_pcm_sframes_t n;

  if (!priv->c.enable) {
    return;
  }

  if (!priv->c.rate) {
    /* Set rate. */
    char channels[32];
    char rate[32];
    sprintf(rate, "%d", wav_in->params.rate);
    set_rate(pi, rate);

    /* Set channels. */
    sprintf(channels, "%d", wav_in->params.channels);
    set_channels(pi, channels);

    /* Set format */
    snd_pcm_format_t format = ALSAio_bps_to_snd_fmt(wav_in->params.bits_per_sample);
    if (format != SND_PCM_FORMAT_UNKNOWN) {
      priv->c.format = format;
      rc = snd_pcm_hw_params_set_format(priv->c.handle, priv->c.hwparams, priv->c.format);
      if (rc < 0) {
        fprintf(stderr, "*** %s: snd_pcm_hw_params_set_format %s: %s\n", __func__,
                s(priv->c.device), snd_strerror(rc));
      }
    }
  }

  state = snd_pcm_state(priv->c.handle);
  dpf("%s: state(1)=%s\n", __func__, ALSAio_state_to_string(state));

  if (state == SND_PCM_STATE_OPEN || state == SND_PCM_STATE_SETUP) {
    /* One time playback setup. */

    /* FIXME: Why does 64 work on NVidia CK804 with "snd_intel8x0"
       driver, but not 32, 128, 2048?  How to find out what will
       work? */
    snd_pcm_uframes_t frames =  priv->c.frames_per_io;

    fprintf(stderr, "%s: state=%s\n", __func__, ALSAio_state_to_string(state));

    rc = snd_pcm_hw_params_set_period_size_near(priv->c.handle, priv->c.hwparams, &frames, &dir);
    fprintf(stderr, "set_period_size_near returns %d (frames=%d)\n", rc, (int)frames);

    int periods = 4;

    rc = snd_pcm_hw_params_set_periods(priv->c.handle, priv->c.hwparams, periods, 0);
    if (rc < 0) {
      fprintf(stderr, "*** snd_pcm_hw_params_set_periods %s: %s\n", s(priv->c.device), snd_strerror(rc));
    }

    rc = snd_pcm_hw_params(priv->c.handle, priv->c.hwparams);
    if (rc < 0) {
      fprintf(stderr, "*** snd_pcm_hw_params %s: %s\n", s(priv->c.device), snd_strerror(rc));
    }

    state = snd_pcm_state(priv->c.handle);
    fprintf(stderr, "%s: state=%s\n", __func__, ALSAio_state_to_string(state));

    rc = snd_pcm_prepare(priv->c.handle);
    state = snd_pcm_state(priv->c.handle);
    fprintf(stderr, "%s: state=%s\n", __func__, ALSAio_state_to_string(state));
  }

  dpf("%s: state(2)=%s\n", __func__, ALSAio_state_to_string(state));

  int out_frames = wav_in->data_length / (priv->c.channels * priv->c.format_bytes);
  int frames_written = 0;
  while (1) {
    n = snd_pcm_writei(priv->c.handle, (uint8_t*)wav_in->data + (frames_written * (priv->c.channels * priv->c.format_bytes)),
                       out_frames);
    if (n > 0) {
      out_frames -= n;
      frames_written += n;
    }
    else {
      break;
    }
  }

  if (n < 0) {
    fprintf(stderr, "*** snd_pcm_writei %s: %s\n", s(priv->c.device), snd_strerror((int)n));
    fprintf(stderr, "*** attempting snd_pcm_prepare() to correct...\n");
    snd_pcm_prepare(priv->c.handle);
  }

  if (wav_in->no_feedback == 0  /* The default is 0, set to 1 if "filler" code below is called. */
      && pi->outputs[OUTPUT_FEEDBACK].destination) {
    Feedback_buffer *fb = Feedback_buffer_new();
    fb->seq = wav_in->seq;
    PostData(fb, pi->outputs[OUTPUT_FEEDBACK].destination);
  }

  Wav_buffer_release(&wav_in);
}
Example #24
0
File: sgi.c Project: 5py/libmpg123
static int open_sgi(audio_output_t *ao)
{
	int dev = AL_DEFAULT_OUTPUT;
	ALconfig config = alNewConfig();
	ALport port = NULL;
	
	/* Test for correct completion */
	if (config == 0) {
		error1("open_sgi: %s",alGetErrorString(oserror()));
		return -1;
	}
	
	/* Set port parameters */
	if(ao->channels == 2)
		alSetChannels(config, AL_STEREO);
	else
		alSetChannels(config, AL_MONO);
	
	alSetWidth(config, AL_SAMPLE_16);
	alSetSampFmt(config,AL_SAMPFMT_TWOSCOMP);
	alSetQueueSize(config, 131069);
	
	/* Setup output device to specified module. If there is no module
	specified in ao structure, use the default four output */
	if ((ao->device) != NULL) {
		char *dev_name;
		
		dev_name=malloc((strlen(ao->device) + strlen(analog_output_res_name) + 1) *
		  sizeof(char));
		
		strcpy(dev_name,ao->device);
		strcat(dev_name,analog_output_res_name);
		
		/* Find the asked device resource */
		dev=alGetResourceByName(AL_SYSTEM,dev_name,AL_DEVICE_TYPE);
		
		/* Free allocated space */
		free(dev_name);
		
		if (!dev) {
			error2("Invalid audio resource: %s (%s)",dev_name, alGetErrorString(oserror()));
			return -1;
		}
	}
	
	/* Set the device */
	if (alSetDevice(config,dev) < 0)
	{
		error1("open_sgi: %s",alGetErrorString(oserror()));
		return -1;
	}
	
	/* Open the audio port */
	port = alOpenPort("mpg123-VSC", "w", config);
	if(port == NULL) {
		error1("Unable to open audio channel: %s", alGetErrorString(oserror()));
		return -1;
	}
	
	ao->userptr = (void*)port;
	
	
	set_format(ao, config);
	set_channels(ao, config);
	set_rate(ao, config);
	
	
	alFreeConfig(config);
	
	return 1;
}
Example #25
0
int main(int argc, char *argv[])
{
	int dev_from_class = 0, write_cnt;
	int fd;
	static struct sysfs_names *names;
	struct rc_device	  rc_dev;

	argp_parse(&argp, argc, argv, 0, 0, 0);

	/* Just list all devices */
	if (!clear && !readtable && !keys.next && !ch_proto && !cfg.next && !test && !delay && !period) {
		if (devicename) {
			fd = open(devicename, O_RDONLY);
			if (fd < 0) {
				perror("Can't open device");
				return -1;
			}
			device_info(fd, "");
			close(fd);
			return 0;
		}
		if (show_sysfs_attribs(&rc_dev))
			return -1;

		return 0;
	}

	if (cfg.next && (clear || keys.next || ch_proto || devicename)) {
		fprintf (stderr, "Auto-mode can be used only with --read, --debug and --sysdev options\n");
		return -1;
	}
	if (!devicename) {
		names = find_device(devclass);
		if (!names)
			return -1;
		rc_dev.sysfs_name = names->name;
		if (get_attribs(&rc_dev, names->name)) {
			free_names(names);
			return -1;
		}
		names->name = NULL;
		free_names(names);

		devicename = rc_dev.input_name;
		dev_from_class++;
	}

	if (cfg.next) {
		struct cfgfile *cur;
		char *fname, *name;
		int rc;

		for (cur = &cfg; cur->next; cur = cur->next) {
			if ((!rc_dev.drv_name || strcasecmp(cur->driver, rc_dev.drv_name)) && strcasecmp(cur->driver, "*"))
				continue;
			if ((!rc_dev.keytable_name || strcasecmp(cur->table, rc_dev.keytable_name)) && strcasecmp(cur->table, "*"))
				continue;
			break;
		}

		if (!cur->next) {
			if (debug)
				fprintf(stderr, "Table for %s, %s not found. Keep as-is\n",
				       rc_dev.drv_name, rc_dev.keytable_name);
			return 0;
		}
		if (debug)
			fprintf(stderr, "Table for %s, %s is on %s file.\n",
				rc_dev.drv_name, rc_dev.keytable_name,
				cur->fname);
		if (cur->fname[0] == '/' || ((cur->fname[0] == '.') && strchr(cur->fname, '/'))) {
			fname = cur->fname;
			rc = parse_keyfile(fname, &name);
			if (rc < 0) {
				fprintf(stderr, "Can't load %s table\n", fname);
				return -1;
			}
		} else {
			fname = malloc(strlen(cur->fname) + strlen(IR_KEYTABLE_USER_DIR) + 2);
			strcpy(fname, IR_KEYTABLE_USER_DIR);
			strcat(fname, "/");
			strcat(fname, cur->fname);
			rc = parse_keyfile(fname, &name);
			if (rc != 0) {
				fname = malloc(strlen(cur->fname) + strlen(IR_KEYTABLE_SYSTEM_DIR) + 2);
				strcpy(fname, IR_KEYTABLE_SYSTEM_DIR);
				strcat(fname, "/");
				strcat(fname, cur->fname);
				rc = parse_keyfile(fname, &name);
			}
			if (rc != 0) {
				fprintf(stderr, "Can't load %s table from %s or %s\n", cur->fname, IR_KEYTABLE_USER_DIR, IR_KEYTABLE_SYSTEM_DIR);
				return -1;
			}
		}
		if (!keys.next) {
			fprintf(stderr, "Empty table %s\n", fname);
			return -1;
		}
		clear = 1;
	}

	if (debug)
		fprintf(stderr, "Opening %s\n", devicename);
	fd = open(devicename, O_RDONLY);
	if (fd < 0) {
		perror(devicename);
		return -1;
	}
	if (dev_from_class)
		free(devicename);
	if (get_input_protocol_version(fd))
		return -1;

	/*
	 * First step: clear, if --clear is specified
	 */
	if (clear) {
		clear_table(fd);
		fprintf(stderr, "Old keytable cleared\n");
	}

	/*
	 * Second step: stores key tables from file or from commandline
	 */
	write_cnt = add_keys(fd);
	if (write_cnt)
		fprintf(stderr, "Wrote %d keycode(s) to driver\n", write_cnt);

	/*
	 * Third step: change protocol
	 */
	if (ch_proto) {
		rc_dev.current = ch_proto;
		if (set_proto(&rc_dev))
			fprintf(stderr, "Couldn't change the IR protocols\n");
		else {
			fprintf(stderr, "Protocols changed to ");
			show_proto(rc_dev.current);
			fprintf(stderr, "\n");
		}
	}

	/*
	 * Fourth step: display current keytable
	 */
	if (readtable)
		display_table(&rc_dev, fd);

	/*
	 * Fiveth step: change repeat rate/delay
	 */
	if (delay || period) {
		unsigned int new_delay, new_period;
		get_rate(fd, &new_delay, &new_period);
		if (delay)
			new_delay = delay;
		if (period)
			new_period = period;
		set_rate(fd, new_delay, new_period);
	}

	if (test)
		test_event(fd);

	return 0;
}