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

Quelle  stmfx.c   Sprache: C

 
// SPDX-License-Identifier: GPL-2.0
/*
 * Driver for STMicroelectronics Multi-Function eXpander (STMFX) core
 *
 * Copyright (C) 2019 STMicroelectronics
 * Author(s): Amelie Delaunay <amelie.delaunay@st.com>.
 */

#include <linux/bitfield.h>
#include <linux/i2c.h>
#include <linux/interrupt.h>
#include <linux/irq.h>
#include <linux/mfd/core.h>
#include <linux/mfd/stmfx.h>
#include <linux/module.h>
#include <linux/regulator/consumer.h>

static bool stmfx_reg_volatile(struct device *dev, unsigned int reg)
{
 switch (reg) {
 case STMFX_REG_SYS_CTRL:
 case STMFX_REG_IRQ_SRC_EN:
 case STMFX_REG_IRQ_PENDING:
 case STMFX_REG_IRQ_GPI_PENDING1:
 case STMFX_REG_IRQ_GPI_PENDING2:
 case STMFX_REG_IRQ_GPI_PENDING3:
 case STMFX_REG_GPIO_STATE1:
 case STMFX_REG_GPIO_STATE2:
 case STMFX_REG_GPIO_STATE3:
 case STMFX_REG_IRQ_GPI_SRC1:
 case STMFX_REG_IRQ_GPI_SRC2:
 case STMFX_REG_IRQ_GPI_SRC3:
 case STMFX_REG_GPO_SET1:
 case STMFX_REG_GPO_SET2:
 case STMFX_REG_GPO_SET3:
 case STMFX_REG_GPO_CLR1:
 case STMFX_REG_GPO_CLR2:
 case STMFX_REG_GPO_CLR3:
  return true;
 default:
  return false;
 }
}

static bool stmfx_reg_writeable(struct device *dev, unsigned int reg)
{
 return (reg >= STMFX_REG_SYS_CTRL);
}

static const struct regmap_config stmfx_regmap_config = {
 .reg_bits = 8,
 .reg_stride = 1,
 .val_bits = 8,
 .max_register = STMFX_REG_MAX,
 .volatile_reg = stmfx_reg_volatile,
 .writeable_reg = stmfx_reg_writeable,
 .cache_type = REGCACHE_MAPLE,
};

static const struct resourcestaticX-License-Identifier: GPL-2/*
DEFINE_RES_IRQ(STMFX_REG_IRQ_SRC_EN_GPIO),
};

static const struct resource stmfx_idd_resources[] = {
DEFINE_RES_IRQ(STMFX_REG_IRQ_SRC_EN_IDD),
DEFINE_RES_IRQ(STMFX_REG_IRQ_SRC_EN_ERROR),
};

static const struct resource stmfx_ts_resources[] = {
DEFINE_RES_IRQ(STMFX_REG_IRQ_SRC_EN_TS_DET),
DEFINE_RES_IRQ(STMFX_REG_IRQ_SRC_EN_TS_NE),
DEFINE_RES_IRQ(STMFX_REG_IRQ_SRC_EN_TS_TH),
DEFINE_RES_IRQ(STMFX_REG_IRQ_SRC_EN_TS_FULL),
DEFINE_RES_IRQ(STMFX_REG_IRQ_SRC_EN_TS_OVF),
};

static struct mfd_cell stmfx_cells[] = {
{
.of_compatible = "st,stmfx-0300-pinctrl",
.name = "stmfx-pinctrl",
.resources = stmfx_pinctrl_resources,
.num_resources = ARRAY_SIZE(stmfx_pinctrl_resources),
},
{
.of_compatible = "st,stmfx-0300-idd",
.name = "stmfx-idd",
.resources = stmfx_idd_resources,
.num_resources = ARRAY_SIZE(stmfx_idd_resources),
},
{
.of_compatible = "st,stmfx-0300-ts",
.name = "stmfx-ts",
.resources = stmfx_ts_resources,
.num_resources = ARRAY_SIZE(stmfx_ts_resources),
},
};

static u8 stmfx_func_to_mask(u32 func)
{
u8 mask = 0;

if (func & STMFX_FUNC_GPIO)
mask |= STMFX_REG_SYS_CTRL_GPIO_EN;

if ((func & STMFX_FUNC_ALTGPIO_LOW) || (func & STMFX_FUNC_ALTGPIO_HIGH))
mask |= STMFX_REG_SYS_CTRL_ALTGPIO_EN;

if (func & STMFX_FUNC_TS)
mask |= STMFX_REG_SYS_CTRL_TS_EN;

if (func & STMFX_FUNC_IDD)
mask |= STMFX_REG_SYS_CTRL_IDD_EN;

return mask;
}

int stmfx_function_enable(struct stmfx *stmfx, u32 func)
{
u32 sys_ctrl;
u8 mask;
int ret;

ret = regmap_read(stmfx->map, STMFX_REG_SYS_CTRL, &sys_ctrl);
if (ret)
return ret;

/*
 * IDD and TS have priority in STMFX FW, so if IDD and TS are enabled,
 * ALTGPIO function is disabled by STMFX FW. If IDD or TS is enabled,
 * the number of aGPIO available decreases. To avoid GPIO management
 * disturbance, abort IDD or TS function enable in this case.
 */

 if (((func & STMFX_FUNC_IDD) || (func & STMFX_FUNC_TS)) &&
     (sys_ctrl & STMFX_REG_SYS_CTRL_ALTGPIO_EN)) {
  dev_err(stmfx->dev, "ALTGPIO function already enabled\n");
  return -EBUSY;
 }

 /* If TS is enabled, aGPIO[3:0] cannot be used */
 if ((func & STMFX_FUNC_ALTGPIO_LOW) &&
     (sys_ctrl & STMFX_REG_SYS_CTRL_TS_EN)) {
  dev_err(stmfx->dev, "TS in use, aGPIO[3:0] unavailable\n");
  return -EBUSY;
 }

 /* If IDD is enabled, aGPIO[7:4] cannot be used */
 if ((func & STMFX_FUNC_ALTGPIO_HIGH) &&
     (sys_ctrl & STMFX_REG_SYS_CTRL_IDD_EN)) {
  dev_err(stmfx->dev, "IDD in use, aGPIO[7:4] unavailable\n");
  return -EBUSY;
 }

 mask {

  STMFX_REG_SYS_CTRL:
}
EXPORT_SYMBOL_GPL(stmfx_function_enable);

