aiodev: Name channels with device instance name
Subsystems (3)
PATCH v2 1/4 aiodev: Name channels with device instance name
When dynamically assigning device names, an aiodev's name will be "aiodev" and an index, not part of the name string itself, will be allocated dynamically. These are combined to register a device with a name like "aiodev0" or "aiodev1".
The shell environment variables use the device name, so one might use "${aiodev0.in_value0_mV}" and "${aiodev1.in_value0_mV}".
However, the channel names that are used with aiochannel_get_by_name() just use the aiodev's name and channel name. So channel 0 of the 1st aiodev would be "aiodev.in_value0_mV" and the 2nd aiodev would use the same name.
Change the channel naming to use the device instance name, e.g. "aiodev0", rather than the aiodev's base name. This makes the names used aiochannel_get_by_name() match the environment variable names and also avoids duplicate names with more than one dynamically allocated aiodev.
Rename aiochannel_get_by_name() to aiochannel_by_name() so that any out of tree boards that use it will fail to compile, since they now need to pass in a different name.
---
Changes in v2:
* Rename aiochannel_get_by_name()
drivers/aiodev/core.c | 4 ++-- include/aiodev.h | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-)
drivers/aiodev/core.c +2 -2
@@ -24,7 +24,7 @@LIST_HEAD (aiodevices);EXPORT_SYMBOL (aiodevices); -struct aiochannel *aiochannel_get_by_name (const char *name) +struct aiochannel *aiochannel_by_name (const char *name) {struct aiodevice *aiodev;int i;
@@ -131,7 +131,7 @@ int aiodevice_register(struct aiodevice *aiodev) aiochannel_param_get_value, &aiochan->value, "%d", aiochan); - aiochan->name =xasprintf ("%s.%s" , aiodev->name, name); + aiochan->name =xasprintf ("%s.%s" ,dev_name (&aiodev->dev), name);free (name); }
include/aiodev.h +2 -1
@@ -31,7 +31,8 @@ struct aiodevice {int aiodevice_register (struct aiodevice *aiodev);struct aiochannel *aiochannel_get (struct device_d *dev,int index); -struct aiochannel *aiochannel_get_by_name (const char *name); +/* Find aiochannel by channel name, e.g. "aiodev0.in_value0_mV" */ +struct aiochannel *aiochannel_by_name (const char *name);int aiochannel_get_value (struct aiochannel *aiochan,int *value);int aiochannel_get_index (struct aiochannel *aiochan);
Signature · 7 lines
2.26.2 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
PATCH v2 2/4 aiodev: am335x_adc: Driver for ADC on TI AM335x SoCs
This is a simple driver for the ADC. It's designed to get single readings. Possible uses would be temperature sensing a thermistor, measuring a power rail, or a detecting multi-level board ID pin strapping.
It's not designed to co-exist with a touch screen controller driver, which uses the same hardware on the AM335x, as there is no barebox touchscreen driver.
The device tree binding is compatible with the Linux IIO driver.
This is from the Linux driver:
The ADC clock is expected to run at target of 3MHz, and expected to capture 12-bit data at a rate of 200 KSPS. The TSC_ADC_SS controller design assumes the OCP clock is at least 6x faster than the ADC clock.
The OCP clock is 100 MHz, from CORE_CLKOUTM4/2. The AM335x Reference Manual §12.2.2 gives a max ADC clock of 24 MHz. There's nothing about the factor of 6x OCP to ADC, a 3 MHz ADC target, nor 200 kSPS. In §12.3.7 a limit of at least 15 ADC clock cycles per sample is given.
The AM335x Datasheet §5.10 provides more parameters for the ADC: An ADC clock max of 3 MHz, a nominal conversion time of 13 cycles, min and max acquisition time of 2 to 257 cycles, and a max sample rate (@ 3 MHz) of 200 kSPS.
A 3 MHz ADC clock at 15 cycles per sample provides for a 200 kSPS sampling rate. The minimum open, sampling, and conversion times are 0, 1, and 13 clocks, respectively. This would seem to indicate the sampling at 14 cyles per sample is possible. Perhaps the "Sample Delay" in the reference manual is called "Acquisition Time" in the datasheet, and the reference manual minimum of 1 cycle is incorrect and the minimum is actually 2 cycles. Which would then produce a minimum of 15 cycles per sample.
This driver assumes the external references will be used (as does the Linux IIO driver). This would have been good to put into the device tree bindings, but the Linux driver's bindings did not do that.
The Barebox driver will convert the ADC reading to mV, and assumes the external refs are GND and 1.8V. This also would have been nice to put into the device tree binding. It also doesn't allow for automatically adjusting for an external divider, commonly to measure power rails above 1.8V, e.g. the BeagleBone Black ain7 measures the 3.3V rail divided by 2.
--- drivers/aiodev/Kconfig | 8 ++ drivers/aiodev/Makefile | 1 + drivers/aiodev/am335x_adc.c | 183 ++++++++++++++++++++++++++++++ drivers/aiodev/ti_am335x_tscadc.h | 163 ++++++++++++++++++++++++++ 4 files changed, 355 insertions(+) create mode 100644 drivers/aiodev/am335x_adc.c create mode 100644 drivers/aiodev/ti_am335x_tscadc.h
drivers/aiodev/Kconfig +8 -0
@@ -35,4 +35,12 @@ config MC13XXX_ADC help Support for MC13783, MC13892, MC34708 ADC +config AM335X_ADC + tristate "AM335X ADC driver" + depends on ARCH_AM33XX + help + Support for ADC on TI AM335X SoCs. Supports simple one-shot readings + rather than continuous sampling with DMA, etc. ADC channels should be + configured via device tree, using the kernel bindings. + endif
drivers/aiodev/Makefile +1 -0
@@ -4,3 +4,4 @@ obj-$(CONFIG_IMX_THERMAL) += imx_thermal.o obj-$(CONFIG_LM75) += lm75.o obj-$(CONFIG_MC13XXX_ADC) += mc13xxx_adc.o obj-$(CONFIG_QORIQ_THERMAL) += qoriq_thermal.o +obj-$(CONFIG_AM335X_ADC) += am335x_adc.o
drivers/aiodev/am335x_adc.c new file +183 -0
183 lines not on this page · raw message
drivers/aiodev/ti_am335x_tscadc.h new file +163 -0
163 lines not on this page · raw message
Signature · 7 lines
2.26.2 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
PATCH v2 3/4 ARM: am335x: Enable TSC/ADC clock
In reply to Trent PiephoNow that there is a Barebox driver for the ADC, enable the clock to the TSC/ADC block.
This machine doesn't use common clock framework clocks in Barebox, and instead enables any clock that might get used. Enalbing the clock could be made conditional based on enabling the driver, but none of the other clocks do this.
--- arch/arm/mach-omap/am33xx_clock.c | 4 ++++ arch/arm/mach-omap/include/mach/am33xx-clock.h | 1 + 2 files changed, 5 insertions(+)
arch/arm/mach-omap/am33xx_clock.c +4 -0
@@ -165,6 +165,10 @@ void am33xx_enable_per_clocks(void)__raw_writel (PRCM_MOD_EN ,CM_PER_USB0_CLKCTRL );while ((__raw_readl (CM_PER_USB0_CLKCTRL ) &0x30000 ) !=0x0 ); +/* TSC & ADC */ +__raw_writel (PRCM_MOD_EN ,CM_WKUP_ADC_TSC_CLKCTRL ); +while (__raw_readl (CM_WKUP_ADC_TSC_CLKCTRL ) !=PRCM_MOD_EN ); + clkdcoldo =__raw_readl (CM_CLKDCOLDO_DPLL_PER ); clkdcoldo = clkdcoldo |0x100 ;__raw_writel (clkdcoldo,CM_CLKDCOLDO_DPLL_PER );
arch/arm/mach-omap/include/mach/am33xx-clock.h +1 -0
@@ -138,6 +138,7 @@#define CM_PER_I2C1_CLKCTRL (CM_PER + 0x48)/* I2C1 */ #define CM_PER_I2C2_CLKCTRL (CM_PER + 0x44)/* I2C2 */ #define CM_WKUP_GPIO0_CLKCTRL (CM_WKUP + 0x8)/* GPIO0 */ +#define CM_WKUP_ADC_TSC_CLKCTRL (CM_WKUP + 0xbc)/* TSCADC */ #define CM_PER_MMC0_CLKCTRL (CM_PER + 0x3C)#define CM_PER_MMC1_CLKCTRL (CM_PER + 0xF4)
Signature · 7 lines
2.26.2 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
PATCH v2 4/4 ARM: beaglebone: Enable ADC
In reply to Trent PiephoOn the BeagleBone Black, enable the dts node for the TSC/ADC. Add a simple configuration that maps all eight channels in order. AIN[0:6] are exposed on connector P9, while AIN7 measures the 3.3V rail divided by 2.
--- arch/arm/dts/am335x-boneblack.dts | 10 ++++++++++ 1 file changed, 10 insertions(+)
arch/arm/dts/am335x-boneblack.dts +10 -0
@@ -85,3 +85,13 @@ status = "okay"; }; }; + +&tscadc { + status = "okay"; + adc { + /* Ch 0-6 are on connector P9. Ch 7 measures the 3.3V rail + * divided by 2 (e.g., it should read 1650). + */ + ti,adc-channels = <0>, <1>, <2>, <3>, <4>, <5>, <6>, <7>; + }; +};
Signature · 7 lines
2.26.2 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
Sascha Hauer
AppliedQuoted 19 lines · Trent Piepho
When dynamically assigning device names, an aiodev's name will be "aiodev" and an index, not part of the name string itself, will be allocated dynamically. These are combined to register a device with a name like "aiodev0" or "aiodev1".
The shell environment variables use the device name, so one might use "${aiodev0.in_value0_mV}" and "${aiodev1.in_value0_mV}".
However, the channel names that are used with
aiochannel_get_by_name()just use the aiodev's name and channel name. So channel 0 of the 1st aiodev would be "aiodev.in_value0_mV" and the 2nd aiodev would use the same name.Change the channel naming to use the device instance name, e.g. "aiodev0", rather than the aiodev's base name. This makes the names used
aiochannel_get_by_name()match the environment variable names and also avoids duplicate names with more than one dynamically allocated aiodev.
Quoted 8 lines
Rename
aiochannel_get_by_name()toaiochannel_by_name()so that any out of tree boards that use it will fail to compile, since they now need to pass in a different name.Signed-off-by Trent Piepho <[email protected]>---
Changes in v2:
* Renameaiochannel_get_by_name()
Applied all, thanks
Sascha
Signature · 9 lines
Pengutronix e.K. | | Steuerwalder Str. 21 | http://www.pengutronix.de/ | 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 | _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox