linux/drivers/gpu/drm/nouveau/core/include/subdev/i2c.h
<<
>>
Prefs
   1#ifndef __NOUVEAU_I2C_H__
   2#define __NOUVEAU_I2C_H__
   3
   4#include <core/subdev.h>
   5#include <core/device.h>
   6
   7#include <subdev/bios.h>
   8#include <subdev/bios/i2c.h>
   9
  10#define NV_I2C_PORT(n)    (0x00 + (n))
  11#define NV_I2C_DEFAULT(n) (0x80 + (n))
  12
  13#define NV_I2C_TYPE_DCBI2C(n) (0x0000 | (n))
  14#define NV_I2C_TYPE_EXTDDC(e) (0x0005 | (e) << 8)
  15#define NV_I2C_TYPE_EXTAUX(e) (0x0006 | (e) << 8)
  16
  17struct nvkm_i2c_ntfy_req {
  18#define NVKM_I2C_PLUG                                                      0x01
  19#define NVKM_I2C_UNPLUG                                                    0x02
  20#define NVKM_I2C_IRQ                                                       0x04
  21#define NVKM_I2C_DONE                                                      0x08
  22#define NVKM_I2C_ANY                                                       0x0f
  23        u8 mask;
  24        u8 port;
  25};
  26
  27struct nvkm_i2c_ntfy_rep {
  28        u8 mask;
  29};
  30
  31struct nouveau_i2c_port {
  32        struct nouveau_object base;
  33        struct i2c_adapter adapter;
  34        struct mutex mutex;
  35
  36        struct list_head head;
  37        u8  index;
  38        int aux;
  39
  40        const struct nouveau_i2c_func *func;
  41};
  42
  43struct nouveau_i2c_func {
  44        void (*drive_scl)(struct nouveau_i2c_port *, int);
  45        void (*drive_sda)(struct nouveau_i2c_port *, int);
  46        int  (*sense_scl)(struct nouveau_i2c_port *);
  47        int  (*sense_sda)(struct nouveau_i2c_port *);
  48
  49        int  (*aux)(struct nouveau_i2c_port *, bool, u8, u32, u8 *, u8);
  50        int  (*pattern)(struct nouveau_i2c_port *, int pattern);
  51        int  (*lnk_ctl)(struct nouveau_i2c_port *, int nr, int bw, bool enh);
  52        int  (*drv_ctl)(struct nouveau_i2c_port *, int lane, int sw, int pe);
  53};
  54
  55struct nouveau_i2c_board_info {
  56        struct i2c_board_info dev;
  57        u8 udelay; /* set to 0 to use the standard delay */
  58};
  59
  60struct nouveau_i2c {
  61        struct nouveau_subdev base;
  62        struct nvkm_event event;
  63
  64        struct nouveau_i2c_port *(*find)(struct nouveau_i2c *, u8 index);
  65        struct nouveau_i2c_port *(*find_type)(struct nouveau_i2c *, u16 type);
  66        int  (*acquire_pad)(struct nouveau_i2c_port *, unsigned long timeout);
  67        void (*release_pad)(struct nouveau_i2c_port *);
  68        int  (*acquire)(struct nouveau_i2c_port *, unsigned long timeout);
  69        void (*release)(struct nouveau_i2c_port *);
  70        int (*identify)(struct nouveau_i2c *, int index,
  71                        const char *what, struct nouveau_i2c_board_info *,
  72                        bool (*match)(struct nouveau_i2c_port *,
  73                                      struct i2c_board_info *, void *), void *);
  74
  75        wait_queue_head_t wait;
  76        struct list_head ports;
  77};
  78
  79static inline struct nouveau_i2c *
  80nouveau_i2c(void *obj)
  81{
  82        return (void *)nv_device(obj)->subdev[NVDEV_SUBDEV_I2C];
  83}
  84
  85extern struct nouveau_oclass *nv04_i2c_oclass;
  86extern struct nouveau_oclass *nv4e_i2c_oclass;
  87extern struct nouveau_oclass *nv50_i2c_oclass;
  88extern struct nouveau_oclass *nv94_i2c_oclass;
  89extern struct nouveau_oclass *nvd0_i2c_oclass;
  90extern struct nouveau_oclass *gf117_i2c_oclass;
  91extern struct nouveau_oclass *nve0_i2c_oclass;
  92
  93static inline int
  94nv_rdi2cr(struct nouveau_i2c_port *port, u8 addr, u8 reg)
  95{
  96        u8 val;
  97        struct i2c_msg msgs[] = {
  98                { .addr = addr, .flags = 0, .len = 1, .buf = &reg },
  99                { .addr = addr, .flags = I2C_M_RD, .len = 1, .buf = &val },
 100        };
 101
 102        int ret = i2c_transfer(&port->adapter, msgs, 2);
 103        if (ret != 2)
 104                return -EIO;
 105
 106        return val;
 107}
 108
 109static inline int
 110nv_wri2cr(struct nouveau_i2c_port *port, u8 addr, u8 reg, u8 val)
 111{
 112        u8 buf[2] = { reg, val };
 113        struct i2c_msg msgs[] = {
 114                { .addr = addr, .flags = 0, .len = 2, .buf = buf },
 115        };
 116
 117        int ret = i2c_transfer(&port->adapter, msgs, 1);
 118        if (ret != 1)
 119                return -EIO;
 120
 121        return 0;
 122}
 123
 124static inline bool
 125nv_probe_i2c(struct nouveau_i2c_port *port, u8 addr)
 126{
 127        return nv_rdi2cr(port, addr, 0) >= 0;
 128}
 129
 130int nv_rdaux(struct nouveau_i2c_port *, u32 addr, u8 *data, u8 size);
 131int nv_wraux(struct nouveau_i2c_port *, u32 addr, u8 *data, u8 size);
 132
 133#endif
 134