Trouble using at91-sama5d2_adc driver

This forum is for users of Microchip MPUs and who are interested in using Linux OS.

Moderator: nferre

PeterT
Posts: 17
Joined: Tue Jun 21, 2016 12:03 am

Trouble using at91-sama5d2_adc driver

Sat Feb 10, 2018 1:20 am

I am attempting to use the ADC on the SAMA5D2 device. I have 3.3V connected to the ADVREF and both VDDANA. There is nothing else currently giving me any trouble. I'm quickly running out of idea for where to look for a solution. Any suggestions would be greatly appreciated.

Buildroot: 2017.02.x
Linux: 4.9.52-linux4sam_5.7

Linux config:

Code: Select all

CONFIG_IIO=y
CONFIG_IIO_BUFFER=y
# CONFIG_IIO_BUFFER_CB is not set
CONFIG_IIO_KFIFO_BUF=y
CONFIG_IIO_TRIGGERED_BUFFER=y
# CONFIG_IIO_CONFIGFS is not set
CONFIG_IIO_TRIGGER=y
CONFIG_IIO_CONSUMERS_PER_TRIGGER=2
# CONFIG_IIO_SW_DEVICE is not set
# CONFIG_IIO_SW_TRIGGER is not set

CONFIG_AT91_ADC=y
CONFIG_AT91_SAMA5D2_ADC=y
(note: linux compilation fails if I disable CONFIG_AT91_ADC)

I have the following entries in my dts at the path /ahb/apb/
(stock SAMA5D2 include)

Code: Select all

adc: adc@fc030000 {
	compatible = "atmel,sama5d2-adc";
	reg = <0xfc030000 0x100>;
	interrupts = <40 IRQ_TYPE_LEVEL_HIGH 7>;
	clocks = <&adc_clk>;
	clock-names = "adc_clk";
	atmel,min-sample-rate-hz = <200000>;
	atmel,max-sample-rate-hz = <20000000>;
	atmel,startup-time-ms = <4>;
	atmel,trigger-edge-type = <IRQ_TYPE_EDGE_RISING>;
	status = "disabled";
};
(custom dts)

Code: Select all

adc: adc@fc030000 {
	vddana-supply = <&vdd_3v3_lp_reg>;
	vref-supply = <&vdd_3v3_lp_reg>;
	pinctrl-names = "default";
	pinctrl-0 = <&pinctrl_adc_default>;
	status = "okay";
};
And this entry in my pinctrl section:

Code: Select all

pinctrl_adc_default: adc_default {
	pinmux = <PIN_PD24__GPIO>;
	bias-disable;
};
The DTS compiles with no errors.
The /sys/firmware/devicetree files appear to be populated correctly:
(WD is /sys/firmware/devicetree/base/ahb/apb/adc@fc030000)

Code: Select all

# cat status
okay
# cat compatible
atmel,sama5d2-adc

Code: Select all

# echo 0 > drivers_probe
-sh: echo: write error: No such device
# ls -al /sys/bus/iio/devices
total 0
drwxr-xr-x 2 root root 0 Nov  3 17:16 .
drwxr-xr-x 4 root root 0 Nov  3 17:16 ..
# lsmod
Module                  Size  Used by
at91_sama5d2_adc        6953  0
(lsmod only shows that line when I include the driver as a module instead of builtin)
blue_z
Location: USA
Posts: 1704
Joined: Thu Apr 19, 2007 10:15 pm

Re: Trouble using at91-sama5d2_adc driver

Tue Feb 13, 2018 2:51 am

PeterT wrote:I am attempting to use the ADC on the SAMA5D2 device.
What board is this?

PeterT wrote:(lsmod only shows that line when I include the driver as a module instead of builtin)
Of course, because that command only reports loadable modules.
The sensible places to look for driver status are the system log (e.g. the `dmesg` command) (for any messages from the driver), the /proc/iomem file (for registration of the (well-behaved) device's register space), the /proc/interrupts file (for registration of the device's interrupt), and the /proc/devices file.

