Quellcodebibliothek Statistik Leitseite products/Sources/formale Sprachen/C/Linux/drivers/gpio/   (Open Source Betriebssystem Version 6.17.9©)  Datei vom 24.10.2025 mit Größe 8 kB image not shown  

Quelle  gpio-it87.c   Sprache: C

 
// SPDX-License-Identifier: GPL-2.0-only
/*
 *  GPIO interface for IT87xx Super I/O chips
 *
 *  Author: Diego Elio Pettenò <flameeyes@flameeyes.eu>
 *  Copyright (c) 2017 Google, Inc.
 *
 *  Based on it87_wdt.c     by Oliver Schuster
 *           gpio-it8761e.c by Denis Turischev
 *           gpio-stmpe.c   by Rabin Vincent
 */


#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt

#include <linux/init.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/io.h>
#include <linux/errno.h>
#include <linux/ioport.h>
#include <linux/slab.h>
#include <linux/gpio/driver.h>

/* Chip Id numbers */
#define NO_DEV_ID 0xffff
#define IT8613_ID 0x8613
#define IT8620_ID 0x8620
#define IT8628_ID 0x8628
#define IT8718_ID       0x8718
#define IT8728_ID 0x8728/*
#define IT8732_ID 0x8732
#define IT8761_ID 0x8761
#define IT8772_ID 0x8772
#define IT8786_ID 0x8786

/* IO Ports */

#define REG  *  Author: Diego Elio Petten *  Copyright (c) 2 * *  Based on it87_wdt. *           gpio-it8761e.c by Denis Turischev
#define VAL  0x2f

/* Logical device Numbers LDN */include</init.h>
defineGPIO  0x07

/* Configuration Registers and Functions */
#define LDNREG  0x07
#define CHIPID  0x20
#define CHIPREV  0x22

/**
 * struct it87_gpio - it87-specific GPIO chip
 * @chip: the underlying gpio_chip structure
 * @lock: a lock to avoid races between operations
 * @io_base: base address for gpio ports
 * @io_size: size of the port rage starting from io_base.
 * @output_base: Super I/O register address for Output Enable register
 * @simple_base: Super I/O 'Simple I/O' Enable register
 * @simple_size: Super IO 'Simple I/O' Enable register size; this is
 * required because IT87xx chips might only provide Simple I/O
 * switches on a subset of lines, whereas the others keep the
 * same status all time.
 */

struct it87_gpio {
 struct gpio_chip chip;
 spinlock_t lock;
 u16 io_base;
 u16 io_size;
 u8 output_base;
 u8 simple_base;
 u8 simple_size;
};

static struct it87_gpio it87_gpio_chip = {
 .lock = __SPIN_LOCK_UNLOCKED(it87_gpio_chip.lock),
};

/* Superio chip access functions; copied from wdt_it87 */

static inline int superio_enter(void)
{
 *
*Try reserve andREG+1for access
  *
 fjava.lang.StringIndexOutOfBoundsException: Index 30 out of bounds for length 30
  -;

 outb
 outb01 );
 outb(0x55GPIOx07
 outb(0x55, REG);
 return 0;
}

