1*acd6199fSWentong Wu /* SPDX-License-Identifier: GPL-2.0-only */ 2*acd6199fSWentong Wu /* 3*acd6199fSWentong Wu * Copyright (c) 2023, Intel Corporation. All rights reserved. 4*acd6199fSWentong Wu */ 5*acd6199fSWentong Wu #ifndef _LINUX_USB_LJCA_H_ 6*acd6199fSWentong Wu #define _LINUX_USB_LJCA_H_ 7*acd6199fSWentong Wu 8*acd6199fSWentong Wu #include <linux/auxiliary_bus.h> 9*acd6199fSWentong Wu #include <linux/list.h> 10*acd6199fSWentong Wu #include <linux/spinlock.h> 11*acd6199fSWentong Wu #include <linux/types.h> 12*acd6199fSWentong Wu 13*acd6199fSWentong Wu #define LJCA_MAX_GPIO_NUM 64 14*acd6199fSWentong Wu 15*acd6199fSWentong Wu #define auxiliary_dev_to_ljca_client(auxiliary_dev) \ 16*acd6199fSWentong Wu container_of(auxiliary_dev, struct ljca_client, auxdev) 17*acd6199fSWentong Wu 18*acd6199fSWentong Wu struct ljca_adapter; 19*acd6199fSWentong Wu 20*acd6199fSWentong Wu /** 21*acd6199fSWentong Wu * typedef ljca_event_cb_t - event callback function signature 22*acd6199fSWentong Wu * 23*acd6199fSWentong Wu * @context: the execution context of who registered this callback 24*acd6199fSWentong Wu * @cmd: the command from device for this event 25*acd6199fSWentong Wu * @evt_data: the event data payload 26*acd6199fSWentong Wu * @len: the event data payload length 27*acd6199fSWentong Wu * 28*acd6199fSWentong Wu * The callback function is called in interrupt context and the data payload is 29*acd6199fSWentong Wu * only valid during the call. If the user needs later access of the data, it 30*acd6199fSWentong Wu * must copy it. 31*acd6199fSWentong Wu */ 32*acd6199fSWentong Wu typedef void (*ljca_event_cb_t)(void *context, u8 cmd, const void *evt_data, int len); 33*acd6199fSWentong Wu 34*acd6199fSWentong Wu /** 35*acd6199fSWentong Wu * struct ljca_client - represent a ljca client device 36*acd6199fSWentong Wu * 37*acd6199fSWentong Wu * @type: ljca client type 38*acd6199fSWentong Wu * @id: ljca client id within same client type 39*acd6199fSWentong Wu * @link: ljca client on the same ljca adapter 40*acd6199fSWentong Wu * @auxdev: auxiliary device object 41*acd6199fSWentong Wu * @adapter: ljca adapter the ljca client sit on 42*acd6199fSWentong Wu * @context: the execution context of the event callback 43*acd6199fSWentong Wu * @event_cb: ljca client driver register this callback to get 44*acd6199fSWentong Wu * firmware asynchronous rx buffer pending notifications 45*acd6199fSWentong Wu * @event_cb_lock: spinlock to protect event callback 46*acd6199fSWentong Wu */ 47*acd6199fSWentong Wu struct ljca_client { 48*acd6199fSWentong Wu u8 type; 49*acd6199fSWentong Wu u8 id; 50*acd6199fSWentong Wu struct list_head link; 51*acd6199fSWentong Wu struct auxiliary_device auxdev; 52*acd6199fSWentong Wu struct ljca_adapter *adapter; 53*acd6199fSWentong Wu 54*acd6199fSWentong Wu void *context; 55*acd6199fSWentong Wu ljca_event_cb_t event_cb; 56*acd6199fSWentong Wu /* lock to protect event_cb */ 57*acd6199fSWentong Wu spinlock_t event_cb_lock; 58*acd6199fSWentong Wu }; 59*acd6199fSWentong Wu 60*acd6199fSWentong Wu /** 61*acd6199fSWentong Wu * struct ljca_gpio_info - ljca gpio client device info 62*acd6199fSWentong Wu * 63*acd6199fSWentong Wu * @num: ljca gpio client device pin number 64*acd6199fSWentong Wu * @valid_pin_map: ljca gpio client device valid pin mapping 65*acd6199fSWentong Wu */ 66*acd6199fSWentong Wu struct ljca_gpio_info { 67*acd6199fSWentong Wu unsigned int num; 68*acd6199fSWentong Wu DECLARE_BITMAP(valid_pin_map, LJCA_MAX_GPIO_NUM); 69*acd6199fSWentong Wu }; 70*acd6199fSWentong Wu 71*acd6199fSWentong Wu /** 72*acd6199fSWentong Wu * struct ljca_i2c_info - ljca i2c client device info 73*acd6199fSWentong Wu * 74*acd6199fSWentong Wu * @id: ljca i2c client device identification number 75*acd6199fSWentong Wu * @capacity: ljca i2c client device capacity 76*acd6199fSWentong Wu * @intr_pin: ljca i2c client device interrupt pin number if exists 77*acd6199fSWentong Wu */ 78*acd6199fSWentong Wu struct ljca_i2c_info { 79*acd6199fSWentong Wu u8 id; 80*acd6199fSWentong Wu u8 capacity; 81*acd6199fSWentong Wu u8 intr_pin; 82*acd6199fSWentong Wu }; 83*acd6199fSWentong Wu 84*acd6199fSWentong Wu /** 85*acd6199fSWentong Wu * struct ljca_spi_info - ljca spi client device info 86*acd6199fSWentong Wu * 87*acd6199fSWentong Wu * @id: ljca spi client device identification number 88*acd6199fSWentong Wu * @capacity: ljca spi client device capacity 89*acd6199fSWentong Wu */ 90*acd6199fSWentong Wu struct ljca_spi_info { 91*acd6199fSWentong Wu u8 id; 92*acd6199fSWentong Wu u8 capacity; 93*acd6199fSWentong Wu }; 94*acd6199fSWentong Wu 95*acd6199fSWentong Wu /** 96*acd6199fSWentong Wu * ljca_register_event_cb - register a callback function to receive events 97*acd6199fSWentong Wu * 98*acd6199fSWentong Wu * @client: ljca client device 99*acd6199fSWentong Wu * @event_cb: callback function 100*acd6199fSWentong Wu * @context: execution context of event callback 101*acd6199fSWentong Wu * 102*acd6199fSWentong Wu * Return: 0 in case of success, negative value in case of error 103*acd6199fSWentong Wu */ 104*acd6199fSWentong Wu int ljca_register_event_cb(struct ljca_client *client, ljca_event_cb_t event_cb, void *context); 105*acd6199fSWentong Wu 106*acd6199fSWentong Wu /** 107*acd6199fSWentong Wu * ljca_unregister_event_cb - unregister the callback function for an event 108*acd6199fSWentong Wu * 109*acd6199fSWentong Wu * @client: ljca client device 110*acd6199fSWentong Wu */ 111*acd6199fSWentong Wu void ljca_unregister_event_cb(struct ljca_client *client); 112*acd6199fSWentong Wu 113*acd6199fSWentong Wu /** 114*acd6199fSWentong Wu * ljca_transfer - issue a LJCA command and wait for a response 115*acd6199fSWentong Wu * 116*acd6199fSWentong Wu * @client: ljca client device 117*acd6199fSWentong Wu * @cmd: the command to be sent to the device 118*acd6199fSWentong Wu * @obuf: the buffer to be sent to the device; it can be NULL if the user 119*acd6199fSWentong Wu * doesn't need to transmit data with this command 120*acd6199fSWentong Wu * @obuf_len: the size of the buffer to be sent to the device; it should 121*acd6199fSWentong Wu * be 0 when obuf is NULL 122*acd6199fSWentong Wu * @ibuf: any data associated with the response will be copied here; it can be 123*acd6199fSWentong Wu * NULL if the user doesn't need the response data 124*acd6199fSWentong Wu * @ibuf_len: must be initialized to the input buffer size 125*acd6199fSWentong Wu * 126*acd6199fSWentong Wu * Return: the actual length of response data for success, negative value for errors 127*acd6199fSWentong Wu */ 128*acd6199fSWentong Wu int ljca_transfer(struct ljca_client *client, u8 cmd, const u8 *obuf, 129*acd6199fSWentong Wu u8 obuf_len, u8 *ibuf, u8 ibuf_len); 130*acd6199fSWentong Wu 131*acd6199fSWentong Wu /** 132*acd6199fSWentong Wu * ljca_transfer_noack - issue a LJCA command without a response 133*acd6199fSWentong Wu * 134*acd6199fSWentong Wu * @client: ljca client device 135*acd6199fSWentong Wu * @cmd: the command to be sent to the device 136*acd6199fSWentong Wu * @obuf: the buffer to be sent to the device; it can be NULL if the user 137*acd6199fSWentong Wu * doesn't need to transmit data with this command 138*acd6199fSWentong Wu * @obuf_len: the size of the buffer to be sent to the device 139*acd6199fSWentong Wu * 140*acd6199fSWentong Wu * Return: 0 for success, negative value for errors 141*acd6199fSWentong Wu */ 142*acd6199fSWentong Wu int ljca_transfer_noack(struct ljca_client *client, u8 cmd, const u8 *obuf, 143*acd6199fSWentong Wu u8 obuf_len); 144*acd6199fSWentong Wu 145*acd6199fSWentong Wu #endif 146