Regards
PeterT
Posts: 17
Joined: Tue Jun 21, 2016 12:03 am

Re: Trouble using at91-sama5d2_adc driver

Tue Feb 13, 2018 8:01 pm

Thank you for the reply, blue_z. This is a custom board. Your suggestions gave me more places to look. dmesg makes no mention of the driver and neither do any of the other locations you suggested looking. I'm assuming that even if the hardware device isn't responding, there should be some message to that effect because I declare the device in the DTS. This would lead me to believe there is a problem with the device tree, the driver, or the kernel. Certainly the most likely is the device tree. Did I miss something obvious?

Code: Select all

# cat devices
Character devices:
  1 mem
  2 pty
  3 ttyp
  4 /dev/vc/0
  4 tty
  4 ttyS
  5 /dev/tty
  5 /dev/console
  5 /dev/ptmx
  7 vcs
 10 misc
 13 input
 29 fb
 89 i2c
128 ptm
136 pts
251 watchdog
252 iio
253 rtc
254 gpiochip

Block devices:
  1 ramdisk
259 blkext
  7 loop
179 mmc
# cat iomem
00200000-0021ffff : 200000.sram
20000000-27ffffff : System RAM
  20008000-206fffff : Kernel code
  20800000-2084d5db : Kernel data
a0000000-a00002ff : /ahb/sdio-host@a0000000
b0000000-b00002ff : /ahb/sdio-host@b0000000
f0004000-f0004fff : /ahb/apb/dma-controller@f0004000
f0010000-f0010fff : /ahb/apb/dma-controller@f0010000
f8000000-f80000ff : /ahb/apb/spi@f8000000
f8008000-f8008fff : /ahb/apb/ethernet@f8008000
f800c000-f800c0ff : /ahb/apb/timer@f800c000
f8010000-f80100ff : /ahb/apb/timer@f8010000
f8020000-f80200ff : atmel_serial
f8028000-f80280ff : /ahb/apb/i2c@f8028000
f802c000-f802ffff : /ahb/apb/pwm@f802c000
f8048010-f804801f : /ahb/apb/shdwc@f8048010
fc000000-fc0000ff : /ahb/apb/spi@fc000000
fc014000-fc0141ff : /ahb/apb/flexcom@fc014000
fc014200-fc0143ff : atmel_serial
fc01c000-fc01c0ff : /ahb/apb/trng@fc01c000
fc028000-fc0280ff : /ahb/apb/i2c@fc028000
fc038000-fc0385ff : /ahb/apb/pinctrl@fc038000
# cat interrupts
           CPU0       
 16:         63  atmel-aic5   3 Level     at91_tick
 19:       8145  atmel-aic5  31 Level     mmc0
 20:     320344  atmel-aic5  32 Level     mmc1
 21:          0  atmel-aic5   6 Level     at_xdmac
 22:          0  atmel-aic5   7 Level     at_xdmac
 23:          1  atmel-aic5  74 Level     at91_rtc
 26:          0  atmel-aic5  33 Level     f8000000.spi
 27:      76298  atmel-aic5   5 Level     eth0
 28:       6137  atmel-aic5  66 Level     eth0
 29:        230  atmel-aic5  67 Level     eth0
 30:  443742968  atmel-aic5  35 Level     tc_clkevt
 32:      53596  atmel-aic5  25 Level     ttyS0
 33:          0  atmel-aic5  29 Level     f8028000.i2c
 36:          8  atmel-aic5  34 Level     fc000000.spi
 38:         14  atmel-aic5  30 Level     fc028000.i2c
118:         11      GPIO  73 Level     phy_interrupt
Err:          0

Code: Select all

