Beispiel #1
0
int as_particle_compare_int(as_particle *p, void *data, uint32_t sz)
{
	if (!p || !data)
		return (-1);

	uint64_t i;
	if (sz == 8) {
		i = __be64_to_cpup(data);
	}
	else if (sz == 4) {
		i = __be32_to_cpup(data);
	}
	else {
		i = int_convert(data, sz);
	}

	as_particle_int *pi = (as_particle_int *) p;

	if (pi->i < i)
		return (-1);
	else if (pi->i > i)
		return (1);
	else
		return (0);
}
Beispiel #2
0
as_particle *as_particle_set_int(as_particle *p, as_particle_type type, void *data, uint32_t sz, bool data_in_memory)
{
	// convert the incoming buffer to a uint64_t

	uint64_t i;

	if (sz == 8) {
		i = __be64_to_cpup(data);
	}
	else if (sz == 4) {
		i = __be32_to_cpup(data);
	}
	else {
		i = int_convert(data, sz);
	}

	// The integer particle is never allocated anymore
	if (!p) {
		cf_info(AS_PARTICLE, "as_particle_set_int: null particle passed inf or integer. Error ");
		return (p);
	}
	as_particle_int *pi = (as_particle_int *)p;
	pi->i = i;
	return (p);
}
static u32 get_u32(struct platform_device *ofdev, const char *s) {
	u32 *p = (u32 *)of_get_property(ofdev->dev.of_node, s, NULL);
	if(p) {
		return __be32_to_cpup(p);
	} else {
		dev_warn(&ofdev->dev, "Parameter %s not found, defaulting to 0.\n", s);
		return 0;
	}
}
Beispiel #4
0
static int __devinit xilinx_spi_probe(struct platform_device *dev)
{
	struct xspi_platform_data *pdata;
	struct resource *r;
	int irq, num_cs = 0, little_endian = 0, bits_per_word = 8;
	struct spi_master *master;
	u8 i;

	pdata = dev->dev.platform_data;
	if (pdata) {
		num_cs = pdata->num_chipselect;
		little_endian = pdata->little_endian;
		bits_per_word = pdata->bits_per_word;
	}

#ifdef CONFIG_OF
	if (dev->dev.of_node) {
		const __be32 *prop;
		int len;

		/* number of slave select bits is required */
		prop = of_get_property(dev->dev.of_node, "xlnx,num-ss-bits",
				       &len);
		if (prop && len >= sizeof(*prop))
			num_cs = __be32_to_cpup(prop);
	}
#endif

	if (!num_cs) {
		dev_err(&dev->dev, "Missing slave select configuration data\n");
		return -EINVAL;
	}


	r = platform_get_resource(dev, IORESOURCE_MEM, 0);
	if (!r)
		return -ENODEV;

	irq = platform_get_irq(dev, 0);
	if (irq < 0)
		return -ENXIO;

	master = xilinx_spi_init(&dev->dev, r, irq, dev->id, num_cs,
				 little_endian, bits_per_word);
	if (!master)
		return -ENODEV;

	if (pdata) {
		for (i = 0; i < pdata->num_devices; i++)
			spi_new_device(master, pdata->devices + i);
	}

	platform_set_drvdata(dev, master);
	return 0;
}
Beispiel #5
0
static
int as_particle_add_int(as_particle *p, void *data, uint32_t sz, bool mc_compliant)
{
	if (!p || !data)
		return(-1);

	uint64_t i;
	if (sz == 8) {
		i = __be64_to_cpup(data);
	}
	else if (sz == 4) {
		i = __be32_to_cpup(data);
	}
	else {
		i = int_convert(data, sz);
	}

// The integer particle is never allocated anymore
	if (!p) {
		cf_info(AS_PARTICLE, "as_particle_add_int: null particle passed inf or integer. Error ");
		return (-1);
	}

	as_particle_int *pi = (as_particle_int *)p;

	// memcache has wrap requirement that decrements cannot take the value
	// below 0. The value is unsigned, so that really means don't wrap from 0 to
	// 0xFFFF... It also means you can't use (int64_t)(pi->i + i) < 0 since
	// all unsigned numbers > 0x8000... typecast to signed will be < 0.
	if (mc_compliant && ((int64_t)i < 0) && ((pi->i + i) > pi->i)) {
		pi->i = 0;
	} else {
		pi->i += i;
	}

	return(0);
}