Lines Matching +full:semi +full:- +full:static

1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (C) 2006-2007 PA Semi, Inc
5 * SMBus host driver for PA Semi PWRficient
18 #include "i2c-pasemi-core.h"
45 static inline void reg_write(struct pasemi_smbus *smbus, int reg, int val) in reg_write()
47 dev_dbg(smbus->dev, "smbus write reg %x val %08x\n", reg, val); in reg_write()
48 iowrite32(val, smbus->ioaddr + reg); in reg_write()
51 static inline int reg_read(struct pasemi_smbus *smbus, int reg) in reg_read()
54 ret = ioread32(smbus->ioaddr + reg); in reg_read()
55 dev_dbg(smbus->dev, "smbus read reg %x val %08x\n", reg, ret); in reg_read()
62 static void pasemi_reset(struct pasemi_smbus *smbus) in pasemi_reset()
64 u32 val = (CTL_MTR | CTL_MRR | (smbus->clk_div & CTL_CLK_M)); in pasemi_reset()
66 if (smbus->hw_rev >= 6) in pasemi_reset()
70 reinit_completion(&smbus->irq_completion); in pasemi_reset()
73 static void pasemi_smb_clear(struct pasemi_smbus *smbus) in pasemi_smb_clear()
81 static int pasemi_smb_waitready(struct pasemi_smbus *smbus) in pasemi_smb_waitready()
86 if (smbus->use_irq) { in pasemi_smb_waitready()
87 reinit_completion(&smbus->irq_completion); in pasemi_smb_waitready()
89 wait_for_completion_timeout(&smbus->irq_completion, msecs_to_jiffies(100)); in pasemi_smb_waitready()
94 while (!(status & SMSTA_XEN) && timeout--) { in pasemi_smb_waitready()
102 return -ENXIO; in pasemi_smb_waitready()
105 dev_warn(smbus->dev, "Timeout, status 0x%08x\n", status); in pasemi_smb_waitready()
107 return -ETIME; in pasemi_smb_waitready()
116 static int pasemi_i2c_xfer_msg(struct i2c_adapter *adapter, in pasemi_i2c_xfer_msg()
119 struct pasemi_smbus *smbus = adapter->algo_data; in pasemi_i2c_xfer_msg()
123 read = msg->flags & I2C_M_RD ? 1 : 0; in pasemi_i2c_xfer_msg()
128 TXFIFO_WR(smbus, msg->len | MTXFIFO_READ | in pasemi_i2c_xfer_msg()
135 for (i = 0; i < msg->len; i++) { in pasemi_i2c_xfer_msg()
138 err = -ENODATA; in pasemi_i2c_xfer_msg()
141 msg->buf[i] = rd & MRXFIFO_DATA_M; in pasemi_i2c_xfer_msg()
144 for (i = 0; i < msg->len - 1; i++) in pasemi_i2c_xfer_msg()
145 TXFIFO_WR(smbus, msg->buf[i]); in pasemi_i2c_xfer_msg()
147 TXFIFO_WR(smbus, msg->buf[msg->len-1] | in pasemi_i2c_xfer_msg()
164 static int pasemi_i2c_xfer(struct i2c_adapter *adapter, in pasemi_i2c_xfer()
167 struct pasemi_smbus *smbus = adapter->algo_data; in pasemi_i2c_xfer()
175 ret = pasemi_i2c_xfer_msg(adapter, &msgs[i], (i == (num - 1))); in pasemi_i2c_xfer()
180 static int pasemi_smb_xfer(struct i2c_adapter *adapter, in pasemi_smb_xfer()
184 struct pasemi_smbus *smbus = adapter->algo_data; in pasemi_smb_xfer()
189 /* All our ops take 8-bit shifted addresses */ in pasemi_smb_xfer()
214 TXFIFO_WR(smbus, MTXFIFO_STOP | data->byte); in pasemi_smb_xfer()
224 TXFIFO_WR(smbus, data->word & MTXFIFO_DATA_M); in pasemi_smb_xfer()
225 TXFIFO_WR(smbus, MTXFIFO_STOP | (data->word >> 8)); in pasemi_smb_xfer()
240 len = min_t(u8, data->block[0], I2C_SMBUS_BLOCK_MAX); in pasemi_smb_xfer()
243 TXFIFO_WR(smbus, data->block[i]); in pasemi_smb_xfer()
244 TXFIFO_WR(smbus, data->block[len] | MTXFIFO_STOP); in pasemi_smb_xfer()
251 TXFIFO_WR(smbus, data->word & MTXFIFO_DATA_M); in pasemi_smb_xfer()
252 TXFIFO_WR(smbus, (data->word >> 8) & MTXFIFO_DATA_M); in pasemi_smb_xfer()
257 len = min_t(u8, data->block[0], I2C_SMBUS_BLOCK_MAX - 1); in pasemi_smb_xfer()
263 TXFIFO_WR(smbus, data->block[i]); in pasemi_smb_xfer()
268 I2C_SMBUS_BLOCK_MAX - len); in pasemi_smb_xfer()
273 dev_warn(&adapter->dev, "Unsupported transaction %d\n", size); in pasemi_smb_xfer()
274 return -EINVAL; in pasemi_smb_xfer()
289 err = -ENODATA; in pasemi_smb_xfer()
292 data->byte = rd & MRXFIFO_DATA_M; in pasemi_smb_xfer()
298 err = -ENODATA; in pasemi_smb_xfer()
301 data->word = rd & MRXFIFO_DATA_M; in pasemi_smb_xfer()
304 err = -ENODATA; in pasemi_smb_xfer()
307 data->word |= (rd & MRXFIFO_DATA_M) << 8; in pasemi_smb_xfer()
311 data->block[0] = len; in pasemi_smb_xfer()
315 err = -ENODATA; in pasemi_smb_xfer()
318 data->block[i] = rd & MRXFIFO_DATA_M; in pasemi_smb_xfer()
330 static u32 pasemi_smb_func(struct i2c_adapter *adapter) in pasemi_smb_func()
338 static const struct i2c_algorithm smbus_algorithm = {
348 smbus->adapter.owner = THIS_MODULE; in pasemi_i2c_common_probe()
349 snprintf(smbus->adapter.name, sizeof(smbus->adapter.name), in pasemi_i2c_common_probe()
350 "PA Semi SMBus adapter (%s)", dev_name(smbus->dev)); in pasemi_i2c_common_probe()
351 smbus->adapter.algo = &smbus_algorithm; in pasemi_i2c_common_probe()
352 smbus->adapter.algo_data = smbus; in pasemi_i2c_common_probe()
355 smbus->adapter.dev.parent = smbus->dev; in pasemi_i2c_common_probe()
356 smbus->use_irq = 0; in pasemi_i2c_common_probe()
357 init_completion(&smbus->irq_completion); in pasemi_i2c_common_probe()
359 if (smbus->hw_rev != PASEMI_HW_REV_PCI) in pasemi_i2c_common_probe()
360 smbus->hw_rev = reg_read(smbus, REG_REV); in pasemi_i2c_common_probe()
366 error = devm_i2c_add_adapter(smbus->dev, &smbus->adapter); in pasemi_i2c_common_probe()
379 complete(&smbus->irq_completion); in pasemi_irq_handler()
386 MODULE_DESCRIPTION("PA Semi PWRficient SMBus driver");