# dmesg
[    0.000000] Booting Linux on physical CPU 0x0
[    0.000000] Linux version 4.9.52-linux4sam_5.7 (peter@peter-laptop) (gcc version 6.3.0 (Buildroot 2017.02.10) ) #2 PREEMPT Fri Feb 9 10:32:15 MST 2018
[    0.000000] CPU: ARMv7 Processor [410fc051] revision 1 (ARMv7), cr=10c53c7d
[    0.000000] CPU: PIPT / VIPT nonaliasing data cache, VIPT aliasing instruction cache
[    0.000000] OF: fdt:Machine model: Ray Allen Synergy POD-G3
[    0.000000] Memory policy: Data cache writeback
[    0.000000] On node 0 totalpages: 32768
[    0.000000] free_area_init_node: node 0, pgdat c0821508, node_mem_map c7efb000
[    0.000000]   Normal zone: 256 pages used for memmap
[    0.000000]   Normal zone: 0 pages reserved
[    0.000000]   Normal zone: 32768 pages, LIFO batch:7
[    0.000000] CPU: All CPU(s) started in SVC mode.
[    0.000000] pcpu-alloc: s0 r0 d32768 u32768 alloc=1*32768
[    0.000000] pcpu-alloc: [0] 0 
[    0.000000] Built 1 zonelists in Zone order, mobility grouping on.  Total pages: 32512
[    0.000000] Kernel command line: console=ttyS0,115200n8 root=/dev/mmcblk0p2 rootfstype=ext4 earlyprintk boot_a
[    0.000000] PID hash table entries: 512 (order: -1, 2048 bytes)
[    0.000000] Dentry cache hash table entries: 16384 (order: 4, 65536 bytes)
[    0.000000] Inode-cache hash table entries: 8192 (order: 3, 32768 bytes)
[    0.000000] Memory: 122264K/131072K available (4096K kernel code, 135K rwdata, 1160K rodata, 1024K init, 174K bss, 8808K reserved, 0K cma-reserved)
[    0.000000] Virtual kernel memory layout:
                   vector  : 0xffff0000 - 0xffff1000   (   4 kB)
                   fixmap  : 0xffc00000 - 0xfff00000   (3072 kB)
                   vmalloc : 0xc8800000 - 0xff800000   ( 880 MB)
                   lowmem  : 0xc0000000 - 0xc8000000   ( 128 MB)
                   modules : 0xbf000000 - 0xc0000000   (  16 MB)
                     .text : 0xc0008000 - 0xc0500000   (5088 kB)
                     .init : 0xc0700000 - 0xc0800000   (1024 kB)
                     .data : 0xc0800000 - 0xc0821d60   ( 136 kB)
                      .bss : 0xc0821d60 - 0xc084d5dc   ( 175 kB)\x000 - 0xc084d5dc   ( 175 kB)
