cvmx-gpio.h revision 215990
1/***********************license start***************
2 * Copyright (c) 2003-2010  Cavium Networks (support@cavium.com). All rights
3 * reserved.
4 *
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are
8 * met:
9 *
10 *   * Redistributions of source code must retain the above copyright
11 *     notice, this list of conditions and the following disclaimer.
12 *
13 *   * Redistributions in binary form must reproduce the above
14 *     copyright notice, this list of conditions and the following
15 *     disclaimer in the documentation and/or other materials provided
16 *     with the distribution.
17
18 *   * Neither the name of Cavium Networks nor the names of
19 *     its contributors may be used to endorse or promote products
20 *     derived from this software without specific prior written
21 *     permission.
22
23 * This Software, including technical data, may be subject to U.S. export  control
24 * laws, including the U.S. Export Administration Act and its  associated
25 * regulations, and may be subject to export or import  regulations in other
26 * countries.
27
28 * TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED "AS IS"
29 * AND WITH ALL FAULTS AND CAVIUM  NETWORKS MAKES NO PROMISES, REPRESENTATIONS OR
30 * WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, OR OTHERWISE, WITH RESPECT TO
31 * THE SOFTWARE, INCLUDING ITS CONDITION, ITS CONFORMITY TO ANY REPRESENTATION OR
32 * DESCRIPTION, OR THE EXISTENCE OF ANY LATENT OR PATENT DEFECTS, AND CAVIUM
33 * SPECIFICALLY DISCLAIMS ALL IMPLIED (IF ANY) WARRANTIES OF TITLE,
34 * MERCHANTABILITY, NONINFRINGEMENT, FITNESS FOR A PARTICULAR PURPOSE, LACK OF
35 * VIRUSES, ACCURACY OR COMPLETENESS, QUIET ENJOYMENT, QUIET POSSESSION OR
36 * CORRESPONDENCE TO DESCRIPTION. THE ENTIRE  RISK ARISING OUT OF USE OR
37 * PERFORMANCE OF THE SOFTWARE LIES WITH YOU.
38 ***********************license end**************************************/
39
40
41
42
43
44
45
46/**
47 * @file
48 *
49 * General Purpose IO interface.
50 *
51 * <hr>$Revision: 49448 $<hr>
52 */
53
54#ifndef __CVMX_GPIO_H__
55#define __CVMX_GPIO_H__
56
57#ifdef	__cplusplus
58extern "C" {
59#endif
60
61/* CSR typedefs have been moved to cvmx-gpio-defs.h */
62
63/**
64 * Clear the interrupt rising edge detector for the supplied
65 * pins in the mask. Chips which have more than 16 GPIO pins
66 * can't use them for interrupts.
67 *
68 * @param clear_mask Mask of pins to clear
69 */
70static inline void cvmx_gpio_interrupt_clear(uint16_t clear_mask)
71{
72    cvmx_gpio_int_clr_t gpio_int_clr;
73    gpio_int_clr.u64 = 0;
74    gpio_int_clr.s.type = clear_mask;
75    cvmx_write_csr(CVMX_GPIO_INT_CLR, gpio_int_clr.u64);
76}
77
78
79/**
80 * GPIO Read Data
81 *
82 * @return Status of the GPIO pins
83 */
84static inline uint32_t cvmx_gpio_read(void)
85{
86    cvmx_gpio_rx_dat_t gpio_rx_dat;
87    gpio_rx_dat.u64 = cvmx_read_csr(CVMX_GPIO_RX_DAT);
88    return gpio_rx_dat.s.dat;
89}
90
91
92/**
93 * GPIO Clear pin
94 *
95 * @param clear_mask Bit mask to indicate which bits to drive to '0'.
96 */
97static inline void cvmx_gpio_clear(uint32_t clear_mask)
98{
99    cvmx_gpio_tx_clr_t gpio_tx_clr;
100    gpio_tx_clr.u64 = 0;
101    gpio_tx_clr.s.clr = clear_mask;
102    cvmx_write_csr(CVMX_GPIO_TX_CLR, gpio_tx_clr.u64);
103}
104
105
106/**
107 * GPIO Set pin
108 *
109 * @param set_mask Bit mask to indicate which bits to drive to '1'.
110 */
111static inline void cvmx_gpio_set(uint32_t set_mask)
112{
113    cvmx_gpio_tx_set_t gpio_tx_set;
114    gpio_tx_set.u64 = 0;
115    gpio_tx_set.s.set = set_mask;
116    cvmx_write_csr(CVMX_GPIO_TX_SET, gpio_tx_set.u64);
117}
118
119#ifdef	__cplusplus
120}
121#endif
122
123#endif
124
125