LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Hardware > Linux - Embedded & Single-board computer
User Name
Password
Linux - Embedded & Single-board computer This forum is for the discussion of Linux on both embedded devices and single-board computers (such as the Raspberry Pi, BeagleBoard and PandaBoard). Discussions involving Arduino, plug computers and other micro-controller like devices are also welcome.

Notices


Reply
  Search this Thread
Old 09-10-2018, 03:15 PM   #1
Shreeya Patel
LQ Newbie
 
Registered: Sep 2018
Posts: 2

Rep: Reputation: Disabled
Device Tree Bindings for ADT7516 sensor


I have a BeagleBone green and ADT7516's evaluation board connected with SDA and SCL pins.

When I do i2cdetect -y -r 2, I can see the i2c address as 0x4b and I am able to probe the adt7316 driver present in IIO subsystem.

adt7316 driver uses platform data to get the hardware description. But my goal is to remove platform data and use DT bindings.

I understand some basic things about the DT bindings like..

1. Compatible
2. reg

But when I have a close look at the driver, I can see that there are certain
things which are taken from the platform data and are used in the whole driver.

So my question is that how do I replace those things in the driver if I remove platform data and use DT bindings.

I am putting probe function's code here.


Code:
    int adt7316_probe(struct device *dev, struct adt7316_bus *bus,
		const char *name)
    {
	struct adt7316_chip_info *chip;
	struct iio_dev *indio_dev;
	unsigned short *adt7316_platform_data = dev->platform_data;
	int ret = 0;

	indio_dev = devm_iio_device_alloc(dev, sizeof(*chip));
	if (!indio_dev)
		return -ENOMEM;
	chip = iio_priv(indio_dev);
	/* this is only used for device removal purposes */
	dev_set_drvdata(dev, indio_dev);

	chip->bus = *bus;

	if (name[4] == '3')
		chip->id = ID_ADT7316 + (name[6] - '6');
	else if (name[4] == '5')
		chip->id = ID_ADT7516 + (name[6] - '6');
	else
		return -ENODEV;

	chip->ldac_pin = adt7316_platform_data[1];
	if (chip->ldac_pin) {
		chip->config3 |= ADT7316_DA_EN_VIA_DAC_LDCA;
		if ((chip->id & ID_FAMILY_MASK) == ID_ADT75XX)
			chip->config1 |= ADT7516_SEL_AIN3;
	}
	chip->int_mask = ADT7316_TEMP_INT_MASK | ADT7316_VDD_INT_MASK;
	if ((chip->id & ID_FAMILY_MASK) == ID_ADT75XX)
		chip->int_mask |= ADT7516_AIN_INT_MASK;

	indio_dev->dev.parent = dev;
	if ((chip->id & ID_FAMILY_MASK) == ID_ADT75XX)
		indio_dev->info = &adt7516_info;
	else
		indio_dev->info = &adt7316_info;
	indio_dev->name = name;
	indio_dev->modes = INDIO_DIRECT_MODE;

	if (chip->bus.irq > 0) {
		if (adt7316_platform_data[0])
			chip->bus.irq_flags = adt7316_platform_data[0];

		ret = devm_request_threaded_irq(dev, chip->bus.irq,
						NULL,
						adt7316_event_handler,
						chip->bus.irq_flags |
						IRQF_ONESHOT,
						indio_dev->name,
						indio_dev);
		if (ret)
			return ret;

		if (chip->bus.irq_flags & IRQF_TRIGGER_HIGH)
			chip->config1 |= ADT7316_INT_POLARITY;
	}

	ret = chip->bus.write(chip->bus.client, ADT7316_CONFIG1, chip->config1);
	if (ret)
		return -EIO;

	ret = chip->bus.write(chip->bus.client, ADT7316_CONFIG3, chip->config3);
	if (ret)
		return -EIO;

	ret = devm_iio_device_register(dev, indio_dev);
	if (ret)
		return ret;

	dev_info(dev, "%s temperature sensor, ADC and DAC registered.\n",
			indio_dev->name);

	return 0;
    }
    EXPORT_SYMBOL(adt7316_probe);



So in the code we can see that chip->ldac_pin and chip->bus.irq_flags uses
platform data.
If I use DT bindings then platform data will have NULL value in it.