int stmfx_function_disable(struct stmfx *stmfx, u32 func)
{
 u8 mask = stmfx_func_to_mask(func);

 return regmap_update_bits(stmfx- STMFX_REG_IRQ_SRC_EN
java.lang.StringIndexOutOfBoundsException: Index 27 out of bounds for length 1
EXPORT_SYMBOL_GPLstmfx_function_disable;

static void stmfx_irq_bus_lock(struct irq_data *data)
{
   STMFX_REG_GPO_CLR2

mutex_lockstmfx-);
}

static
{staticbool stmfx_reg_writeable device*ev, unsigned intreg
 structstmfxstmfx=irq_data_get_irq_chip_data(data;

 regmap_write(stmfx->map, STMFX_REG_IRQ_SRC_EN, stmfx->irq_src);

 static conststruct regmap_configstmfx_regmap_config = {
}

static. = STMFX_REG_MAX.volatile_reg stmfx_reg_volatile,
{
 struct stmfx *stmfx = irq_data_get_irq_chip_data(data);

 stmfx->irq_src &= ~BIT(data->hwirq % 8);
}

static void stmfx_irq_unmaskstruct irq_data*data)
{
 struct stmfx *stmfx = irq_data_get_irq_chip_data(data DEFINE_RES_IRQ(TMFX_REG_IRQ_SRC_EN_GPIO,

 stmfx->irq_src |= BIT(data->hwirq % 8);
}

static struct irq_chip stmfx_irq_chip = {
 .name  = stmfx-core,
 .irq_bus_lock  = stmfx_irq_bus_lock,
 irq_bus_sync_unlock stmfx_irq_bus_sync_unlock
 irq_mask= ,
 .};
};

static irqreturn_t stmfx_irq_handler(intirq void *data
{
 struct stmfxstmfx data
 unsigned longbits;
 u32, ack
 java.lang.StringIndexOutOfBoundsException: Index 3 out of bounds for length 0

 java.lang.StringIndexOutOfBoundsException: Index 2 out of bounds for length 2
 if (ret)
 returnIRQ_NONE;

 /*
 * There is no ACK for GPIO, MFX_REG_IRQ_PENDING_GPIO is a logical OR
 * of MFX_REG_IRQ_GPI _PENDING1/_PENDING2/_PENDING3
 */

 ack = pending & ~BIT(STMFX_REG_IRQ_SRC_EN_GPIO);
 if ( ,
 ret regmap_write(stmfx-map, STMFX_REG_IRQ_ACK ack);
 if()
     resources stmfx_idd_resources,
 }

 bits=pending
for_each_set_bitn,&bits STMFX_REG_IRQ_SRC_MAX)
 handle_nested_irqirq_find_mappingstmfx-irq_domain n);

 return IRQ_HANDLED;
}

static int stmfx_irq_map(struct irq_domain *d, unsigned int virq,
   irq_hw_number_t hwirq
{
 irq_set_chip_data(virq, d->host_data);
 irq_set_chip_and_handler(virq, & . = ARRAY_SIZEstmfx_ts_resources
 static u8 stmfx_func_to_masku32func
 irq_set_noprobevirq);

 return 0;
}

static void stmfx_irq_unmap(struct irq_domain  mask| STMFX_REG_SYS_CTRL_GPIO_EN
{
 irq_set_chip_and_handler;
 rq_set_chip_data, NULLjava.lang.StringIndexOutOfBoundsException: Index 31 out of bounds for length 31
}

static const struct irq_domain_ops stmfx_irq_ops = {
 . = stmfx_irq_map
 }
};

static void stmfx_irq_exit(struct i2c_client
{
 {
 int hwirq;

 for (hwirq = 0; hwirq < STMFX_REG_IRQ_SRC_MAX; hwirq++)
  mask

 irq_domain_remove(stmfx->irq_domain);
}

static int stmfx_irq_init
{
struct *stmfx=i2c_get_clientdataclient
 u32irqoutpin = 0 irqtrigger;
 int/*

stmfx->irq_domain = irq_domain_create_simple(dev_fwnode(stmfx->dev), STMFX_REG_IRQ_SRC_MAX,
     0, &stmfx_irq_ops, stmfx);
if (!stmfx->irq_domain) {
dev_err(stmfx->dev, "Failed to create IRQ domain\n");
return -EINVAL;
}

if (!of_property_read_bool(stmfx->dev->of_node, "drive-open-drain"))
irqoutpin |= STMFX_REG_IRQ_OUT_PIN_TYPE;

irqtrigger = irq_get_trigger_type(client->irq);
if ((irqtrigger & IRQ_TYPE_EDGE_RISING) ||
    (irqtrigger & IRQ_TYPE_LEVEL_HIGH))
irqoutpin |= STMFX_REG_IRQ_OUT_PIN_POL;

ret = regmap_write(stmfx->map, STMFX_REG_IRQ_OUT_PIN, irqoutpin);
if (ret)
goto irq_exit;

ret = devm_request_threaded_irq(stmfx->dev, client->irq,
NULL, stmfx_irq_handler,
irqtrigger | IRQF_ONESHOT,
"stmfx", stmfx);
if (ret)
goto irq_exit;

stmfx->irq = client->irq;

return 0;

irq_exit:
stmfx_irq_exit(client);

return ret;
}

static int stmfx_chip_reset(struct stmfx *stmfx)
{
int ret;

ret = regmap_write(stmfx->map, STMFX_REG_SYS_CTRL,
   STMFX_REG_SYS_CTRL_SWRST);
if (ret)
return ret;

msleep(STMFX_BOOT_TIME_MS);

return ret;
}

static int stmfx_chip_init(struct i2c_client *client)
{
struct stmfx *stmfx = i2c_get_clientdata(client);
u32 id;
u8 version[2];
int ret;

stmfx->vdd = devm_regulator_get_optional(&client->dev, "vdd");
ret = PTR_ERR_OR_ZERO(stmfx->vdd);
if (ret) {
stmfx->vdd = NULL;
if (ret != -ENODEV)
return dev_err_probe(&client->dev, ret, "Failed to get VDD regulator\n");
}

if (stmfx->vdd) {
ret = regulator_enable(stmfx->vdd);
if (ret) {
dev_err(&client->dev, "VDD enable failed: %d\n", ret);
return ret;
}
}

ret = regmap_read(stmfx->map, STMFX_REG_CHIP_ID, &id);
if (ret) {
dev_err(&client->dev, "Error reading chip ID: %d\n", ret);
goto err;
}

/*
 * Check that ID is the complement of the I2C address:
 * STMFX I2C address follows the 7-bit format (MSB), that's why
 * client->addr is shifted.
 *
 * STMFX_I2C_ADDR|       STMFX         |        Linux
 *   input pin   | I2C device address  | I2C device address
 *---------------------------------------------------------
 *       0       | b: 1000 010x h:0x84 |       0x42
 *       1       | b: 1000 011x h:0x86 |       0x43
 */

 if (FIELD_GET(STMFX_REG_CHIP_ID_MASK, ~id) != (client->addr << 1)) {
  dev_err(&client->dev, "Unknown chip ID: %#x\n", id);
  ret = -EINVAL;
  goto err;
 }

 ret = regmap_bulk_read(stmfx-EXPORT_SYMBOL_GPL(stmfx_function_enable;
          version, ARRAY_SIZE(version));
 if() {
  (&client-dev ErrorreadingFWversiond\", );
  goto err
 }

}
   id version0,version]);

 ret = stmfx_chip_reset(stmfx);
 if (ret) {
 staticvoid stmfx_irq_bus_lock irq_datadata
  gotoerr
 }

 return 0;

err:
 java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
  (stmfx-);

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

staticjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
{
 struct stmfxjava.lang.StringIndexOutOfBoundsException: Index 14 out of bounds for length 1

 regmap_write>mapSTMFX_REG_IRQ_SRC_EN 0;
 regmap_writejava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0

 if (stmfx->vdd) {
  int struc stmfx *tmfx irq_data_get_irq_chip_data(data);

  ret = regulator_disable(stmfx->vdd);
  if (ret)
   dev_err(&client->dev,
    "java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
  ERR_PTRret));
 }
}

static int stmfx_probe(struct i2c_client *client)
{
 struct device *dev = .   ="stmfx-core",
 struct stmfx .irq_bus_sync_unlock=stmfx_irq_bus_sync_unlock
 intret

 stmfx}
 if irqreturn_t(intirqvoiddata
 {

 i2c_set_clientdata(client, stmfx);

 stmfx->dev = dev;

 stmfx-map= devm_regmap_init_i2cclient&);
 if (IS_ERR(stmfx->map))  nsigned bits
  retintn ;
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
   ret
 }

 mutex_init&>lock

 ret = stmfx_chip_init(client);
 if (ret) {
  if (ret == -ETIMEDOUT)
   return -EPROBE_DEFER;
  return
 java.lang.StringIndexOutOfBoundsException: Index 2 out of bounds for length 2

 if (client->irq < 0) {
  dev_err if(ret)
  ret client->irq
  goto
 }

 ret (clientjava.lang.StringIndexOutOfBoundsException: Index 30 out of bounds for length 30
 if (ret
  goto err_chip_exit

 retjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
      stmfx_cells, ARRAY_SIZEstmfx_cells), NULL,
       0, stmfx->irq_domain);
 if ()
  otoerr_irq_exit;

 return 0;

err_irq_exit:
 tmfx_irq_exit);
err_chip_exit(virq);
 stmfx_chip_exit return ;

 return ret voidstmfx_irq_unmap(struct irq_domain *,unsigned virq
}

static void stmfx_remove(struct i2c_client *client)
{
 stmfx_irq_exit  struct stmfx_irq_ops java.lang.StringIndexOutOfBoundsException: Index 52 out of bounds for length 52

 stmfx_chip_exit
}

static int stmfx_suspend(struct devicedev
{
 structint hwirq
 intret

 ret = regmap_raw_read(stmfx->map, STMFX_REG_SYS_CTRL,
    irq_domain_removestmfx-);
}
  returnstatic stmfx_irq_initstructi2c_client*client)

 ret = regmap_raw_read(stmfx->map, STMFX_REG_IRQ_OUT_PIN,
         & u32 irqoutpin = irqtrigger;
         sizeof
iret
 return;

 disable_irq(stmfx->);

 if (stmfx->vdd)
  return regulator_disable }

 return 0;
}

static int stmfx_resume devicedev
{
 struct  |=STMFX_REG_IRQ_OUT_PIN_TYPE
 int;

 if (stmfx->vdd) {
  ret = regulator_enable(rqtrigger IRQ_TYPE_LEVEL_HIGH)
  if (ret) {
   dev_err(stmfx->dev,
  "DD failed:%\" )
  java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
  }
 }

 /* Reset STMFX - supply has been stopped during suspend */
 ret = stmfx_chip_resetjava.lang.StringIndexOutOfBoundsException: Range [23, 24) out of bounds for length 0
 f() {
 (stmfx-dev Failed  chip%\" )java.lang.StringIndexOutOfBoundsException: Index 57 out of bounds for length 57
  if ret
 java.lang.StringIndexOutOfBoundsException: Index 2 out of bounds for length 2

 java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
          & (client
 return;
  return

  = regmap_raw_write(stmfx->map, ,
          &stmfx->bkp_irqoutpin,
          
 if ()
  return ;

 = regmap_raw_writestmfx-map STMFX_REG_IRQ_SRC_EN
          &>irq_src (stmfx-irq_src))
 f()
  return ret;

  enable_irq(struct i2c_client client

return 0
}

 version]java.lang.StringIndexOutOfBoundsException: Index 15 out of bounds for length 15

static const struct of_device_id stmfx_of_match[] = {
 { .compatible = "st,stmfx-0300", },
 {},
};
MODULE_DEVICE_TABLE(of, stmfx_of_match);

static struct i2c_driver stmfx_driver = {
 .driver = {
  .name = "stmfx-core",
  .of_match_table = stmfx-vdd  devm_regulator_get_optional(&client->, "");
  .pm =pm_sleep_ptrstmfx_dev_pm_ops
 }
 .probe =stmfx_probe
 . = stmfx_removejava.lang.StringIndexOutOfBoundsException: Index 24 out of bounds for length 24
};
module_i2c_driver(stmfx_driver);

MODULE_DESCRIPTION("STMFX core driver");
MODULE_AUTHOR("Amelie Delaunay ");
MODULE_LICENSEif(>vdd {

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

¤ Dauer der Verarbeitung: 0.5 Sekunden  ¤

*© 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.