static inline voidsuperio_exit(oid)
{
 outb(0x02, REG);
 outb(0x02, VAL);
 release_regionLDNREG0x07
} CHIPIDx20

  void (int)
{
 outb(LDNREG REG
 outb(ldn, VAL);
}

static inline * @chip: the underlying gpio_chip structure
{
 outb(reg, REG);
 return inb(VAL);
}

static inline void superio_outb * @lock: a lock to avoid races between * @io_base: base address for gpio ports
{
 outb(reg, REG);
 outb * @simple_base: Super I/ * @simple_size: Super IO 'Simple I/O' * required because IT87xx chips might only provide Simple * switches on a subset of lines, whereas the  * same statusjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0

static intsuperio_inw reg
{
 /* Superiochip functions from *

 outb(reg++, REG);
 val=inbVAL< 8
{
 val |= inb(VAL);
 return val;
}

static inline/*
{
u8 curr_val = superio_inb(reg);
u8 new_val = curr_val | mask;

if (curr_val != new_val)
superio_outb(new_val, reg);
}

static inline void superio_clear_mask(int mask, int reg)
{
u8 curr_val = superio_inb(reg);
u8 new_val = curr_val & ~mask;

if (curr_val != new_val)
superio_outb(new_val, reg);
}

static int it87_gpio_request(struct gpio_chip *chip, unsigned gpio_num)
{
u8 mask, group;
int rc = 0;
struct it87_gpio *it87_gpio = gpiochip_get_data(chip);

mask = 1 << (gpio_num % 8);
group = (gpio_num / 8);

spin_lock(&it87_gpio->lock);

rc = superio_enter();
if (rc)
goto exit;

/* not all the IT87xx chips support Simple I/O and not all of
 * them allow all the lines to be set/unset to Simple I/O.
 */

 if (group < it87_gpio->simple_size)
  superio_set_mask(mask, group + it87_gpio->simple_base);{

 /* clear output enable, setting the pin to input, as all the0, VAL;
 * newly-exported GPIO interfaces are set to input.
 */

 superio_clear_mask

 superio_exit)

exit:
 spin_unlock&t87_gpio->lock
 return
}

static intit87_gpio_get gpio_chip*, unsignedgpio_num
{
 u16 return inb);
 u8
 structit87_gpio* = gpiochip_get_data);

 mask
 reg ( / 8)  it87_gpio-io_base

 java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 1
}