[    0.000000] Preemptible * RCU implementation.
[    0.000000] 	Build-time adjustment of leaf fanout to 32.\x002.
[    0.000000] NR_IRQS:16 nr_irqs:16 16
[    0.000000] L2C-310 ID prefetch enabled, offset 2 lines
[    0.000000] L2C-310 dynamic clock gating enabled, standby mode enabled
[    0.000000] L2C-310 cache controller enabled, 8 ways, 128 kB
[    0.000000] L2C-310: CACHE_ID 0x410000c9, AUX_CTRL 0x36020000
[    0.000000] clocksource: pit: mask: 0xffffff max_cycles: 0xffffff, max_idle_ns: 1439202057 ns
[    0.000000] sched_clock: 32 bits at 1kHz, resolution 1000000ns, wraps every 2147483647500000ns
[    0.000000] Console: colour dummy device 80x30
[    0.008000] Calibrating delay loop... 325.63 BogoMIPS (lpj=162816)
[    0.009000] pid_max: default: 32768 minimum: 301
[    0.009000] Mount-cache hash table entries: 1024 (order: 0, 4096 bytes)
[    0.009000] Mountpoint-cache hash table entries: 1024 (order: 0, 4096 bytes)
[    0.011000] CPU: Testing write buffer coherency: ok
[    0.011000] Setting up static identity map for 0x20100000 - 0x20100034
[    0.015000] devtmpfs: initialized
[    0.035000] VFP support v0.3: implementor 41 architecture 2 part 30 variant 5 rev 1
[    0.035000] clocksource: jiffies: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 1911260446275000 ns
[    0.036000] futex hash table entries: 256 (order: -1, 3072 bytes)
[    0.036000] pinctrl core: initialized pinctrl subsystem
[    0.038000] NET: Registered protocol family 16
[    0.040000] DMA: preallocated 256 KiB pool for atomic coherent allocations
[    0.061000] hw-breakpoint: found 2 (+1 reserved) breakpoint and 1 watchpoint registers.
[    0.061000] hw-breakpoint: maximum watchpoint size is 4 bytes.
[    0.063000] tcb_clksrc: tc0 at 10.875 MHz
[    0.063000] clocksource: tcb_clksrc: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 184217874325 ns
[    0.077000] at_xdmac f0010000.dma-controller: 16 channels, mapped at 0xc8855000
[    0.080000] at_xdmac f0004000.dma-controller: 16 channels, mapped at 0xc8857000
[    0.082000] AT91: Detected SoC family: sama5d2
[    0.082000] AT91: Detected SoC: sama5d27, revision 1
[    0.083000] at91_i2c f8028000.i2c: could not find pctldev for node /ahb/apb/pinctrl@fc038000/i2c0_default, deferring probe
[    0.083000] at91_i2c fc028000.i2c: could not find pctldev for node /ahb/apb/pinctrl@fc038000/i2c1_default, deferring probe
[    0.086000] clocksource: Switched to clocksource tcb_clksrc
[    0.107000] NET: Registered protocol family 2
[    0.109000] TCP established hash table entries: 1024 (order: 0, 4096 bytes)
[    0.109000] TCP bind hash table entries: 1024 (order: 0, 4096 bytes)
[    0.109000] TCP: Hash tables configured (established 1024 bind 1024)
[    0.109000] UDP hash table entries: 256 (order: 0, 4096 bytes)
[    0.110000] UDP-Lite hash table entries: 256 (order: 0, 4096 bytes)
[    0.110000] NET: Registered protocol family 1
[    0.111000] hw perfevents: enabled with armv7_cortex_a5 PMU driver, 3 counters available
[    0.115000] workingset: timestamp_bits=30 max_order=15 bucket_order=0
[    0.116000] fuse init (API version 7.26)
[    0.127000] io scheduler noop registered (default)
[    0.142000] GPIO line 85 (pinctrl_rs485_re_gpio) hogged as output/high
[    0.143000] pinctrl-at91-pio4 fc038000.pinctrl: atmel pinctrl initialized
[    0.150000] f8020000.serial: ttyS0 at MMIO 0xf8020000 (irq = 32, base_baud = 5187500) is a ATMEL_SERIAL
[    0.602000] console [ttyS0] enabled
[    0.618000] brd: module loaded
[    0.631000] loop: module loaded
[    0.636000] atmel_usart fc014200.rs485: Using FIFO (64 data)
[    0.642000] fc014200.rs485: ttyS1 at MMIO 0xfc014200 (irq = 173, base_baud = 5187500) is a ATMEL_SERIAL
[    0.653000] atmel_spi f8000000.spi: Using dma0chan0 (tx) and dma0chan1 (rx) for DMA transfers
[    0.662000] atmel_spi f8000000.spi: Using FIFO (16 data)
[    0.669000] atmel_spi f8000000.spi: Atmel SPI Controller version 0x311 at 0xf8000000 (irq 26)
[    0.679000] atmel_spi fc000000.spi: Using dma0chan2 (tx) and dma0chan3 (rx) for DMA transfers
[    0.687000] random: fast init done
[    0.691000] atmel_spi fc000000.spi: Using FIFO (16 data)
[    0.697000] atmel_spi fc000000.spi: Atmel SPI Controller version 0x311 at 0xfc000000 (irq 36)
[    0.707000] libphy: Fixed MDIO Bus: probed
[    0.714000] libphy: MACB_mii_bus: probed
[    0.777000] Micrel KSZ8081 or KSZ8091 f8008000.etherne:01: attached PHY driver [Micrel KSZ8081 or KSZ8091] (mii_bus:phy_addr=f8008000.etherne:01, irq=118)
[    0.791000] macb f8008000.ethernet eth0: Cadence GEM rev 0x00020203 at 0xf8008000 irq 27 (fc:c2:3d:03:4f:0a)
[    0.806000] ieee802154fakelb ieee802154fakelb: added ieee802154 hardware
[    0.814000] at86rf230 spi32765.0: Non-Atmel dev found (MAN_ID 00 00)
[    0.821000] at86rf230: probe of spi32765.0 failed with error -22
[    0.828000] rtc rtc0: alarm rollover not handled
[    0.833000] rtc rtc0: invalid alarm value: 1900-1-1 0:0:0
[    0.839000] at91_rtc f80480b0.rtc: rtc core: registered f80480b0.rtc as rtc0
[    0.846000] at91_rtc f80480b0.rtc: AT91 Real Time Clock driver.
[    0.853000] i2c /dev entries driver
[    0.856000] Driver for 1-wire Dallas network protocol.
[    0.863000] AT91: Starting after software reset
[    0.869000] sdhci: Secure Digital Host Controller Interface driver
[    0.876000] sdhci: Copyright(c) Pierre Ossman
[    0.880000] sdhci-pltfm: SDHCI platform and OF driver helper
[    0.887000] sdhci-at91 a0000000.sdio-host: update clk mul to 39 as gck rate is 480000000 Hz
[    0.932000] mmc0: SDHCI controller on a0000000.sdio-host [a0000000.sdio-host] using ADMA
[    0.946000] sdhci-at91 b0000000.sdio-host: update clk mul to 39 as gck rate is 480000000 Hz
[    0.992000] mmc1: SDHCI controller on b0000000.sdio-host [b0000000.sdio-host] using ADMA
[    1.020000] NET: Registered protocol family 10
[    1.036000] sit: IPv6, IPv4 and MPLS over IPv4 tunneling driver
[    1.044000] NET: Registered protocol family 17
[    1.049000] can: controller area network core (rev 20120528 abi 9)
[    1.055000] NET: Registered protocol family 29
[    1.067000] mmc0: new high speed MMC card at address 0001
[    1.073000] NET: Registered protocol family 36
[    1.074000] Key type dns_resolver registered
[    1.094000] mmc1: new high speed SD card at address 1234
[    1.098000] mmcblk1: mmc1:1234 SA02G 1.84 GiB 
[    1.106000]  mmcblk1: p1 p2 p3
[    1.122000] at91_i2c f8028000.i2c: can't get DMA channel, continue without DMA support
[    1.130000] mmcblk0: mmc0:0001 Q2J54A 1.80 GiB 
[    1.131000] mmcblk0boot0: mmc0:0001 Q2J54A partition 1 16.0 MiB
[    1.136000] mmcblk0boot1: mmc0:0001 Q2J54A partition 2 16.0 MiB
[    1.137000] mmcblk0rpmb: mmc0:0001 Q2J54A partition 3 512 KiB
[    1.158000] at91_i2c f8028000.i2c: Using FIFO (16 data)
[    1.164000]  mmcblk0: p1 p2 p3 p4 < p5 p6 p7 p8 >
[    1.171000] at91_i2c f8028000.i2c: AT91 i2c bus driver (hw version: 0x704).
[    1.186000] at91_i2c fc028000.i2c: can't get DMA channel, continue without DMA support
[    1.194000] at91_i2c fc028000.i2c: Using FIFO (16 data)
[    1.206000] at91_i2c fc028000.i2c: AT91 i2c bus driver (hw version: 0x704).
[    1.213000] at91_rtc f80480b0.rtc: setting system clock to 2012-01-01 00:10:46 UTC (1325376646)
[    1.232000] EXT4-fs (mmcblk0p2): mounted filesystem with ordered data mode. Opts: (null)
[    1.241000] VFS: Mounted root (ext4 filesystem) readonly on device 179:14.
[    1.253000] devtmpfs: mounted
[    1.266000] Freeing unused kernel memory: 1024K
[    1.489000] systemd[1]: System time before build time, advancing clock.
[    1.532000] systemd[1]: systemd 232 running in system mode. (-PAM -AUDIT -SELINUX -IMA -APPARMOR -SMACK +SYSVINIT +UTMP -LIBCRYPTSETUP -GCRYPT -GNUTLS -ACL -XZ -LZ4 -SECCOMP +BLKID -ELFUTILS +KMOD -IDN)
[    1.552000] systemd[1]: Detected architecture arm.
[    1.567000] systemd[1]: Set hostname to <board>.
[    1.582000] systemd[1]: Initializing machine ID from random generator.
[    1.589000] systemd[1]: Installed transient /etc/machine-id file.
[    2.447000] systemd[1]: Started Dispatch Password Requests to Console Directory Watch.
[    2.467000] systemd[1]: Listening on Syslog Socket.
[    2.481000] systemd[1]: Listening on Journal Socket (/dev/log).
[    2.497000] systemd[1]: Started Forward Password Requests to Wall Directory Watch.
[    2.517000] systemd[1]: Reached target Remote File Systems.
[    4.373000] EXT4-fs (mmcblk0p2): re-mounted. Opts: (null)
[    5.248000] EXT4-fs (mmcblk0p8): mounted filesystem with ordered data mode. Opts: (null)
[    6.376000] systemd-journald[100]: Received request to flush runtime journal from PID 1
[    8.975000] random: crng init done
[   11.023000] EXT4-fs (mmcblk0boot0): mounted filesystem without journal. Opts: (null)
[   11.369000] EXT4-fs (mmcblk0p3): mounted filesystem without journal. Opts: (null)
[   14.016000] IPv6: ADDRCONF(NETDEV_UP): eth0: link is not ready
[   17.012000] macb f8008000.ethernet eth0: link up (100/Full)
[   17.024000] IPv6: ADDRCONF(NETDEV_CHANGE): eth0: link becomes ready
blue_z
Location: USA
Posts: 1704
Joined: Thu Apr 19, 2007 10:15 pm

