18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */ 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * Copyright 2011 Florian Tobias Schandinat <FlorianSchandinat@gmx.de> 48c2ecf20Sopenharmony_ci */ 58c2ecf20Sopenharmony_ci/* 68c2ecf20Sopenharmony_ci * infrastructure for devices connected via I2C 78c2ecf20Sopenharmony_ci */ 88c2ecf20Sopenharmony_ci 98c2ecf20Sopenharmony_ci#ifndef __VIA_AUX_H__ 108c2ecf20Sopenharmony_ci#define __VIA_AUX_H__ 118c2ecf20Sopenharmony_ci 128c2ecf20Sopenharmony_ci 138c2ecf20Sopenharmony_ci#include <linux/list.h> 148c2ecf20Sopenharmony_ci#include <linux/i2c.h> 158c2ecf20Sopenharmony_ci#include <linux/fb.h> 168c2ecf20Sopenharmony_ci 178c2ecf20Sopenharmony_ci 188c2ecf20Sopenharmony_cistruct via_aux_bus { 198c2ecf20Sopenharmony_ci struct i2c_adapter *adap; /* the I2C device to access the bus */ 208c2ecf20Sopenharmony_ci struct list_head drivers; /* drivers for devices on this bus */ 218c2ecf20Sopenharmony_ci}; 228c2ecf20Sopenharmony_ci 238c2ecf20Sopenharmony_cistruct via_aux_drv { 248c2ecf20Sopenharmony_ci struct list_head chain; /* chain to support multiple drivers */ 258c2ecf20Sopenharmony_ci 268c2ecf20Sopenharmony_ci struct via_aux_bus *bus; /* the I2C bus used */ 278c2ecf20Sopenharmony_ci u8 addr; /* the I2C slave address */ 288c2ecf20Sopenharmony_ci 298c2ecf20Sopenharmony_ci const char *name; /* human readable name of the driver */ 308c2ecf20Sopenharmony_ci void *data; /* private data of this driver */ 318c2ecf20Sopenharmony_ci 328c2ecf20Sopenharmony_ci void (*cleanup)(struct via_aux_drv *drv); 338c2ecf20Sopenharmony_ci const struct fb_videomode* (*get_preferred_mode) 348c2ecf20Sopenharmony_ci (struct via_aux_drv *drv); 358c2ecf20Sopenharmony_ci}; 368c2ecf20Sopenharmony_ci 378c2ecf20Sopenharmony_ci 388c2ecf20Sopenharmony_cistruct via_aux_bus *via_aux_probe(struct i2c_adapter *adap); 398c2ecf20Sopenharmony_civoid via_aux_free(struct via_aux_bus *bus); 408c2ecf20Sopenharmony_ciconst struct fb_videomode *via_aux_get_preferred_mode(struct via_aux_bus *bus); 418c2ecf20Sopenharmony_ci 428c2ecf20Sopenharmony_ci 438c2ecf20Sopenharmony_cistatic inline bool via_aux_add(struct via_aux_drv *drv) 448c2ecf20Sopenharmony_ci{ 458c2ecf20Sopenharmony_ci struct via_aux_drv *data = kmalloc(sizeof(*data), GFP_KERNEL); 468c2ecf20Sopenharmony_ci 478c2ecf20Sopenharmony_ci if (!data) 488c2ecf20Sopenharmony_ci return false; 498c2ecf20Sopenharmony_ci 508c2ecf20Sopenharmony_ci *data = *drv; 518c2ecf20Sopenharmony_ci list_add_tail(&data->chain, &data->bus->drivers); 528c2ecf20Sopenharmony_ci return true; 538c2ecf20Sopenharmony_ci} 548c2ecf20Sopenharmony_ci 558c2ecf20Sopenharmony_cistatic inline bool via_aux_read(struct via_aux_drv *drv, u8 start, u8 *buf, 568c2ecf20Sopenharmony_ci u8 len) 578c2ecf20Sopenharmony_ci{ 588c2ecf20Sopenharmony_ci struct i2c_msg msg[2] = { 598c2ecf20Sopenharmony_ci {.addr = drv->addr, .flags = 0, .len = 1, .buf = &start}, 608c2ecf20Sopenharmony_ci {.addr = drv->addr, .flags = I2C_M_RD, .len = len, .buf = buf} }; 618c2ecf20Sopenharmony_ci 628c2ecf20Sopenharmony_ci return i2c_transfer(drv->bus->adap, msg, 2) == 2; 638c2ecf20Sopenharmony_ci} 648c2ecf20Sopenharmony_ci 658c2ecf20Sopenharmony_ci 668c2ecf20Sopenharmony_ci/* probe functions of existing drivers - should only be called in via_aux.c */ 678c2ecf20Sopenharmony_civoid via_aux_ch7301_probe(struct via_aux_bus *bus); 688c2ecf20Sopenharmony_civoid via_aux_edid_probe(struct via_aux_bus *bus); 698c2ecf20Sopenharmony_civoid via_aux_sii164_probe(struct via_aux_bus *bus); 708c2ecf20Sopenharmony_civoid via_aux_vt1636_probe(struct via_aux_bus *bus); 718c2ecf20Sopenharmony_civoid via_aux_vt1632_probe(struct via_aux_bus *bus); 728c2ecf20Sopenharmony_civoid via_aux_vt1631_probe(struct via_aux_bus *bus); 738c2ecf20Sopenharmony_civoid via_aux_vt1625_probe(struct via_aux_bus *bus); 748c2ecf20Sopenharmony_civoid via_aux_vt1622_probe(struct via_aux_bus *bus); 758c2ecf20Sopenharmony_civoid via_aux_vt1621_probe(struct via_aux_bus *bus); 768c2ecf20Sopenharmony_ci 778c2ecf20Sopenharmony_ci 788c2ecf20Sopenharmony_ci#endif /* __VIA_AUX_H__ */ 79