xref: /qemu/include/hw/i2c/npcm7xx_smbus.h (revision fc524567087c2537b5103cdfc1d41e4f442892b6)
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 
19*8be545baSRichard Henderson #include "system/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 
306b6e7570SHao Wu /* Size of the FIFO buffer. */
316b6e7570SHao Wu #define NPCM7XX_SMBUS_FIFO_SIZE 16
326b6e7570SHao 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.
596b6e7570SHao Wu  * @fif_ctl: The FIFO control register.
606b6e7570SHao Wu  * @fif_cts: The FIFO control status register.
618fa21b80SMichael Tokarev  * @fair_per: The fair period register.
626b6e7570SHao Wu  * @txf_ctl: The transmit FIFO control register.
636b6e7570SHao Wu  * @t_out: The SMBus timeout register.
646b6e7570SHao Wu  * @txf_sts: The transmit FIFO status register.
656b6e7570SHao Wu  * @rxf_sts: The receive FIFO status register.
666b6e7570SHao Wu  * @rxf_ctl: The receive FIFO control register.
676b6e7570SHao Wu  * @rx_fifo: The FIFO buffer for receiving in FIFO mode.
686b6e7570SHao Wu  * @rx_cur: The current position of rx_fifo.
6994e77879SHao Wu  * @status: The current status of the SMBus.
7094e77879SHao Wu  */
71c79aa350SPhilippe Mathieu-Daudé 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 
946b6e7570SHao Wu     uint8_t      fif_ctl;
956b6e7570SHao Wu     uint8_t      fif_cts;
966b6e7570SHao Wu     uint8_t      fair_per;
976b6e7570SHao Wu     uint8_t      txf_ctl;
986b6e7570SHao Wu     uint8_t      t_out;
996b6e7570SHao Wu     uint8_t      txf_sts;
1006b6e7570SHao Wu     uint8_t      rxf_sts;
1016b6e7570SHao Wu     uint8_t      rxf_ctl;
1026b6e7570SHao Wu 
1036b6e7570SHao Wu     uint8_t      rx_fifo[NPCM7XX_SMBUS_FIFO_SIZE];
1046b6e7570SHao Wu     uint8_t      rx_cur;
1056b6e7570SHao Wu 
10694e77879SHao Wu     NPCM7xxSMBusStatus status;
107c79aa350SPhilippe Mathieu-Daudé };
10894e77879SHao Wu 
10994e77879SHao Wu #define TYPE_NPCM7XX_SMBUS "npcm7xx-smbus"
110c79aa350SPhilippe Mathieu-Daudé OBJECT_DECLARE_SIMPLE_TYPE(NPCM7xxSMBusState, NPCM7XX_SMBUS)
11194e77879SHao Wu 
11294e77879SHao Wu #endif /* NPCM7XX_SMBUS_H */
113