| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * arch/powerpc/sysdev/qe_lib/qe_io.c |
|---|
| 3 | 4 | * |
|---|
| .. | .. |
|---|
| 7 | 8 | * |
|---|
| 8 | 9 | * Author: Li Yang <LeoLi@freescale.com> |
|---|
| 9 | 10 | * Based on code from Shlomi Gridish <gridish@freescale.com> |
|---|
| 10 | | - * |
|---|
| 11 | | - * This program is free software; you can redistribute it and/or modify it |
|---|
| 12 | | - * under the terms of the GNU General Public License as published by the |
|---|
| 13 | | - * Free Software Foundation; either version 2 of the License, or (at your |
|---|
| 14 | | - * option) any later version. |
|---|
| 15 | 11 | */ |
|---|
| 16 | 12 | |
|---|
| 17 | 13 | #include <linux/stddef.h> |
|---|
| .. | .. |
|---|
| 22 | 18 | |
|---|
| 23 | 19 | #include <asm/io.h> |
|---|
| 24 | 20 | #include <soc/fsl/qe/qe.h> |
|---|
| 25 | | -#include <asm/prom.h> |
|---|
| 26 | | -#include <sysdev/fsl_soc.h> |
|---|
| 27 | 21 | |
|---|
| 28 | 22 | #undef DEBUG |
|---|
| 29 | 23 | |
|---|
| .. | .. |
|---|
| 34 | 28 | { |
|---|
| 35 | 29 | struct resource res; |
|---|
| 36 | 30 | int ret; |
|---|
| 37 | | - const u32 *num_ports; |
|---|
| 31 | + u32 num_ports; |
|---|
| 38 | 32 | |
|---|
| 39 | 33 | /* Map Parallel I/O ports registers */ |
|---|
| 40 | 34 | ret = of_address_to_resource(np, 0, &res); |
|---|
| 41 | 35 | if (ret) |
|---|
| 42 | 36 | return ret; |
|---|
| 43 | 37 | par_io = ioremap(res.start, resource_size(&res)); |
|---|
| 38 | + if (!par_io) |
|---|
| 39 | + return -ENOMEM; |
|---|
| 44 | 40 | |
|---|
| 45 | | - num_ports = of_get_property(np, "num-ports", NULL); |
|---|
| 46 | | - if (num_ports) |
|---|
| 47 | | - num_par_io_ports = *num_ports; |
|---|
| 41 | + if (!of_property_read_u32(np, "num-ports", &num_ports)) |
|---|
| 42 | + num_par_io_ports = num_ports; |
|---|
| 48 | 43 | |
|---|
| 49 | 44 | return 0; |
|---|
| 50 | 45 | } |
|---|
| .. | .. |
|---|
| 61 | 56 | pin_mask1bit = (u32) (1 << (QE_PIO_PINS - (pin + 1))); |
|---|
| 62 | 57 | |
|---|
| 63 | 58 | /* Set open drain, if required */ |
|---|
| 64 | | - tmp_val = in_be32(&par_io->cpodr); |
|---|
| 59 | + tmp_val = qe_ioread32be(&par_io->cpodr); |
|---|
| 65 | 60 | if (open_drain) |
|---|
| 66 | | - out_be32(&par_io->cpodr, pin_mask1bit | tmp_val); |
|---|
| 61 | + qe_iowrite32be(pin_mask1bit | tmp_val, &par_io->cpodr); |
|---|
| 67 | 62 | else |
|---|
| 68 | | - out_be32(&par_io->cpodr, ~pin_mask1bit & tmp_val); |
|---|
| 63 | + qe_iowrite32be(~pin_mask1bit & tmp_val, &par_io->cpodr); |
|---|
| 69 | 64 | |
|---|
| 70 | 65 | /* define direction */ |
|---|
| 71 | 66 | tmp_val = (pin > (QE_PIO_PINS / 2) - 1) ? |
|---|
| 72 | | - in_be32(&par_io->cpdir2) : |
|---|
| 73 | | - in_be32(&par_io->cpdir1); |
|---|
| 67 | + qe_ioread32be(&par_io->cpdir2) : |
|---|
| 68 | + qe_ioread32be(&par_io->cpdir1); |
|---|
| 74 | 69 | |
|---|
| 75 | 70 | /* get all bits mask for 2 bit per port */ |
|---|
| 76 | 71 | pin_mask2bits = (u32) (0x3 << (QE_PIO_PINS - |
|---|
| .. | .. |
|---|
| 82 | 77 | |
|---|
| 83 | 78 | /* clear and set 2 bits mask */ |
|---|
| 84 | 79 | if (pin > (QE_PIO_PINS / 2) - 1) { |
|---|
| 85 | | - out_be32(&par_io->cpdir2, |
|---|
| 86 | | - ~pin_mask2bits & tmp_val); |
|---|
| 80 | + qe_iowrite32be(~pin_mask2bits & tmp_val, &par_io->cpdir2); |
|---|
| 87 | 81 | tmp_val &= ~pin_mask2bits; |
|---|
| 88 | | - out_be32(&par_io->cpdir2, new_mask2bits | tmp_val); |
|---|
| 82 | + qe_iowrite32be(new_mask2bits | tmp_val, &par_io->cpdir2); |
|---|
| 89 | 83 | } else { |
|---|
| 90 | | - out_be32(&par_io->cpdir1, |
|---|
| 91 | | - ~pin_mask2bits & tmp_val); |
|---|
| 84 | + qe_iowrite32be(~pin_mask2bits & tmp_val, &par_io->cpdir1); |
|---|
| 92 | 85 | tmp_val &= ~pin_mask2bits; |
|---|
| 93 | | - out_be32(&par_io->cpdir1, new_mask2bits | tmp_val); |
|---|
| 86 | + qe_iowrite32be(new_mask2bits | tmp_val, &par_io->cpdir1); |
|---|
| 94 | 87 | } |
|---|
| 95 | 88 | /* define pin assignment */ |
|---|
| 96 | 89 | tmp_val = (pin > (QE_PIO_PINS / 2) - 1) ? |
|---|
| 97 | | - in_be32(&par_io->cppar2) : |
|---|
| 98 | | - in_be32(&par_io->cppar1); |
|---|
| 90 | + qe_ioread32be(&par_io->cppar2) : |
|---|
| 91 | + qe_ioread32be(&par_io->cppar1); |
|---|
| 99 | 92 | |
|---|
| 100 | 93 | new_mask2bits = (u32) (assignment << (QE_PIO_PINS - |
|---|
| 101 | 94 | (pin % (QE_PIO_PINS / 2) + 1) * 2)); |
|---|
| 102 | 95 | /* clear and set 2 bits mask */ |
|---|
| 103 | 96 | if (pin > (QE_PIO_PINS / 2) - 1) { |
|---|
| 104 | | - out_be32(&par_io->cppar2, |
|---|
| 105 | | - ~pin_mask2bits & tmp_val); |
|---|
| 97 | + qe_iowrite32be(~pin_mask2bits & tmp_val, &par_io->cppar2); |
|---|
| 106 | 98 | tmp_val &= ~pin_mask2bits; |
|---|
| 107 | | - out_be32(&par_io->cppar2, new_mask2bits | tmp_val); |
|---|
| 99 | + qe_iowrite32be(new_mask2bits | tmp_val, &par_io->cppar2); |
|---|
| 108 | 100 | } else { |
|---|
| 109 | | - out_be32(&par_io->cppar1, |
|---|
| 110 | | - ~pin_mask2bits & tmp_val); |
|---|
| 101 | + qe_iowrite32be(~pin_mask2bits & tmp_val, &par_io->cppar1); |
|---|
| 111 | 102 | tmp_val &= ~pin_mask2bits; |
|---|
| 112 | | - out_be32(&par_io->cppar1, new_mask2bits | tmp_val); |
|---|
| 103 | + qe_iowrite32be(new_mask2bits | tmp_val, &par_io->cppar1); |
|---|
| 113 | 104 | } |
|---|
| 114 | 105 | } |
|---|
| 115 | 106 | EXPORT_SYMBOL(__par_io_config_pin); |
|---|
| .. | .. |
|---|
| 137 | 128 | /* calculate pin location */ |
|---|
| 138 | 129 | pin_mask = (u32) (1 << (QE_PIO_PINS - 1 - pin)); |
|---|
| 139 | 130 | |
|---|
| 140 | | - tmp_val = in_be32(&par_io[port].cpdata); |
|---|
| 131 | + tmp_val = qe_ioread32be(&par_io[port].cpdata); |
|---|
| 141 | 132 | |
|---|
| 142 | 133 | if (val == 0) /* clear */ |
|---|
| 143 | | - out_be32(&par_io[port].cpdata, ~pin_mask & tmp_val); |
|---|
| 134 | + qe_iowrite32be(~pin_mask & tmp_val, &par_io[port].cpdata); |
|---|
| 144 | 135 | else /* set */ |
|---|
| 145 | | - out_be32(&par_io[port].cpdata, pin_mask | tmp_val); |
|---|
| 136 | + qe_iowrite32be(pin_mask | tmp_val, &par_io[port].cpdata); |
|---|
| 146 | 137 | |
|---|
| 147 | 138 | return 0; |
|---|
| 148 | 139 | } |
|---|
| .. | .. |
|---|
| 151 | 142 | int par_io_of_config(struct device_node *np) |
|---|
| 152 | 143 | { |
|---|
| 153 | 144 | struct device_node *pio; |
|---|
| 154 | | - const phandle *ph; |
|---|
| 155 | 145 | int pio_map_len; |
|---|
| 156 | | - const unsigned int *pio_map; |
|---|
| 146 | + const __be32 *pio_map; |
|---|
| 157 | 147 | |
|---|
| 158 | 148 | if (par_io == NULL) { |
|---|
| 159 | 149 | printk(KERN_ERR "par_io not initialized\n"); |
|---|
| 160 | 150 | return -1; |
|---|
| 161 | 151 | } |
|---|
| 162 | 152 | |
|---|
| 163 | | - ph = of_get_property(np, "pio-handle", NULL); |
|---|
| 164 | | - if (ph == NULL) { |
|---|
| 153 | + pio = of_parse_phandle(np, "pio-handle", 0); |
|---|
| 154 | + if (pio == NULL) { |
|---|
| 165 | 155 | printk(KERN_ERR "pio-handle not available\n"); |
|---|
| 166 | 156 | return -1; |
|---|
| 167 | 157 | } |
|---|
| 168 | | - |
|---|
| 169 | | - pio = of_find_node_by_phandle(*ph); |
|---|
| 170 | 158 | |
|---|
| 171 | 159 | pio_map = of_get_property(pio, "pio-map", &pio_map_len); |
|---|
| 172 | 160 | if (pio_map == NULL) { |
|---|
| .. | .. |
|---|
| 180 | 168 | } |
|---|
| 181 | 169 | |
|---|
| 182 | 170 | while (pio_map_len > 0) { |
|---|
| 183 | | - par_io_config_pin((u8) pio_map[0], (u8) pio_map[1], |
|---|
| 184 | | - (int) pio_map[2], (int) pio_map[3], |
|---|
| 185 | | - (int) pio_map[4], (int) pio_map[5]); |
|---|
| 171 | + u8 port = be32_to_cpu(pio_map[0]); |
|---|
| 172 | + u8 pin = be32_to_cpu(pio_map[1]); |
|---|
| 173 | + int dir = be32_to_cpu(pio_map[2]); |
|---|
| 174 | + int open_drain = be32_to_cpu(pio_map[3]); |
|---|
| 175 | + int assignment = be32_to_cpu(pio_map[4]); |
|---|
| 176 | + int has_irq = be32_to_cpu(pio_map[5]); |
|---|
| 177 | + |
|---|
| 178 | + par_io_config_pin(port, pin, dir, open_drain, |
|---|
| 179 | + assignment, has_irq); |
|---|
| 186 | 180 | pio_map += 6; |
|---|
| 187 | 181 | pio_map_len -= 6; |
|---|
| 188 | 182 | } |
|---|