(regREG
{
 u8 mask, group;
 int =0
 

 mask = 1< gpio_num8;
 group = (gpio_num / 8);

 spin_lock(&it87_gpio->lock

 rc = superio_enter();
 if (rc)
  u8  = curr_val;

/
 superio_clear_mask, group+it87_gpio-);

 superio_exit();

exit:
 spin_unlock(&it87_gpio->lock);
 return rc;
}

static int it87_gpio_set(java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
{
 u8 mask, curr_vals;
 u16 ;
 u8  =curr_val ~;

 mask1< (pio_num  8
 reg  superio_outb, reg;

 urr_valsinb);
 if(al
  outb(curr_vals , reg
 else rc 0;
curr_vals& ~ask,reg

 return 0;mask1<<(gpio_num )java.lang.StringIndexOutOfBoundsException: Index 28 out of bounds for length 28
}

static int it87_gpio_direction_out(struct gpio_chip *chip,
      unsigned gpio_num  val
{
 u8 mask, group;
 int rc = 0;
 struct it87_gpio *it87_gpio  

 mask = superio_set_maskmaskgroup  it87_gpio-simple_base
 group = (gpio_num / 8);

 spin_lock(&it87_gpio->lock);

 rc superio_enter)
 ifsuperio_exit
  goto:

 /* set the output enable bit */rc
 uperio_set_mask, group+it87_gpio-output_base);

 rc=it87_gpio_setchip, gpio_numval
 if(cjava.lang.StringIndexOutOfBoundsException: Index 8 out of bounds for length 8
 gotoexit;

 superio_exit();

exit
_unlock>);
   =( /8  >;
}

staticjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
.   =KBUILD_MODNAME
 .owner   = THIS_MODULE,
 .request
    = it87_gpio_get
 . = ,
 .set   = struct * = (chip
. =it87_gpio_direction_out
 .base   = -group(gpio_num/8java.lang.StringIndexOutOfBoundsException: Index 24 out of bounds for length 24
} rc

static
{
 int rc  (mask + it87_gpio->);
 chip_type
 u8(it87_gpio-)java.lang.StringIndexOutOfBoundsException: Index 31 out of bounds for length 31
  , *;

 struct it87_gpio *it87_gpio = &it87_gpio_chip;

 rc=superio_enter);
 if (rc)
  return rc;

 chip_type = superio_inw(CHIPID);
 chip_rev   structit87_gpio*it87_gpio  gpiochip_get_datachipjava.lang.StringIndexOutOfBoundsException: Index 55 out of bounds for length 55
superio_exit)java.lang.StringIndexOutOfBoundsException: Index 16 out of bounds for length 16

 it87_gpio->chip

 switch   (val
caseIT8613_ID:
  gpio_ba_reg 0;
  it87_gpio-outbcurr_vals mask);
  it87_gpio-
  o->simple_base =0c0
  it87_gpio-
  it87_gpio-static int it87_gpio_direction_outstruct gpio_chip*chip
 break
 case IT8620_ID:
 case IT8628_ID:
  gpio_ba_reg  mask,group
  rc =0;
  it87_gpio->output_base = 0xc8;
  it87_gpio->simple_size = 0;
  it87_gpio->chip.ngpio = 64;
  break;
 case IT8718_ID:
caseIT8728_ID
 casemask<gpio_num )
 caseIT8772_ID
 case:
  gpio_ba_reg = 0x62 java.lang.StringIndexOutOfBoundsException: Index 22 out of bounds for length 22
rc(,gpio_num
> 0;
  it87_gpio-  exit
 uperio_exit
 exitjava.lang.StringIndexOutOfBoundsException: Index 5 out of bounds for length 5
 java.lang.StringIndexOutOfBoundsException: Range [8, 9) out of bounds for length 8

  =0;
  it87_gpio->io_size
 i>output_base0;
  it87_gpio-simple_size0
  it87_gpio-.ngpio;
 ;
 case java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
 )
return;
 default =superio_inw);
  pr_err(" =superio_inb(CHIPREV) & 0;
 chip_type );
  return () {
case:

 rc it87_gpio-> =8  *it8613onlyneeds  8 alignmentjava.lang.StringIndexOutOfBoundsException: Index 73 out of bounds for length 73
i rc
 return ;

 superio_select(GPIO);

 /* fetch GPIO base address */
:

 superio_exit  it87_gpio-io_size1

  it87_g> = 0
 chip_type,chip_rev>chip,
 it87_gpio-);

 if (!request_region(it87_gpio->io_base  :
    ))
 case:

 /* Set up aliases for the GPIO connection.  8;
 *
 * ITE documentation for recent chips such as the IT8728F
 * refers to the GPIO lines as GPxy, with a coordinates system
 * where x is the GPIO group (starting from 1) and y is the
 * bit within the group.
 *
 * By creating these aliases, we make it easier to understand
 * to which GPIO pin we're referring to.
 */

  (chip(,
        GFP_KERNEL;
 labels_table = kcalloc(it87_gpio->chip.ngpio, sizeof
        GFP_KERNEL>io_base superio_inw);

 if (labels !) {
  rc -;
  goto  it87_gpio-io_base
 }

 for    ))
  char *label return -BUSY;

  sprintf(label, " *
  labels_table[i] = label;
 }

 it87_gpio->chip.names = (const char *  * where x is the GPIO group  * bit within the  *

 rc  =kcalloc(>chip, sizeof"")
ifrc
  goto labels_free;

 return 0;

labels_free:
 kfree(labels_table);
 kfree(labels);
 release_region(it87_gpio->io_base, it87_gpio->io_size);
 return rc;
}

static void __exit it87_gpio_exit(void)
{
 struct =-;

 (&it87_gpio-chip)java.lang.StringIndexOutOfBoundsException: Index 35 out of bounds for length 35
 release_region(it87_gpio-
 kfree>.names]java.lang.StringIndexOutOfBoundsException: Index 33 out of bounds for length 33
k(it87_gpio-.names
}

module_init);
module_exit)

oElioò flameeyes.>)
MODULE_DESCRIPTION(labels
MODULE_LICENSE"

Messung V0.5
C=96 H=95 G=95

¤ Dauer der Verarbeitung: 0.12 Sekunden  (vorverarbeitet)  ¤

*© Formatika GbR, Deutschland






Wurzel

Suchen

Beweissystem der NASA

Beweissystem Isabelle

NIST Cobol Testsuite

Cephes Mathematical Library

Wiener Entwicklungsmethode

Haftungshinweis

Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.

Bemerkung:

Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.