/* * (C) Copyright 2009-2010 * Nokia Siemens Networks, [email protected] * * Portions Copyright (C) 2010 - 2016 Cavium, Inc. * * This file contains the shared part of the driver for the i2c adapter in * Cavium Networks' OCTEON processors and ThunderX SOCs. * * This file is licensed under the terms of the GNU General Public * License version 2. This program is licensed "as is" without any * warranty of any kind, whether express or implied. */ #include <linux/delay.h> #include <linux/i2c.h> #include <linux/interrupt.h> #include <linux/kernel.h> #include <linux/module.h> #include <linux/pci.h> #include "i2c-octeon-core.h" #define INITIAL_DELTA_HZ … #define TWSI_MASTER_CLK_REG_DEF_VAL … #define TWSI_MASTER_CLK_REG_OTX2_VAL … /* interrupt service routine */ irqreturn_t octeon_i2c_isr(int irq, void *dev_id) { … } static bool octeon_i2c_test_iflg(struct octeon_i2c *i2c) { … } /** * octeon_i2c_wait - wait for the IFLG to be set * @i2c: The struct octeon_i2c * * Returns 0 on success, otherwise a negative errno. */ static int octeon_i2c_wait(struct octeon_i2c *i2c) { … } static bool octeon_i2c_hlc_test_valid(struct octeon_i2c *i2c) { … } static void octeon_i2c_hlc_int_clear(struct octeon_i2c *i2c) { … } /* * Cleanup low-level state & enable high-level controller. */ static void octeon_i2c_hlc_enable(struct octeon_i2c *i2c) { … } static void octeon_i2c_hlc_disable(struct octeon_i2c *i2c) { … } /** * octeon_i2c_hlc_wait - wait for an HLC operation to complete * @i2c: The struct octeon_i2c * * Returns 0 on success, otherwise -ETIMEDOUT. */ static int octeon_i2c_hlc_wait(struct octeon_i2c *i2c) { … } static int octeon_i2c_check_status(struct octeon_i2c *i2c, int final_read) { … } static int octeon_i2c_recovery(struct octeon_i2c *i2c) { … } /** * octeon_i2c_start - send START to the bus * @i2c: The struct octeon_i2c * * Returns 0 on success, otherwise a negative errno. */ static int octeon_i2c_start(struct octeon_i2c *i2c) { … } /* send STOP to the bus */ static void octeon_i2c_stop(struct octeon_i2c *i2c) { … } /** * octeon_i2c_read - receive data from the bus via low-level controller * @i2c: The struct octeon_i2c * @target: Target address * @data: Pointer to the location to store the data * @rlength: Length of the data * @recv_len: flag for length byte * * The address is sent over the bus, then the data is read. * * Returns 0 on success, otherwise a negative errno. */ static int octeon_i2c_read(struct octeon_i2c *i2c, int target, u8 *data, u16 *rlength, bool recv_len) { … } /** * octeon_i2c_write - send data to the bus via low-level controller * @i2c: The struct octeon_i2c * @target: Target address * @data: Pointer to the data to be sent * @length: Length of the data * * The address is sent over the bus, then the data. * * Returns 0 on success, otherwise a negative errno. */ static int octeon_i2c_write(struct octeon_i2c *i2c, int target, const u8 *data, int length) { … } /* high-level-controller pure read of up to 8 bytes */ static int octeon_i2c_hlc_read(struct octeon_i2c *i2c, struct i2c_msg *msgs) { … } /* high-level-controller pure write of up to 8 bytes */ static int octeon_i2c_hlc_write(struct octeon_i2c *i2c, struct i2c_msg *msgs) { … } /* high-level-controller composite write+read, msg0=addr, msg1=data */ static int octeon_i2c_hlc_comp_read(struct octeon_i2c *i2c, struct i2c_msg *msgs) { … } /* high-level-controller composite write+write, m[0]len<=2, m[1]len<=8 */ static int octeon_i2c_hlc_comp_write(struct octeon_i2c *i2c, struct i2c_msg *msgs) { … } /** * octeon_i2c_xfer - The driver's xfer function * @adap: Pointer to the i2c_adapter structure * @msgs: Pointer to the messages to be processed * @num: Length of the MSGS array * * Returns the number of messages processed, or a negative errno on failure. */ int octeon_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num) { … } /* calculate and set clock divisors */ void octeon_i2c_set_clock(struct octeon_i2c *i2c) { … } int octeon_i2c_init_lowlevel(struct octeon_i2c *i2c) { … } static int octeon_i2c_get_scl(struct i2c_adapter *adap) { … } static void octeon_i2c_set_scl(struct i2c_adapter *adap, int val) { … } static int octeon_i2c_get_sda(struct i2c_adapter *adap) { … } static void octeon_i2c_prepare_recovery(struct i2c_adapter *adap) { … } static void octeon_i2c_unprepare_recovery(struct i2c_adapter *adap) { … } struct i2c_bus_recovery_info octeon_i2c_recovery_info = …;