Using atmel,tcb-pwm for PWM-LEDs

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

Moderator: nferre

Cyberian
Posts: 21
Joined: Wed Sep 06, 2006 3:06 pm

Using atmel,tcb-pwm for PWM-LEDs

Thu Oct 25, 2018 3:34 pm

I have trouble getting my PWM-LEDs configured and working.

At the moment I'm using linux4sam 5.8 for a customised board based on the SAMA5D27-SOM1-EK.
With the help of the devmem tool I'm sure that the pins and timers are correctly configured but the signal on the pin does not change even if I set the brightness to 127 in sysfs for 50% duty cycle.
If I then use devmem to change TC_CMR to use TIMER2_CLOCK (system bus clock / 8 ) I finally get my PWM signal but of course the period is wrong. So far I'm pretty sure GCLK is not configured correctly but I don't know how to do it with linux.

What am I missing to get it working?

My DTS file

Code: Select all

/*
 * at91-sama5d27_som1_ek_custom.dts - Device Tree file for SAMA5D27 SOM1 EK based board
 *
 *  Copyright (c) 2017, Microchip Technology Inc.
 *                2016 Nicolas Ferre <nicolas.ferre@atmel.com>
 *                2017 Cristian Birsan <cristian.birsan@microchip.com>
 *                2017 Claudiu Beznea <claudiu.beznea@microchip.com>
 *                2018 Matthias Wieloch <matthias.wieloch@few-bauer.de>
 *
 * This file is dual-licensed: you can use it either under the terms
 * of the GPL or the X11 license, at your option. Note that this dual
 * licensing only applies to this file, and not this project as a
 * whole.
 *
 *  a) This file is free software; you can redistribute it and/or
 *     modify it under the terms of the GNU General Public License as
 *     published by the Free Software Foundation; either version 2 of the
 *     License, or (at your option) any later version.
 *
 *     This file is distributed in the hope that it will be useful,
 *     but WITHOUT ANY WARRANTY; without even the implied warranty of
 *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *     GNU General Public License for more details.
 *
 * Or, alternatively,
 *
 *  b) Permission is hereby granted, free of charge, to any person
 *     obtaining a copy of this software and associated documentation
 *     files (the "Software"), to deal in the Software without
 *     restriction, including without limitation the rights to use,
 *     copy, modify, merge, publish, distribute, sublicense, and/or
 *     sell copies of the Software, and to permit persons to whom the
 *     Software is furnished to do so, subject to the following
 *     conditions:
 *
 *     The above copyright notice and this permission notice shall be
 *     included in all copies or substantial portions of the Software.
 *
 *     THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 *     EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
 *     OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 *     NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 *     HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
 *     WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 *     FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 *     OTHER DEALINGS IN THE SOFTWARE.
 */
/dts-v1/;
#include "sama5d2.dtsi"
#include "sama5d2-pinfunc.h"
#include <dt-bindings/mfd/atmel-flexcom.h>
#include <dt-bindings/gpio/gpio.h>
#include <dt-bindings/pinctrl/at91.h>
#include <dt-bindings/pwm/pwm.h>

