Commit 338a1281 authored by Octavian Purdila's avatar Octavian Purdila Committed by Lee Jones

mfd: Add support for Diolan DLN-2 devices

This patch implements the USB part of the Diolan USB-I2C/SPI/GPIO
Master Adapter DLN-2. Details about the device can be found here:

https://www.diolan.com/i2c/i2c_interface.html.

Information about the USB protocol can be found in the Programmer's
Reference Manual [1], see section 1.7.

Because the hardware has a single transmit endpoint and a single
receive endpoint the communication between the various DLN2 drivers
and the hardware will be muxed/demuxed by this driver.

Each DLN2 module will be identified by the handle field within the DLN2
message header. If a DLN2 module issues multiple commands in parallel
they will be identified by the echo counter field in the message header.

The DLN2 modules can use the dln2_transfer() function to issue a
command and wait for its response. They can also register a callback
that is going to be called when a specific event id is generated by
the device (e.g. GPIO interrupts). The device uses handle 0 for
sending events.

[1] https://www.diolan.com/downloads/dln-api-manual.pdfSigned-off-by: default avatarOctavian Purdila <octavian.purdila@intel.com>
Reviewed-by: default avatarJohan Hovold <johan@kernel.org>
Signed-off-by: default avatarLee Jones <lee.jones@linaro.org>
parent a7975473
......@@ -183,6 +183,16 @@ config MFD_DA9063
Additional drivers must be enabled in order to use the functionality
of the device.
config MFD_DLN2
tristate "Diolan DLN2 support"
select MFD_CORE
depends on USB
help
This adds support for Diolan USB-I2C/SPI/GPIO Master Adapter
DLN-2. Additional drivers such as I2C_DLN2, GPIO_DLN2,
etc. must be enabled in order to use the functionality of
the device.
config MFD_MC13XXX
tristate
depends on (SPI_MASTER || I2C)
......
......@@ -174,6 +174,7 @@ obj-$(CONFIG_MFD_STW481X) += stw481x.o
obj-$(CONFIG_MFD_IPAQ_MICRO) += ipaq-micro.o
obj-$(CONFIG_MFD_MENF21BMC) += menf21bmc.o
obj-$(CONFIG_MFD_HI6421_PMIC) += hi6421-pmic-core.o
obj-$(CONFIG_MFD_DLN2) += dln2.o
intel-soc-pmic-objs := intel_soc_pmic_core.o intel_soc_pmic_crc.o
obj-$(CONFIG_INTEL_SOC_PMIC) += intel-soc-pmic.o
This diff is collapsed.
#ifndef __LINUX_USB_DLN2_H
#define __LINUX_USB_DLN2_H
#define DLN2_CMD(cmd, id) ((cmd) | ((id) << 8))
struct dln2_platform_data {
u16 handle; /* sub-driver handle (internally used only) */
u8 port; /* I2C/SPI port */
};
/**
* dln2_event_cb_t - event callback function signature
*
* @pdev - the sub-device that registered this callback
* @echo - the echo header field received in the message
* @data - the data payload
* @len - the data payload length
*
* The callback function is called in interrupt context and the data payload is
* only valid during the call. If the user needs later access of the data, it
* must copy it.
*/
typedef void (*dln2_event_cb_t)(struct platform_device *pdev, u16 echo,
const void *data, int len);
/**
* dl2n_register_event_cb - register a callback function for an event
*
* @pdev - the sub-device that registers the callback
* @event - the event for which to register a callback
* @event_cb - the callback function
*
* @return 0 in case of success, negative value in case of error
*/
int dln2_register_event_cb(struct platform_device *pdev, u16 event,
dln2_event_cb_t event_cb);
/**
* dln2_unregister_event_cb - unregister the callback function for an event
*
* @pdev - the sub-device that registered the callback
* @event - the event for which to register a callback
*/
void dln2_unregister_event_cb(struct platform_device *pdev, u16 event);
/**
* dln2_transfer - issue a DLN2 command and wait for a response and the
* associated data
*
* @pdev - the sub-device which is issuing this transfer
* @cmd - the command to be sent to the device
* @obuf - the buffer to be sent to the device; it can be NULL if the user
* doesn't need to transmit data with this command
* @obuf_len - the size of the buffer to be sent to the device
* @ibuf - any data associated with the response will be copied here; it can be
* NULL if the user doesn't need the response data
* @ibuf_len - must be initialized to the input buffer size; it will be modified
* to indicate the actual data transferred;
*
* @return 0 for success, negative value for errors
*/
int dln2_transfer(struct platform_device *pdev, u16 cmd,
const void *obuf, unsigned obuf_len,
void *ibuf, unsigned *ibuf_len);
/**
* dln2_transfer_rx - variant of @dln2_transfer() where TX buffer is not needed
*
* @pdev - the sub-device which is issuing this transfer
* @cmd - the command to be sent to the device
* @ibuf - any data associated with the response will be copied here; it can be
* NULL if the user doesn't need the response data
* @ibuf_len - must be initialized to the input buffer size; it will be modified
* to indicate the actual data transferred;
*
* @return 0 for success, negative value for errors
*/
static inline int dln2_transfer_rx(struct platform_device *pdev, u16 cmd,
void *ibuf, unsigned *ibuf_len)
{
return dln2_transfer(pdev, cmd, NULL, 0, ibuf, ibuf_len);
}
/**
* dln2_transfer_tx - variant of @dln2_transfer() where RX buffer is not needed
*
* @pdev - the sub-device which is issuing this transfer
* @cmd - the command to be sent to the device
* @obuf - the buffer to be sent to the device; it can be NULL if the
* user doesn't need to transmit data with this command
* @obuf_len - the size of the buffer to be sent to the device
*
* @return 0 for success, negative value for errors
*/
static inline int dln2_transfer_tx(struct platform_device *pdev, u16 cmd,
const void *obuf, unsigned obuf_len)
{
return dln2_transfer(pdev, cmd, obuf, obuf_len, NULL, NULL);
}
#endif
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment