cregit-Linux how code gets into the kernel

Release 4.11 drivers/soc/fsl/qe/qe_io.c

/*
 * arch/powerpc/sysdev/qe_lib/qe_io.c
 *
 * QE Parallel I/O ports configuration routines
 *
 * Copyright 2006 Freescale Semiconductor, Inc. All rights reserved.
 *
 * Author: Li Yang <LeoLi@freescale.com>
 * Based on code from Shlomi Gridish <gridish@freescale.com>
 *
 * This program 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.
 */

#include <linux/stddef.h>
#include <linux/kernel.h>
#include <linux/errno.h>
#include <linux/module.h>
#include <linux/ioport.h>

#include <asm/io.h>
#include <soc/fsl/qe/qe.h>
#include <asm/prom.h>
#include <sysdev/fsl_soc.h>


#undef DEBUG


static struct qe_pio_regs __iomem *par_io;

static int num_par_io_ports = 0;


int par_io_init(struct device_node *np) { struct resource res; int ret; const u32 *num_ports; /* Map Parallel I/O ports registers */ ret = of_address_to_resource(np, 0, &res); if (ret) return ret; par_io = ioremap(res.start, resource_size(&res)); num_ports = of_get_property(np, "num-ports", NULL); if (num_ports) num_par_io_ports = *num_ports; return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Li Yang7593.75%133.33%
Joe Perches45.00%133.33%
Stephen Rothwell11.25%133.33%
Total80100.00%3100.00%


void __par_io_config_pin(struct qe_pio_regs __iomem *par_io, u8 pin, int dir, int open_drain, int assignment, int has_irq) { u32 pin_mask1bit; u32 pin_mask2bits; u32 new_mask2bits; u32 tmp_val; /* calculate pin location for single and 2 bits information */ pin_mask1bit = (u32) (1 << (QE_PIO_PINS - (pin + 1))); /* Set open drain, if required */ tmp_val = in_be32(&par_io->cpodr); if (open_drain) out_be32(&par_io->cpodr, pin_mask1bit | tmp_val); else out_be32(&par_io->cpodr, ~pin_mask1bit & tmp_val); /* define direction */ tmp_val = (pin > (QE_PIO_PINS / 2) - 1) ? in_be32(&par_io->cpdir2) : in_be32(&par_io->cpdir1); /* get all bits mask for 2 bit per port */ pin_mask2bits = (u32) (0x3 << (QE_PIO_PINS - (pin % (QE_PIO_PINS / 2) + 1) * 2)); /* Get the final mask we need for the right definition */ new_mask2bits = (u32) (dir << (QE_PIO_PINS - (pin % (QE_PIO_PINS / 2) + 1) * 2)); /* clear and set 2 bits mask */ if (pin > (QE_PIO_PINS / 2) - 1) { out_be32(&par_io->cpdir2, ~pin_mask2bits & tmp_val); tmp_val &= ~pin_mask2bits; out_be32(&par_io->cpdir2, new_mask2bits | tmp_val); } else { out_be32(&par_io->cpdir1, ~pin_mask2bits & tmp_val); tmp_val &= ~pin_mask2bits; out_be32(&par_io->cpdir1, new_mask2bits | tmp_val); } /* define pin assignment */ tmp_val = (pin > (QE_PIO_PINS / 2) - 1) ? in_be32(&par_io->cppar2) : in_be32(&par_io->cppar1); new_mask2bits = (u32) (assignment << (QE_PIO_PINS - (pin % (QE_PIO_PINS / 2) + 1) * 2)); /* clear and set 2 bits mask */ if (pin > (QE_PIO_PINS / 2) - 1) { out_be32(&par_io->cppar2, ~pin_mask2bits & tmp_val); tmp_val &= ~pin_mask2bits; out_be32(&par_io->cppar2, new_mask2bits | tmp_val); } else { out_be32(&par_io->cppar1, ~pin_mask2bits & tmp_val); tmp_val &= ~pin_mask2bits; out_be32(&par_io->cppar1, new_mask2bits | tmp_val); } }

Contributors

PersonTokensPropCommitsCommitProp
Li Yang36090.00%150.00%
Anton Vorontsov4010.00%150.00%
Total400100.00%2100.00%

EXPORT_SYMBOL(__par_io_config_pin);
int par_io_config_pin(u8 port, u8 pin, int dir, int open_drain, int assignment, int has_irq) { if (!par_io || port >= num_par_io_ports) return -EINVAL; __par_io_config_pin(&par_io[port], pin, dir, open_drain, assignment, has_irq); return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Anton Vorontsov5493.10%150.00%
Li Yang46.90%150.00%
Total58100.00%2100.00%

EXPORT_SYMBOL(par_io_config_pin);
int par_io_data_set(u8 port, u8 pin, u8 val) { u32 pin_mask, tmp_val; if (port >= num_par_io_ports) return -EINVAL; if (pin >= QE_PIO_PINS) return -EINVAL; /* calculate pin location */ pin_mask = (u32) (1 << (QE_PIO_PINS - 1 - pin)); tmp_val = in_be32(&par_io[port].cpdata); if (val == 0) /* clear */ out_be32(&par_io[port].cpdata, ~pin_mask & tmp_val); else /* set */ out_be32(&par_io[port].cpdata, pin_mask | tmp_val); return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Li Yang11198.23%150.00%
Anton Vorontsov21.77%150.00%
Total113100.00%2100.00%

EXPORT_SYMBOL(par_io_data_set);
int par_io_of_config(struct device_node *np) { struct device_node *pio; const phandle *ph; int pio_map_len; const unsigned int *pio_map; if (par_io == NULL) { printk(KERN_ERR "par_io not initialized\n"); return -1; } ph = of_get_property(np, "pio-handle", NULL); if (ph == NULL) { printk(KERN_ERR "pio-handle not available\n"); return -1; } pio = of_find_node_by_phandle(*ph); pio_map = of_get_property(pio, "pio-map", &pio_map_len); if (pio_map == NULL) { printk(KERN_ERR "pio-map is not set!\n"); return -1; } pio_map_len /= sizeof(unsigned int); if ((pio_map_len % 6) != 0) { printk(KERN_ERR "pio-map format wrong!\n"); return -1; } while (pio_map_len > 0) { par_io_config_pin((u8) pio_map[0], (u8) pio_map[1], (int) pio_map[2], (int) pio_map[3], (int) pio_map[4], (int) pio_map[5]); pio_map += 6; pio_map_len -= 6; } of_node_put(pio); return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Li Yang21296.80%125.00%
Frans Pop41.83%125.00%
Stephen Rothwell20.91%125.00%
Anton Vorontsov10.46%125.00%
Total219100.00%4100.00%

EXPORT_SYMBOL(par_io_of_config);

Overall Contributors

PersonTokensPropCommitsCommitProp
Li Yang81687.37%225.00%
Anton Vorontsov10611.35%225.00%
Frans Pop40.43%112.50%
Joe Perches40.43%112.50%
Stephen Rothwell30.32%112.50%
Zhao Qiang10.11%112.50%
Total934100.00%8100.00%
Information contained on this website is for historical information purposes only and does not indicate or represent copyright ownership.
Created with cregit.