Re: Trouble using at91-sama5d2_adc driver

Wed Feb 14, 2018 12:33 am

PeterT wrote:I'm assuming that even if the hardware device isn't responding, there should be some message to that effect because I declare the device in the DTS.
No, that's an invalid assumption.

PeterT wrote: This would lead me to believe there is a problem with the device tree, the driver, or the kernel. Certainly the most likely is the device tree.
There's a section in "How To Ask Questions The Smart Way" about the appropriateness of providing your guesses and assumptions.

A quick inspection of the ADC driver indicates that there are about a dozen possibly silent error returns from probe().
You could hack the driver, and make every return from probe() verbose with a dev_err() output.
Or the Q&D hack is to boot with "initcall_debug" and "ignore_loglevel" in the kernel command line (e.g. the bootargs environment variable in U-Boot). This should indicate whether the init (and probe) of the ADC driver was executed or not, and reveal any return code.


Regards
PeterT
Posts: 17
Joined: Tue Jun 21, 2016 12:03 am

Re: Trouble using at91-sama5d2_adc driver

Thu Feb 15, 2018 8:39 pm

Using your recommendations, blue_z, (ultimately adding dev_err calls to the driver) I found that the pmic was not getting initialized properly and so the ADC driver was failing due to unsuccessful returns from requesting regulator information. Thank you very much for your help on this issue.

Return to “LINUX”

Who is online

Users browsing this forum: No registered users and 2 guests