/ {
	model = "Based on SAMA5D27 SOM1 EK";
	compatible = "atmel,sama5d27-som1-ek", "atmel,sama5d27-som1", "atmel,sama5d27", "atmel,sama5d2", "atmel,sama5";

	aliases {
		dbgu = &uart1;
		com1 = &flx0;	/* COM1 */
		com2 = &flx2;	/* COM2 */
		com3 = &flx3;	/* COM3 */
		i2c0 = &i2c0;
	};

	chosen {
		stdout-path = "dbgu:115200n8";
	};
	
	clocks {
		slow_xtal {
			clock-frequency = <32768>;
		};

		main_xtal {
			clock-frequency = <24000000>;
		};
	};

	ahb {
		usb1: ohci@00400000 {
			num-ports = <3>;
			atmel,vbus-gpio = <&pioA PIN_PD5 GPIO_ACTIVE_LOW 
					   &pioA PIN_PD7 GPIO_ACTIVE_LOW
					   0
					  >;
			pinctrl-names = "default";
			pinctrl-0 = <&pinctrl_usb_default>;
			status = "okay";
		};

		sdmmc1: sdio-host@b0000000 {
			bus-width = <4>;
			pinctrl-names = "default";
			pinctrl-0 = <&pinctrl_sdmmc1_default>;
			status = "okay";
		};

		apb {
		
			com1: flexcom@f8034000 {
				atmel,flexcom-mode = <ATMEL_FLEXCOM_MODE_USART>;
				status = "okay";

				uart5: serial@200 {
					compatible = "atmel,at91sam9260-usart";
					reg = <0x200 0x200>;
					interrupts = <19 IRQ_TYPE_LEVEL_HIGH 7>;
					clocks = <&flx0_clk>;
					clock-names = "usart";
					pinctrl-names = "default";
					pinctrl-0 = <&pinctrl_com1_default>;
					atmel,fifo-size = <32>;
					status = "okay";
				};
			};
			
			com2: flexcom@fc010000 {
				atmel,flexcom-mode = <ATMEL_FLEXCOM_MODE_USART>;
				status = "okay";

				uart6: serial@200 {
					compatible = "atmel,at91sam9260-usart";
					reg = <0x200 0x200>;
					interrupts = <21 IRQ_TYPE_LEVEL_HIGH 7>;
					clocks = <&flx2_clk>;
					clock-names = "usart";
					pinctrl-names = "default";
					pinctrl-0 = <&pinctrl_com2_default>;
					atmel,fifo-size = <32>;
					status = "okay";
				};
			};
			
			com3: flexcom@fc014000 {
				atmel,flexcom-mode = <ATMEL_FLEXCOM_MODE_USART>;
				status = "okay";

				uart7: serial@200 {
					compatible = "atmel,at91sam9260-usart";
					reg = <0x200 0x200>;
					interrupts = <22 IRQ_TYPE_LEVEL_HIGH 7>;
					clocks = <&flx3_clk>;
					clock-names = "usart";
					pinctrl-names = "default";
					pinctrl-0 = <&pinctrl_com3_default>;
					atmel,fifo-size = <32>;
					status = "okay";
				};
			};

			macb0: ethernet@f8008000 {
				pinctrl-names = "default";
				pinctrl-0 = <&pinctrl_macb0_default>;
				phy-mode = "rmii";
				
				status = "okay";

				ethernet-phy@0 {
					reg = <0x0>;
					interrupt-parent = <&pioA>;
					interrupts = <PIN_PB24 IRQ_TYPE_LEVEL_LOW>;
					pinctrl-names = "default";
					pinctrl-0 = <&pinctrl_macb0_phy_irq>;
				};
			};

			dbgu: serial@f8020000 {
				pinctrl-names = "default";
				pinctrl-0 = <&pinctrl_dbgu_default>;
				atmel,use-dma-rx;
				atmel,use-dma-tx;
				status = "okay";
			};
			
			i2c0: i2c@f8028000 {
				dmas = <0>, <0>;
				pinctrl-names = "default";
				pinctrl-0 = <&pinctrl_i2c0_default>;
				status = "okay";

				at24@50 {
					compatible = "at24,24c256";
					reg = <0x50>;
					pagesize = <64>;
				};
			};

			/*watchdog@f8048040 {
				status = "okay";
			};*/

			pinctrl@fc038000 {
			
				pinctrl_i2c0_default: i2c0_default {
					pinmux = <PIN_PD21__TWD0>,
						 <PIN_PD22__TWCK0>;
					bias-disable;
				};

				pinctrl_led_gpio_default: led_gpio_default {
					pinmux = <PIN_PB1__GPIO>,
						 <PIN_PA31__GPIO>;
					bias-pull-up;
				};

				pinctrl_sdmmc1_default: sdmmc1_default {
					cmd_data {
						pinmux = <PIN_PA28__SDMMC1_CMD>,
							 <PIN_PA18__SDMMC1_DAT0>,
							 <PIN_PA19__SDMMC1_DAT1>,
							 <PIN_PA20__SDMMC1_DAT2>,
							 <PIN_PA21__SDMMC1_DAT3>;
						bias-disable;
					};

					conf-ck_cd {
						pinmux = <PIN_PA22__SDMMC1_CK>,
							 <PIN_PA30__SDMMC1_CD>;
						bias-disable;
					};
				};

				pinctrl_dbgu_default: uart1_default {
					pinmux = <PIN_PD2__URXD1>,
						 <PIN_PD3__UTXD1>;
					bias-disable;
				};

				pinctrl_usb_default: usb_default {
					pinmux = <PIN_PD7__GPIO>,
						 <PIN_PD8__GPIO>,
						 <PIN_PD5__GPIO>,
						 <PIN_PD6__GPIO>;
					bias-disable;
				};

				pinctrl_macb0_default: macb0_default {
					pinmux = <PIN_PB14__GTXCK>,
						 <PIN_PB15__GTXEN>,
						 <PIN_PB16__GRXDV>,
						 <PIN_PB17__GRXER>,
						 <PIN_PB18__GRX0>,
						 <PIN_PB19__GRX1>,
						 <PIN_PB20__GTX0>,
						 <PIN_PB21__GTX1>,
						 <PIN_PB22__GMDC>,
						 <PIN_PB23__GMDIO>;
					bias-disable;
				};
				
				pinctrl_macb0_phy_irq: macb0_phy_irq {
					pinmux = <PIN_PB24__GPIO>;
					bias-disable;
				};
				
				pinctrl_com1_default: com1_default {
					pinmux = <PIN_PB28__FLEXCOM0_IO0>,
						 <PIN_PB29__FLEXCOM0_IO1>,
						 <PIN_PB31__FLEXCOM0_IO3>,
						 <PIN_PC0__FLEXCOM0_IO4>;
					bias-disable;
				};
				
				pinctrl_com2_default: com2_default {
					pinmux = <PIN_PD26__FLEXCOM2_IO0>,
						 <PIN_PD27__FLEXCOM2_IO1>,
						 <PIN_PD29__FLEXCOM2_IO3>,
						 <PIN_PD30__FLEXCOM2_IO4>;
					bias-disable;
				};
				
				pinctrl_com3_default: com3_default {
					pinmux = <PIN_PA15__FLEXCOM3_IO0>,
						 <PIN_PA13__FLEXCOM3_IO1>,
						 <PIN_PA16__FLEXCOM3_IO3>,
						 <PIN_PA17__FLEXCOM3_IO4>;
					bias-disable;
				};
				
				pinctrl_isaclks_default: isaclks_default {
					pinmux = <PIN_PA27__TIOA1>,
						 <PIN_PC10__TIOB4>,
						 <PIN_PD20__TIOA2>;
					bias-disable;
				};
			};
		};
	};

	leds {
		compatible = "gpio-leds";
		pinctrl-names = "default";
		pinctrl-0 = <&pinctrl_led_gpio_default>;
		status = "okay";

		red {
			label = "red";
			gpios = <&pioA PIN_PA31 GPIO_ACTIVE_LOW>;
			linux,default-trigger = "default-on";
		};

		green {
			label = "green";
			gpios = <&pioA PIN_PB1 GPIO_ACTIVE_LOW>;
			linux,default-trigger = "heartbeat";
		};
	};

	pwm-leds {
		compatible = "pwm-leds";

		isa_clk0 {
			label = "pwm:isa:clk0";
			pwms = <&tcb_pwm 2 10000000 PWM_POLARITY_INVERTED>;
			max-brightness = <255>;
			linux,default-trigger = "default-on";
		};
	};

	tcb_pwm: pwm {
		compatible = "atmel,tcb-pwm";
		#pwm-cells = <3>;
		tc-block = <0>;
		pinctrl-names = "default";
		pinctrl-0 = <&pinctrl_isaclks_default>;
	};
};
My kernel config (defconfig)

Code: Select all

# CONFIG_SWAP is not set
CONFIG_SYSVIPC=y
CONFIG_POSIX_MQUEUE=y
CONFIG_IRQ_DOMAIN_DEBUG=y
CONFIG_NO_HZ_IDLE=y
CONFIG_HIGH_RES_TIMERS=y
CONFIG_LOG_BUF_SHIFT=16
CONFIG_CGROUPS=y
CONFIG_MEMCG=y
CONFIG_CGROUP_SCHED=y
CONFIG_CFS_BANDWIDTH=y
CONFIG_RT_GROUP_SCHED=y
CONFIG_CGROUP_FREEZER=y
CONFIG_CGROUP_DEVICE=y
CONFIG_CGROUP_CPUACCT=y
CONFIG_NAMESPACES=y
CONFIG_USER_NS=y
CONFIG_BLK_DEV_INITRD=y
# CONFIG_KALLSYMS is not set
CONFIG_EMBEDDED=y
CONFIG_SLAB=y
CONFIG_JUMP_LABEL=y
CONFIG_MODULES=y
CONFIG_MODULE_FORCE_LOAD=y
CONFIG_MODULE_UNLOAD=y
CONFIG_MODULE_FORCE_UNLOAD=y
CONFIG_MODVERSIONS=y
# CONFIG_BLK_DEV_BSG is not set
# CONFIG_IOSCHED_DEADLINE is not set
# CONFIG_IOSCHED_CFQ is not set
CONFIG_ARCH_AT91=y
CONFIG_SOC_SAMA5D2=y
CONFIG_HZ_1000=y
CONFIG_AEABI=y
CONFIG_CMA=y
CONFIG_CMA_DEBUGFS=y
CONFIG_FORCE_MAX_ZONEORDER=15
CONFIG_UACCESS_WITH_MEMCPY=y
# CONFIG_ATAGS is not set
CONFIG_ZBOOT_ROM_TEXT=0x0
CONFIG_ZBOOT_ROM_BSS=0x0
CONFIG_CMDLINE="console=ttyS0,115200 initrd=0x21100000,25165824 root=/dev/ram0 rw"
CONFIG_KEXEC=y
CONFIG_CPU_IDLE=y
CONFIG_VFP=y
CONFIG_NEON=y
CONFIG_KERNEL_MODE_NEON=y
# CONFIG_CORE_DUMP_DEFAULT_ELF_HEADERS is not set
CONFIG_PM_DEBUG=y
CONFIG_PM_ADVANCED_DEBUG=y
CONFIG_NET=y
CONFIG_PACKET=y
CONFIG_UNIX=y
CONFIG_INET=y
CONFIG_IP_MULTICAST=y
CONFIG_IP_PNP=y
CONFIG_IP_PNP_DHCP=y
# CONFIG_INET_XFRM_MODE_TRANSPORT is not set
# CONFIG_INET_XFRM_MODE_TUNNEL is not set
# CONFIG_INET_XFRM_MODE_BEET is not set
# CONFIG_INET_DIAG is not set
# CONFIG_INET6_XFRM_MODE_TRANSPORT is not set
# CONFIG_INET6_XFRM_MODE_TUNNEL is not set
# CONFIG_INET6_XFRM_MODE_BEET is not set
CONFIG_IPV6_SIT_6RD=y
CONFIG_NETFILTER=y
CONFIG_IP_NF_IPTABLES=y
CONFIG_IP_NF_FILTER=y
CONFIG_CAN=y
CONFIG_CAN_M_CAN=y
# CONFIG_WIRELESS is not set
CONFIG_RFKILL_REGULATOR=y
# CONFIG_UEVENT_HELPER is not set
CONFIG_DEVTMPFS=y
CONFIG_DEVTMPFS_MOUNT=y
# CONFIG_STANDALONE is not set
# CONFIG_PREVENT_FIRMWARE_BUILD is not set
CONFIG_DMA_CMA=y
CONFIG_BLK_DEV_LOOP=y
CONFIG_BLK_DEV_RAM=y
CONFIG_BLK_DEV_RAM_COUNT=4
CONFIG_BLK_DEV_RAM_SIZE=8192
CONFIG_ATMEL_TCLIB=y
# CONFIG_ATMEL_TCB_CLKSRC is not set
CONFIG_EEPROM_AT24=y
CONFIG_NETDEVICES=y
# CONFIG_NET_VENDOR_AMAZON is not set
# CONFIG_NET_VENDOR_ARC is not set
CONFIG_MACB=y
# CONFIG_NET_VENDOR_BROADCOM is not set
# CONFIG_NET_VENDOR_CIRRUS is not set
# CONFIG_NET_VENDOR_EZCHIP is not set
# CONFIG_NET_VENDOR_FARADAY is not set
# CONFIG_NET_VENDOR_HISILICON is not set
# CONFIG_NET_VENDOR_INTEL is not set
# CONFIG_NET_VENDOR_MARVELL is not set
# CONFIG_NET_VENDOR_MICREL is not set
# CONFIG_NET_VENDOR_NATSEMI is not set
# CONFIG_NET_VENDOR_NETRONOME is not set
# CONFIG_NET_VENDOR_QUALCOMM is not set
# CONFIG_NET_VENDOR_RENESAS is not set
# CONFIG_NET_VENDOR_ROCKER is not set
# CONFIG_NET_VENDOR_SAMSUNG is not set
# CONFIG_NET_VENDOR_SEEQ is not set
# CONFIG_NET_VENDOR_SMSC is not set
# CONFIG_NET_VENDOR_STMICRO is not set
# CONFIG_NET_VENDOR_SYNOPSYS is not set
# CONFIG_NET_VENDOR_VIA is not set
# CONFIG_NET_VENDOR_WIZNET is not set
CONFIG_MICREL_PHY=y
# CONFIG_USB_NET_DRIVERS is not set
# CONFIG_WLAN is not set
# CONFIG_INPUT_MOUSEDEV is not set
CONFIG_INPUT_EVDEV=y
# CONFIG_KEYBOARD_ATKBD is not set
CONFIG_KEYBOARD_GPIO=y
# CONFIG_INPUT_MOUSE is not set
# CONFIG_SERIO is not set
CONFIG_LEGACY_PTY_COUNT=4
CONFIG_SERIAL_ATMEL=y
CONFIG_SERIAL_ATMEL_CONSOLE=y
CONFIG_HW_RANDOM=y
CONFIG_I2C=y
CONFIG_I2C_CHARDEV=y
CONFIG_I2C_AT91=y
CONFIG_I2C_GPIO=y
CONFIG_PINCTRL_AT91=y
CONFIG_GPIO_SYSFS=y
CONFIG_POWER_RESET=y
CONFIG_POWER_SUPPLY=y
# CONFIG_HWMON is not set
CONFIG_WATCHDOG=y
CONFIG_AT91SAM9X_WATCHDOG=y
CONFIG_SAMA5D4_WATCHDOG=y
CONFIG_MFD_ATMEL_FLEXCOM=y
CONFIG_REGULATOR=y
CONFIG_REGULATOR_FIXED_VOLTAGE=y
CONFIG_REGULATOR_VIRTUAL_CONSUMER=y
CONFIG_FB=y
CONFIG_USB=y
CONFIG_USB_ANNOUNCE_NEW_DEVICES=y
CONFIG_USB_EHCI_HCD=y
CONFIG_USB_OHCI_HCD=y
CONFIG_MMC=y
# CONFIG_MMC_BLOCK_BOUNCE is not set
CONFIG_MMC_SDHCI=y
CONFIG_MMC_SDHCI_PLTFM=y
CONFIG_MMC_SDHCI_OF_AT91=y
CONFIG_MMC_ATMELMCI=y
CONFIG_NEW_LEDS=y
CONFIG_LEDS_CLASS=y
CONFIG_LEDS_GPIO=y
CONFIG_LEDS_PWM=y
CONFIG_LEDS_REGULATOR=y
CONFIG_LEDS_TRIGGERS=y
CONFIG_LEDS_TRIGGER_TIMER=y
CONFIG_LEDS_TRIGGER_HEARTBEAT=y
CONFIG_LEDS_TRIGGER_CPU=y
CONFIG_LEDS_TRIGGER_GPIO=y
CONFIG_LEDS_TRIGGER_DEFAULT_ON=y
CONFIG_RTC_CLASS=y
CONFIG_RTC_DRV_AT91RM9200=y
CONFIG_DMADEVICES=y
CONFIG_AT_HDMAC=y
CONFIG_AT_XDMAC=y
# CONFIG_IOMMU_SUPPORT is not set
CONFIG_PWM=y
CONFIG_PWM_ATMEL_TCB=y
CONFIG_EXT4_FS=y
CONFIG_FANOTIFY=y
CONFIG_OVERLAY_FS=y
CONFIG_VFAT_FS=y
CONFIG_TMPFS=y
CONFIG_CONFIGFS_FS=y
CONFIG_NFS_FS=y
CONFIG_NFS_V4=y
CONFIG_ROOT_NFS=y
CONFIG_NLS_CODEPAGE_437=y
CONFIG_NLS_CODEPAGE_850=y
CONFIG_NLS_ISO8859_1=y
CONFIG_NLS_UTF8=y
CONFIG_STRIP_ASM_SYMS=y
CONFIG_DEBUG_FS=y
CONFIG_DEBUG_MEMORY_INIT=y
# CONFIG_SCHED_DEBUG is not set
# CONFIG_FTRACE is not set
CONFIG_DEBUG_USER=y
CONFIG_CRYPTO_CCM=y
CONFIG_CRYPTO_GCM=y
CONFIG_CRYPTO_ECHAINIV=y
CONFIG_CRYPTO_ARC4=y
CONFIG_CRYPTO_DEFLATE=y
CONFIG_CRYPTO_LZO=y
CONFIG_CRYPTO_USER_API_HASH=y
CONFIG_CRYPTO_USER_API_SKCIPHER=y
CONFIG_CRYPTO_DEV_ATMEL_AES=y
CONFIG_CRYPTO_DEV_ATMEL_TDES=y
CONFIG_CRYPTO_DEV_ATMEL_SHA=y
CONFIG_CRC_CCITT=y
CONFIG_CRC_ITU_T=y
Cyberian
Posts: 21
Joined: Wed Sep 06, 2006 3:06 pm

Re: Using atmel,tcb-pwm for PWM-LEDs

Fri Nov 02, 2018 2:42 pm

meanwhile I switched to linux4sam_6.0 but still have the same problem.

Return to “LINUX”

Who is online

Users browsing this forum: No registered users and 2 guests