How to work with gpio in linux under PowerPc.

There should be an option in the kernel - CONFIG_GPIO_SYSFS

Control of gpio in PowerPc is available via /sys/class/gpio/ as for processors of other architectures.

The difference is that PowerPc needs the Flattened Device Tree file with describing of the hardware part.

The section with describing of the gpio should look like the following in the file:

		par_io@1400 {
			#address-cells = <0x1>;
			#size-cells = <0x1>;
			reg = <0x1400 0x100>;
			ranges = <0x0 0x1400 0x100>;
			device_type = "par_io";
			num-ports = <0x7>;

			qe_pio_a: gpio-controller@0 {
				#gpio-cells = <0x2>;
				compatible = "fsl,mpc8360-qe-pario-bank", "fsl,mpc8323-qe-pario-bank";
				reg = <0x0 0x18>;
				gpio-controller;
			};

			qe_pio_b: gpio-controller@18 {
				#gpio-cells = <0x2>;
				compatible = "fsl,mpc8360-qe-pario-bank", "fsl,mpc8323-qe-pario-bank";
				reg = <0x18 0x18>;
				gpio-controller;
			};
			qe_pio_g: gpio-controller@90 {
				#gpio-cells = <0x2>;
				compatible = "fsl,mpc8360-qe-pario-bank", "fsl,mpc8323-qe-pario-bank";
				reg = <0x90 0x18>;
				gpio-controller;
			};

			/* port  pin  dir  open_drain  assignment  has_irq */
			pio1: ucc_pin@01 {
				pio-map = 
				<0x0 0x3 0x1 0x0 0x1 0x0
				 0x0 0x4 0x1 0x0 0x1 0x0 
				 0x0 0x5 0x1 0x0 0x1 0x0 
				 0x0 0x6 0x1 0x0 0x1 0x0 
				 0x0 0x8 0x1 0x0 0x0 0x0 
				 0x0 0x9 0x2 0x0 0x1 0x0 
				 0x0 0xa 0x2 0x0 0x1 0x0 
				 0x0 0xb 0x2 0x0 0x1 0x0 
				 0x0 0xc 0x2 0x0 0x1 0x0 
				 0x0 0x7 0x1 0x0 0x1 0x0 
				 0x0 0xf 0x2 0x0 0x1 0x0 
				 0x0 0x0 0x2 0x0 0x1 0x0 
				 0x2 0x8 0x2 0x0 0x1 0x0 
				 0x1 0x9 0x1 0x0 0x0 0x0 
				 0x1 0xa 0x2 0x0 0x1 0x0 
				 0x1 0xb 0x2 0x0 0x1 0x0>;
			};
			
			/* port  pin  dir  open_drain  assignment  has_irq */
			pio2: ucc_pin@02 {
				pio-map =
				<0x1 0x0e 0x1 0x0 0x1 0x0
				 0x1 0x0f 0x1 0x0 0x1 0x0
				 0x1 0x10 0x1 0x0 0x1 0x0
				 0x1 0x11 0x1 0x0 0x1 0x0 
				 0x1 0x14 0x2 0x0 0x1 0x0 
				 0x1 0x15 0x2 0x0 0x1 0x0 
				 0x1 0x16 0x2 0x0 0x1 0x0 
				 0x1 0x17 0x2 0x0 0x1 0x0 
				 0x1 0x12 0x1 0x0 0x1 0x0 
				 0x1 0x13 0x1 0x0 0x0 0x0 
				 0x1 0x1a 0x2 0x0 0x1 0x0 
				 0x1 0x1b 0x2 0x0 0x1 0x0 
				 0x1 0x18 0x2 0x0 0x1 0x0 
				 0x1 0x19 0x2 0x0 0x1 0x0 
				 0x2 0x06 0x2 0x0 0x1 0x0 
				 0x2 0x07 0x2 0x0 0x1 0x0 
				 0x0 0x01 0x3 0x0 0x2 0x0 
				 0x0 0x02 0x1 0x0 0x1 0x0
				 0x6 0x00 0x1 0x0 0x1 0x0
				 0x6 0x01 0x1 0x0 0x1 0x0
				 0x6 0x02 0x1 0x0 0x1 0x0
				 0x6 0x03 0x1 0x0 0x1 0x0
				 >;
				linux,phandle = <0x4>;
			};
		};

where par_io@1400 - is a basic address gpio according to the datasheet
gpio-controller@18 - offset for each port
reg = <0x90 0x18>; - offset and size of the port

According to the messages in this file there will be created the files gpiochip160, gpiochip192, gpiochip224

for gpio access:

root@OpenWrt:/# ls -l /sys/class/gpio/
--w-------    1 root     root          4096 Jan  1 00:00 export
lrwxrwxrwx    1 root     root             0 Jan  1 00:00 gpiochip160
lrwxrwxrwx    1 root     root             0 Jan  1 00:00 gpiochip192
lrwxrwxrwx    1 root     root             0 Jan  1 00:00 gpiochip224
--w-------    1 root     root          4096 Jan  1 00:00 unexport

Working with gpio on PowerPc as usual:
1. create a file for a specific gpio ( 232=224 + 8(pin for each port) ):

root@OpenWrt:/# echo 232 >sys/class/gpio/export

2. pin configuration as output:

root@OpenWrt:/# echo 'out' > /sys/class/gpio/gpio232/direction

or pin configuration as input:

root@OpenWrt:/# echo 'in' > /sys/class/gpio/gpio232/direction

3. write pin value:

root@OpenWrt:/# echo 1 > /sys/class/gpio/gpio232/value

or read the pin content:

cat /sys/class/gpio/gpio232/value