xref: /qemu/include/hw/i2c/npcm7xx_smbus.h (revision 6b6e7570d6ebc8bc6d9bc1356ae46708f02d3eeb)
194e77879SHao Wu /*
294e77879SHao Wu  * Nuvoton NPCM7xx SMBus Module.
394e77879SHao Wu  *
494e77879SHao Wu  * Copyright 2020 Google LLC
594e77879SHao Wu  *
694e77879SHao Wu  * This program is free software; you can redistribute it and/or modify it
794e77879SHao Wu  * under the terms of the GNU General Public License as published by the
894e77879SHao Wu  * Free Software Foundation; either version 2 of the License, or
994e77879SHao Wu  * (at your option) any later version.
1094e77879SHao Wu  *
1194e77879SHao Wu  * This program is distributed in the hope that it will be useful, but WITHOUT
1294e77879SHao Wu  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1394e77879SHao Wu  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
1494e77879SHao Wu  * for more details.
1594e77879SHao Wu  */
1694e77879SHao Wu #ifndef NPCM7XX_SMBUS_H
1794e77879SHao Wu #define NPCM7XX_SMBUS_H
1894e77879SHao Wu 
1994e77879SHao Wu #include "exec/memory.h"
2094e77879SHao Wu #include "hw/i2c/i2c.h"
2194e77879SHao Wu #include "hw/irq.h"
2294e77879SHao Wu #include "hw/sysbus.h"
2394e77879SHao Wu 
2494e77879SHao Wu /*
2594e77879SHao Wu  * Number of addresses this module contains. Do not change this without
2694e77879SHao Wu  * incrementing the version_id in the vmstate.
2794e77879SHao Wu  */
2894e77879SHao Wu #define NPCM7XX_SMBUS_NR_ADDRS 10
2994e77879SHao Wu 
30*6b6e7570SHao Wu /* Size of the FIFO buffer. */
31*6b6e7570SHao Wu #define NPCM7XX_SMBUS_FIFO_SIZE 16
32*6b6e7570SHao Wu 
3394e77879SHao Wu typedef enum NPCM7xxSMBusStatus {
3494e77879SHao Wu     NPCM7XX_SMBUS_STATUS_IDLE,
3594e77879SHao Wu     NPCM7XX_SMBUS_STATUS_SENDING,
3694e77879SHao Wu     NPCM7XX_SMBUS_STATUS_RECEIVING,
3794e77879SHao Wu     NPCM7XX_SMBUS_STATUS_NEGACK,
3894e77879SHao Wu     NPCM7XX_SMBUS_STATUS_STOPPING_LAST_RECEIVE,
3994e77879SHao Wu     NPCM7XX_SMBUS_STATUS_STOPPING_NEGACK,
4094e77879SHao Wu } NPCM7xxSMBusStatus;
4194e77879SHao Wu 
4294e77879SHao Wu /*
4394e77879SHao Wu  * struct NPCM7xxSMBusState - System Management Bus device state.
4494e77879SHao Wu  * @bus: The underlying I2C Bus.
4594e77879SHao Wu  * @irq: GIC interrupt line to fire on events (if enabled).
4694e77879SHao Wu  * @sda: The serial data register.
4794e77879SHao Wu  * @st: The status register.
4894e77879SHao Wu  * @cst: The control status register.
4994e77879SHao Wu  * @cst2: The control status register 2.
5094e77879SHao Wu  * @cst3: The control status register 3.
5194e77879SHao Wu  * @ctl1: The control register 1.
5294e77879SHao Wu  * @ctl2: The control register 2.
5394e77879SHao Wu  * @ctl3: The control register 3.
5494e77879SHao Wu  * @ctl4: The control register 4.
5594e77879SHao Wu  * @ctl5: The control register 5.
5694e77879SHao Wu  * @addr: The SMBus module's own addresses on the I2C bus.
5794e77879SHao Wu  * @scllt: The SCL low time register.
5894e77879SHao Wu  * @sclht: The SCL high time register.
59*6b6e7570SHao Wu  * @fif_ctl: The FIFO control register.
60*6b6e7570SHao Wu  * @fif_cts: The FIFO control status register.
61*6b6e7570SHao Wu  * @fair_per: The fair preriod register.
62*6b6e7570SHao Wu  * @txf_ctl: The transmit FIFO control register.
63*6b6e7570SHao Wu  * @t_out: The SMBus timeout register.
64*6b6e7570SHao Wu  * @txf_sts: The transmit FIFO status register.
65*6b6e7570SHao Wu  * @rxf_sts: The receive FIFO status register.
66*6b6e7570SHao Wu  * @rxf_ctl: The receive FIFO control register.
67*6b6e7570SHao Wu  * @rx_fifo: The FIFO buffer for receiving in FIFO mode.
68*6b6e7570SHao Wu  * @rx_cur: The current position of rx_fifo.
6994e77879SHao Wu  * @status: The current status of the SMBus.
7094e77879SHao Wu  */
7194e77879SHao Wu typedef struct NPCM7xxSMBusState {
7294e77879SHao Wu     SysBusDevice parent;
7394e77879SHao Wu 
7494e77879SHao Wu     MemoryRegion iomem;
7594e77879SHao Wu 
7694e77879SHao Wu     I2CBus      *bus;
7794e77879SHao Wu     qemu_irq     irq;
7894e77879SHao Wu 
7994e77879SHao Wu     uint8_t      sda;
8094e77879SHao Wu     uint8_t      st;
8194e77879SHao Wu     uint8_t      cst;
8294e77879SHao Wu     uint8_t      cst2;
8394e77879SHao Wu     uint8_t      cst3;
8494e77879SHao Wu     uint8_t      ctl1;
8594e77879SHao Wu     uint8_t      ctl2;
8694e77879SHao Wu     uint8_t      ctl3;
8794e77879SHao Wu     uint8_t      ctl4;
8894e77879SHao Wu     uint8_t      ctl5;
8994e77879SHao Wu     uint8_t      addr[NPCM7XX_SMBUS_NR_ADDRS];
9094e77879SHao Wu 
9194e77879SHao Wu     uint8_t      scllt;
9294e77879SHao Wu     uint8_t      sclht;
9394e77879SHao Wu 
94*6b6e7570SHao Wu     uint8_t      fif_ctl;
95*6b6e7570SHao Wu     uint8_t      fif_cts;
96*6b6e7570SHao Wu     uint8_t      fair_per;
97*6b6e7570SHao Wu     uint8_t      txf_ctl;
98*6b6e7570SHao Wu     uint8_t      t_out;
99*6b6e7570SHao Wu     uint8_t      txf_sts;
100*6b6e7570SHao Wu     uint8_t      rxf_sts;
101*6b6e7570SHao Wu     uint8_t      rxf_ctl;
102*6b6e7570SHao Wu 
103*6b6e7570SHao Wu     uint8_t      rx_fifo[NPCM7XX_SMBUS_FIFO_SIZE];
104*6b6e7570SHao Wu     uint8_t      rx_cur;
105*6b6e7570SHao Wu 
10694e77879SHao Wu     NPCM7xxSMBusStatus status;
10794e77879SHao Wu } NPCM7xxSMBusState;
10894e77879SHao Wu 
10994e77879SHao Wu #define TYPE_NPCM7XX_SMBUS "npcm7xx-smbus"
11094e77879SHao Wu #define NPCM7XX_SMBUS(obj) OBJECT_CHECK(NPCM7xxSMBusState, (obj), \
11194e77879SHao Wu                                         TYPE_NPCM7XX_SMBUS)
11294e77879SHao Wu 
11394e77879SHao Wu #endif /* NPCM7XX_SMBUS_H */
114