So how do I design my DT bindings here and how can I fetch that data in the driver?

I have seen many examples of DT bindings but I need specific help with adt7516 sensor.

Datasheet of adt7516 sensor

http://www.analog.com/media/en/techn..._7517_7519.pdf
 
Old 09-11-2018, 05:19 AM   #2
business_kid
LQ Guru
 
Registered: Jan 2006
Location: Ireland
Distribution: Slackware, Slarm64 & Android
Posts: 16,454

Rep: Reputation: 2353Reputation: 2353Reputation: 2353Reputation: 2353Reputation: 2353Reputation: 2353Reputation: 2353Reputation: 2353Reputation: 2353Reputation: 2353Reputation: 2353
Is there an Application note from AD (who are predictable people) on that or similar chips?

It strikes me there may be some underlying intelligence loading things at bootup, or power on, which may be loading data. You may need to alter that environment it loads.
There's a very detailed datasheet section on 'registers' which is where things which are modifiable should be described. You may need to specify a different part or work around it's limitations. In my experience, Analogue Devices write some of the best data sheets around - clear, detailed & concise.

I don't think it's reasonable to ask someone to do all that reading (grok your code & a 44 page datasheet) to assist you do what is essentially your job, while you are the one getting paid to do it.

Last edited by business_kid; 09-11-2018 at 05:20 AM.
 
Old 09-17-2018, 04:59 AM   #3
rocq
Member
 
Registered: Jan 2013
Location: Netherlands
Distribution: XUbuntu
Posts: 57

Rep: Reputation: Disabled
Well the most straightforward is to translate the platform data array to a device tree array.

In the devicetree this would look something like:
Code:
ad7316 {
   platform-data = <
       12 /* platform-data[0] */
       13 /* platform-data[1] */
    >;
};
and in your driver:
Code:
u32 pdata[2];
if (of_property_read_u32_array(np, "platform-data", pdata, ARRAY_SIZE(pdata)) >= 0) {
    /* hooray! */
} else {
    /* error */
}
Above was the straightforward... However, I would encourage you to be more descriptive and break up the platform data array into separate variables:
Code:
ad7316 {
    platform-data = <
        ldac_pin = <32>;
        irq_flags = <128>;
    >;
};
and
Code:
u32 val;
if (of_property_read_u32(np, "ldac_pin", &val) >= 0)
    /* hooray! */
} else {
    /* error */
}
 
Old 06-26-2019, 08:39 AM   #4
T_Versicolor
LQ Newbie
 
Registered: Jun 2019
Location: Usually on fallen trees
Distribution: Whatever I've cobbled together through Yocto
Posts: 18

Rep: Reputation: 0
Quote:
Originally Posted by Shreeya Patel View Post
I have seen many examples of DT bindings but I need specific help with adt7516 sensor.
http://www.analog.com/media/en/techn..._7517_7519.pdf
Looks like rocq gave a pretty good example but I figured I'd elaborate just a bit.

Based on my still very limited experience, you're not really going to find anything specific to a part unless the vendor made something. However, the neat thing about the device tree is that you can pretty much add whatever the hell you want to a node and then let the driver deal with it. Granted, not everything in a node is handled by its driver, but you could add pretty much any field you like and then use of_property* functions to go and grab the data from the tree when you probe.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Device Tree Bindings for ADT7516 sensor Shreeya Patel Linux - Embedded & Single-board computer 1 09-10-2018 03:36 PM
i need code for generate tree structure on sensor nodes ? kunal0807 Linux - Wireless Networking 1 05-11-2014 11:01 AM
[SOLVED] TOSHIBA Hard Drive Impact Sensor (3D sensor) and Linux josephj Linux - Laptop and Netbook 4 11-06-2010 06:39 PM
LXer: Qyoto C#/Mono Bindings for Qt4, New QtRuby release and PHP Bindings Coming Soon LXer Syndicated Linux News 0 07-03-2007 09:01 PM
Generating Interrupts to the USB sensor device lucky6969b Programming 1 03-31-2006 01:18 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Hardware > Linux - Embedded & Single-board computer

All times are GMT -5. The time now is 11:18 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration