uboot/arch/powerpc/include/asm/iopin_8xx.h
<<
>>
Prefs
   1/*
   2 * See file CREDITS for list of people who contributed to this
   3 * project.
   4 *
   5 * This program is free software; you can redistribute it and/or
   6 * modify it under the terms of the GNU General Public License as
   7 * published by the Free Software Foundation; either version 2 of
   8 * the License, or (at your option) any later version.
   9 *
  10 * This program is distributed in the hope that it will be useful,
  11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13 * GNU General Public License for more details.
  14 *
  15 * You should have received a copy of the GNU General Public License
  16 * along with this program; if not, write to the Free Software
  17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  18 * MA 02111-1307 USA
  19 */
  20
  21/*
  22 * MPC8xx I/O port pin manipulation functions
  23 * Roughly based on iopin_8260.h
  24 */
  25
  26#ifndef _ASM_IOPIN_8XX_H_
  27#define _ASM_IOPIN_8XX_H_
  28
  29#include <linux/types.h>
  30#include <asm/8xx_immap.h>
  31
  32#ifdef __KERNEL__
  33
  34typedef struct {
  35        u_char port:2;  /* port number (A=0, B=1, C=2, D=3) */
  36        u_char pin:5;   /* port pin (0-31) */
  37        u_char flag:1;  /* for whatever */
  38} iopin_t;
  39
  40#define IOPIN_PORTA     0
  41#define IOPIN_PORTB     1
  42#define IOPIN_PORTC     2
  43#define IOPIN_PORTD     3
  44
  45extern __inline__ void
  46iopin_set_high(iopin_t *iopin)
  47{
  48        if (iopin->port == IOPIN_PORTA) {
  49                volatile ushort *datp = &((immap_t *)CONFIG_SYS_IMMR)->im_ioport.iop_padat;
  50                *datp |= (1 << (15 - iopin->pin));
  51        } else if (iopin->port == IOPIN_PORTB) {
  52                volatile uint *datp = &((immap_t *)CONFIG_SYS_IMMR)->im_cpm.cp_pbdat;
  53                *datp |= (1 << (31 - iopin->pin));
  54        } else if (iopin->port == IOPIN_PORTC) {
  55                volatile ushort *datp = &((immap_t *)CONFIG_SYS_IMMR)->im_ioport.iop_pcdat;
  56                *datp |= (1 << (15 - iopin->pin));
  57        } else if (iopin->port == IOPIN_PORTD) {
  58                volatile ushort *datp = &((immap_t *)CONFIG_SYS_IMMR)->im_ioport.iop_pddat;
  59                *datp |= (1 << (15 - iopin->pin));
  60        }
  61}
  62
  63extern __inline__ void
  64iopin_set_low(iopin_t *iopin)
  65{
  66        if (iopin->port == IOPIN_PORTA) {
  67                volatile ushort *datp = &((immap_t *)CONFIG_SYS_IMMR)->im_ioport.iop_padat;
  68                *datp &= ~(1 << (15 - iopin->pin));
  69        } else if (iopin->port == IOPIN_PORTB) {
  70                volatile uint *datp = &((immap_t *)CONFIG_SYS_IMMR)->im_cpm.cp_pbdat;
  71                *datp &= ~(1 << (31 - iopin->pin));
  72        } else if (iopin->port == IOPIN_PORTC) {
  73                volatile ushort *datp = &((immap_t *)CONFIG_SYS_IMMR)->im_ioport.iop_pcdat;
  74                *datp &= ~(1 << (15 - iopin->pin));
  75        } else if (iopin->port == IOPIN_PORTD) {
  76                volatile ushort *datp = &((immap_t *)CONFIG_SYS_IMMR)->im_ioport.iop_pddat;
  77                *datp &= ~(1 << (15 - iopin->pin));
  78        }
  79}
  80
  81extern __inline__ uint
  82iopin_is_high(iopin_t *iopin)
  83{
  84        if (iopin->port == IOPIN_PORTA) {
  85                volatile ushort *datp = &((immap_t *)CONFIG_SYS_IMMR)->im_ioport.iop_padat;
  86                return (*datp >> (15 - iopin->pin)) & 1;
  87        } else if (iopin->port == IOPIN_PORTB) {
  88                volatile uint *datp = &((immap_t *)CONFIG_SYS_IMMR)->im_cpm.cp_pbdat;
  89                return (*datp >> (31 - iopin->pin)) & 1;
  90        } else if (iopin->port == IOPIN_PORTC) {
  91                volatile ushort *datp = &((immap_t *)CONFIG_SYS_IMMR)->im_ioport.iop_pcdat;
  92                return (*datp >> (15 - iopin->pin)) & 1;
  93        } else if (iopin->port == IOPIN_PORTD) {
  94                volatile ushort *datp = &((immap_t *)CONFIG_SYS_IMMR)->im_ioport.iop_pddat;
  95                return (*datp >> (15 - iopin->pin)) & 1;
  96        }
  97        return 0;
  98}
  99
 100extern __inline__ uint
 101iopin_is_low(iopin_t *iopin)
 102{
 103        if (iopin->port == IOPIN_PORTA) {
 104                volatile ushort *datp = &((immap_t *)CONFIG_SYS_IMMR)->im_ioport.iop_padat;
 105                return ((*datp >> (15 - iopin->pin)) & 1) ^ 1;
 106        } else if (iopin->port == IOPIN_PORTB) {
 107                volatile uint *datp = &((immap_t *)CONFIG_SYS_IMMR)->im_cpm.cp_pbdat;
 108                return ((*datp >> (31 - iopin->pin)) & 1) ^ 1;
 109        } else if (iopin->port == IOPIN_PORTC) {
 110                volatile ushort *datp = &((immap_t *)CONFIG_SYS_IMMR)->im_ioport.iop_pcdat;
 111                return ((*datp >> (15 - iopin->pin)) & 1) ^ 1;
 112        } else if (iopin->port == IOPIN_PORTD) {
 113                volatile ushort *datp = &((immap_t *)CONFIG_SYS_IMMR)->im_ioport.iop_pddat;
 114                return ((*datp >> (15 - iopin->pin)) & 1) ^ 1;
 115        }
 116        return 0;
 117}
 118
 119extern __inline__ void
 120iopin_set_out(iopin_t *iopin)
 121{
 122        if (iopin->port == IOPIN_PORTA) {
 123                volatile ushort *dirp = &((immap_t *)CONFIG_SYS_IMMR)->im_ioport.iop_padir;
 124                *dirp |= (1 << (15 - iopin->pin));
 125        } else if (iopin->port == IOPIN_PORTB) {
 126                volatile uint *dirp = &((immap_t *)CONFIG_SYS_IMMR)->im_cpm.cp_pbdir;
 127                *dirp |= (1 << (31 - iopin->pin));
 128        } else if (iopin->port == IOPIN_PORTC) {
 129                volatile ushort *dirp = &((immap_t *)CONFIG_SYS_IMMR)->im_ioport.iop_pcdir;
 130                *dirp |= (1 << (15 - iopin->pin));
 131        } else if (iopin->port == IOPIN_PORTD) {
 132                volatile ushort *dirp = &((immap_t *)CONFIG_SYS_IMMR)->im_ioport.iop_pddir;
 133                *dirp |= (1 << (15 - iopin->pin));
 134        }
 135}
 136
 137extern __inline__ void
 138iopin_set_in(iopin_t *iopin)
 139{
 140        if (iopin->port == IOPIN_PORTA) {
 141                volatile ushort *dirp = &((immap_t *)CONFIG_SYS_IMMR)->im_ioport.iop_padir;
 142                *dirp &= ~(1 << (15 - iopin->pin));
 143        } else if (iopin->port == IOPIN_PORTB) {
 144                volatile uint *dirp = &((immap_t *)CONFIG_SYS_IMMR)->im_cpm.cp_pbdir;
 145                *dirp &= ~(1 << (31 - iopin->pin));
 146        } else if (iopin->port == IOPIN_PORTC) {
 147                volatile ushort *dirp = &((immap_t *)CONFIG_SYS_IMMR)->im_ioport.iop_pcdir;
 148                *dirp &= ~(1 << (15 - iopin->pin));
 149        } else if (iopin->port == IOPIN_PORTD) {
 150                volatile ushort *dirp = &((immap_t *)CONFIG_SYS_IMMR)->im_ioport.iop_pddir;
 151                *dirp &= ~(1 << (15 - iopin->pin));
 152        }
 153}
 154
 155extern __inline__ uint
 156iopin_is_out(iopin_t *iopin)
 157{
 158        if (iopin->port == IOPIN_PORTA) {
 159                volatile ushort *dirp = &((immap_t *)CONFIG_SYS_IMMR)->im_ioport.iop_padir;
 160                return (*dirp >> (15 - iopin->pin)) & 1;
 161        } else if (iopin->port == IOPIN_PORTB) {
 162                volatile uint *dirp = &((immap_t *)CONFIG_SYS_IMMR)->im_cpm.cp_pbdir;
 163                return (*dirp >> (31 - iopin->pin)) & 1;
 164        } else if (iopin->port == IOPIN_PORTC) {
 165                volatile ushort *dirp = &((immap_t *)CONFIG_SYS_IMMR)->im_ioport.iop_pcdir;
 166                return (*dirp >> (15 - iopin->pin)) & 1;
 167        } else if (iopin->port == IOPIN_PORTD) {
 168                volatile ushort *dirp = &((immap_t *)CONFIG_SYS_IMMR)->im_ioport.iop_pddir;
 169                return (*dirp >> (15 - iopin->pin)) & 1;
 170        }
 171        return 0;
 172}
 173
 174extern __inline__ uint
 175iopin_is_in(iopin_t *iopin)
 176{
 177        if (iopin->port == IOPIN_PORTA) {
 178                volatile ushort *dirp = &((immap_t *)CONFIG_SYS_IMMR)->im_ioport.iop_padir;
 179                return ((*dirp >> (15 - iopin->pin)) & 1) ^ 1;
 180        } else if (iopin->port == IOPIN_PORTB) {
 181                volatile uint *dirp = &((immap_t *)CONFIG_SYS_IMMR)->im_cpm.cp_pbdir;
 182                return ((*dirp >> (31 - iopin->pin)) & 1) ^ 1;
 183        } else if (iopin->port == IOPIN_PORTC) {
 184                volatile ushort *dirp = &((immap_t *)CONFIG_SYS_IMMR)->im_ioport.iop_pcdir;
 185                return ((*dirp >> (15 - iopin->pin)) & 1) ^ 1;
 186        } else if (iopin->port == IOPIN_PORTD) {
 187                volatile ushort *dirp = &((immap_t *)CONFIG_SYS_IMMR)->im_ioport.iop_pddir;
 188                return ((*dirp >> (15 - iopin->pin)) & 1) ^ 1;
 189        }
 190        return 0;
 191}
 192
 193extern __inline__ void
 194iopin_set_odr(iopin_t *iopin)
 195{
 196        if (iopin->port == IOPIN_PORTA) {
 197                volatile ushort *odrp = &((immap_t *)CONFIG_SYS_IMMR)->im_ioport.iop_paodr;
 198                *odrp |= (1 << (15 - iopin->pin));
 199        } else if (iopin->port == IOPIN_PORTB) {
 200                volatile ushort *odrp = &((immap_t *)CONFIG_SYS_IMMR)->im_cpm.cp_pbodr;
 201                *odrp |= (1 << (31 - iopin->pin));
 202        }
 203}
 204
 205extern __inline__ void
 206iopin_set_act(iopin_t *iopin)
 207{
 208        if (iopin->port == IOPIN_PORTA) {
 209                volatile ushort *odrp = &((immap_t *)CONFIG_SYS_IMMR)->im_ioport.iop_paodr;
 210                *odrp &= ~(1 << (15 - iopin->pin));
 211        } else if (iopin->port == IOPIN_PORTB) {
 212                volatile ushort *odrp = &((immap_t *)CONFIG_SYS_IMMR)->im_cpm.cp_pbodr;
 213                *odrp &= ~(1 << (31 - iopin->pin));
 214        }
 215}
 216
 217extern __inline__ uint
 218iopin_is_odr(iopin_t *iopin)
 219{
 220        if (iopin->port == IOPIN_PORTA) {
 221                volatile ushort *odrp = &((immap_t *)CONFIG_SYS_IMMR)->im_ioport.iop_paodr;
 222                return (*odrp >> (15 - iopin->pin)) & 1;
 223        } else if (iopin->port == IOPIN_PORTB) {
 224                volatile ushort *odrp = &((immap_t *)CONFIG_SYS_IMMR)->im_cpm.cp_pbodr;
 225                return (*odrp >> (31 - iopin->pin)) & 1;
 226        }
 227        return 0;
 228}
 229
 230extern __inline__ uint
 231iopin_is_act(iopin_t *iopin)
 232{
 233        if (iopin->port == IOPIN_PORTA) {
 234                volatile ushort *odrp = &((immap_t *)CONFIG_SYS_IMMR)->im_ioport.iop_paodr;
 235                return ((*odrp >> (15 - iopin->pin)) & 1) ^ 1;
 236        } else if (iopin->port == IOPIN_PORTB) {
 237                volatile ushort *odrp = &((immap_t *)CONFIG_SYS_IMMR)->im_cpm.cp_pbodr;
 238                return ((*odrp >> (31 - iopin->pin)) & 1) ^ 1;
 239        }
 240        return 0;
 241}
 242
 243extern __inline__ void
 244iopin_set_ded(iopin_t *iopin)
 245{
 246        if (iopin->port == IOPIN_PORTA) {
 247                volatile ushort *parp = &((immap_t *)CONFIG_SYS_IMMR)->im_ioport.iop_papar;
 248                *parp |= (1 << (15 - iopin->pin));
 249        } else if (iopin->port == IOPIN_PORTB) {
 250                volatile uint *parp = &((immap_t *)CONFIG_SYS_IMMR)->im_cpm.cp_pbpar;
 251                *parp |= (1 << (31 - iopin->pin));
 252        } else if (iopin->port == IOPIN_PORTC) {
 253                volatile ushort *parp = &((immap_t *)CONFIG_SYS_IMMR)->im_ioport.iop_pcpar;
 254                *parp |= (1 << (15 - iopin->pin));
 255        } else if (iopin->port == IOPIN_PORTD) {
 256                volatile ushort *parp = &((immap_t *)CONFIG_SYS_IMMR)->im_ioport.iop_pdpar;
 257                *parp |= (1 << (15 - iopin->pin));
 258        }
 259}
 260
 261extern __inline__ void
 262iopin_set_gen(iopin_t *iopin)
 263{
 264        if (iopin->port == IOPIN_PORTA) {
 265                volatile ushort *parp = &((immap_t *)CONFIG_SYS_IMMR)->im_ioport.iop_papar;
 266                *parp &= ~(1 << (15 - iopin->pin));
 267        } else if (iopin->port == IOPIN_PORTB) {
 268                volatile uint *parp = &((immap_t *)CONFIG_SYS_IMMR)->im_cpm.cp_pbpar;
 269                *parp &= ~(1 << (31 - iopin->pin));
 270        } else if (iopin->port == IOPIN_PORTC) {
 271                volatile ushort *parp = &((immap_t *)CONFIG_SYS_IMMR)->im_ioport.iop_pcpar;
 272                *parp &= ~(1 << (15 - iopin->pin));
 273        } else if (iopin->port == IOPIN_PORTD) {
 274                volatile ushort *parp = &((immap_t *)CONFIG_SYS_IMMR)->im_ioport.iop_pdpar;
 275                *parp &= ~(1 << (15 - iopin->pin));
 276        }
 277}
 278
 279extern __inline__ uint
 280iopin_is_ded(iopin_t *iopin)
 281{
 282        if (iopin->port == IOPIN_PORTA) {
 283                volatile ushort *parp = &((immap_t *)CONFIG_SYS_IMMR)->im_ioport.iop_papar;
 284                return (*parp >> (15 - iopin->pin)) & 1;
 285        } else if (iopin->port == IOPIN_PORTB) {
 286                volatile uint *parp = &((immap_t *)CONFIG_SYS_IMMR)->im_cpm.cp_pbpar;
 287                return (*parp >> (31 - iopin->pin)) & 1;
 288        } else if (iopin->port == IOPIN_PORTC) {
 289                volatile ushort *parp = &((immap_t *)CONFIG_SYS_IMMR)->im_ioport.iop_pcpar;
 290                return (*parp >> (15 - iopin->pin)) & 1;
 291        } else if (iopin->port == IOPIN_PORTD) {
 292                volatile ushort *parp = &((immap_t *)CONFIG_SYS_IMMR)->im_ioport.iop_pdpar;
 293                return (*parp >> (15 - iopin->pin)) & 1;
 294        }
 295        return 0;
 296}
 297
 298extern __inline__ uint
 299iopin_is_gen(iopin_t *iopin)
 300{
 301        if (iopin->port == IOPIN_PORTA) {
 302                volatile ushort *parp = &((immap_t *)CONFIG_SYS_IMMR)->im_ioport.iop_papar;
 303                return ((*parp >> (15 - iopin->pin)) & 1) ^ 1;
 304        } else if (iopin->port == IOPIN_PORTB) {
 305                volatile uint *parp = &((immap_t *)CONFIG_SYS_IMMR)->im_cpm.cp_pbpar;
 306                return ((*parp >> (31 - iopin->pin)) & 1) ^ 1;
 307        } else if (iopin->port == IOPIN_PORTC) {
 308                volatile ushort *parp = &((immap_t *)CONFIG_SYS_IMMR)->im_ioport.iop_pcpar;
 309                return ((*parp >> (15 - iopin->pin)) & 1) ^ 1;
 310        } else if (iopin->port == IOPIN_PORTD) {
 311                volatile ushort *parp = &((immap_t *)CONFIG_SYS_IMMR)->im_ioport.iop_pdpar;
 312                return ((*parp >> (15 - iopin->pin)) & 1) ^ 1;
 313        }
 314        return 0;
 315}
 316
 317extern __inline__ void
 318iopin_set_opt2(iopin_t *iopin)
 319{
 320        if (iopin->port == IOPIN_PORTC) {
 321                volatile ushort *sorp = &((immap_t *)CONFIG_SYS_IMMR)->im_ioport.iop_pcso;
 322                *sorp |= (1 << (15 - iopin->pin));
 323        }
 324}
 325
 326extern __inline__ void
 327iopin_set_opt1(iopin_t *iopin)
 328{
 329        if (iopin->port == IOPIN_PORTC) {
 330                volatile ushort *sorp = &((immap_t *)CONFIG_SYS_IMMR)->im_ioport.iop_pcso;
 331                *sorp &= ~(1 << (15 - iopin->pin));
 332        }
 333}
 334
 335extern __inline__ uint
 336iopin_is_opt2(iopin_t *iopin)
 337{
 338        if (iopin->port == IOPIN_PORTC) {
 339                volatile ushort *sorp = &((immap_t *)CONFIG_SYS_IMMR)->im_ioport.iop_pcso;
 340                return (*sorp >> (15 - iopin->pin)) & 1;
 341        }
 342        return 0;
 343}
 344
 345extern __inline__ uint
 346iopin_is_opt1(iopin_t *iopin)
 347{
 348        if (iopin->port == IOPIN_PORTC) {
 349                volatile ushort *sorp = &((immap_t *)CONFIG_SYS_IMMR)->im_ioport.iop_pcso;
 350                return ((*sorp >> (15 - iopin->pin)) & 1) ^ 1;
 351        }
 352        return 0;
 353}
 354
 355extern __inline__ void
 356iopin_set_falledge(iopin_t *iopin)
 357{
 358        if (iopin->port == IOPIN_PORTC) {
 359                volatile ushort *intp = &((immap_t *)CONFIG_SYS_IMMR)->im_ioport.iop_pcint;
 360                *intp |= (1 << (15 - iopin->pin));
 361        }
 362}
 363
 364extern __inline__ void
 365iopin_set_anyedge(iopin_t *iopin)
 366{
 367        if (iopin->port == IOPIN_PORTC) {
 368                volatile ushort *intp = &((immap_t *)CONFIG_SYS_IMMR)->im_ioport.iop_pcint;
 369                *intp &= ~(1 << (15 - iopin->pin));
 370        }
 371}
 372
 373extern __inline__ uint
 374iopin_is_falledge(iopin_t *iopin)
 375{
 376        if (iopin->port == IOPIN_PORTC) {
 377                volatile ushort *intp = &((immap_t *)CONFIG_SYS_IMMR)->im_ioport.iop_pcint;
 378                return (*intp >> (15 - iopin->pin)) & 1;
 379        }
 380        return 0;
 381}
 382
 383extern __inline__ uint
 384iopin_is_anyedge(iopin_t *iopin)
 385{
 386        if (iopin->port == IOPIN_PORTC) {
 387                volatile ushort *intp = &((immap_t *)CONFIG_SYS_IMMR)->im_ioport.iop_pcint;
 388                return ((*intp >> (15 - iopin->pin)) & 1) ^ 1;
 389        }
 390        return 0;
 391}
 392
 393#endif /* __KERNEL__ */
 394
 395#endif /* _ASM_IOPIN_8XX_H_ */
 396