summaryrefslogtreecommitdiff
path: root/include/linux
diff options
context:
space:
mode:
authorPhilippe Langlais <philippe.langlais@stericsson.com>2011-10-20 10:34:26 +0200
committerPhilippe Langlais <philippe.langlais@stericsson.com>2012-05-22 11:04:41 +0200
commit08142ec6f4f19a5e882c5650676c6d1c441abd92 (patch)
tree77be1461b43766fa318019d1f92912977e3550f9 /include/linux
parent9d5ac7304583952239cf71a3b3a58f7d3cc742b3 (diff)
misc: Add i2s driver
Signed-off-by: Robert Marklund <robert.marklund@stericsson.com> Conflicts: drivers/misc/Makefile Conflicts: drivers/misc/Kconfig drivers/misc/Makefile
Diffstat (limited to 'include/linux')
-rw-r--r--include/linux/i2s/i2s.h225
-rw-r--r--include/linux/i2s/i2s_test_prot.h44
2 files changed, 269 insertions, 0 deletions
diff --git a/include/linux/i2s/i2s.h b/include/linux/i2s/i2s.h
new file mode 100644
index 00000000000..b67fdb2d80d
--- /dev/null
+++ b/include/linux/i2s/i2s.h
@@ -0,0 +1,225 @@
+/*----------------------------------------------------------------------------*/
+/* copyright STMicroelectronics, 2007. */
+/* */
+/* This program is free software; you can redistribute it and/or modify it */
+/* under the terms of the GNU General Public License as published by the Free */
+/* Software Foundation; either version 2.1 of the License, or (at your option)*/
+/* any later version. */
+/* */
+/* This program is distributed in the hope that it will be useful, but */
+/* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY */
+/* or FITNES */
+/* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more */
+/* details. */
+/* */
+/* You should have received a copy of the GNU General Public License */
+/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
+/*----------------------------------------------------------------------------*/
+
+#ifndef __LINUX_I2S_H
+#define __LINUX_I2S_H
+
+/*
+ * INTERFACES between I2S controller-side drivers and I2S infrastructure.
+ */
+extern struct bus_type i2s_bus_type;
+#define I2S_NAME_SIZE 48
+/**
+ * struct i2s_device - Controller side proxy for an I2S slave device
+ * @dev: Driver model representation of the device.
+ * @controller: I2S controller used with the device.
+ * @chip_select: Chipselect, distinguishing chips handled by @controller.
+ * @modalias: Name of the driver to use with this device, or an alias
+ * for that name. This appears in the sysfs "modalias" attribute
+ * for driver coldplugging, and in uevents used for hotplugging
+ *
+ * A @i2s_device is used to interchange data between an I2S slave
+ *
+ * In @dev, the platform_data is used to hold information about this
+ * device that's meaningful to the device's protocol driver, but not
+ * to its controller.
+ */
+struct i2s_device {
+ struct device dev;
+ struct i2s_controller *controller;
+ u8 chip_select;
+ char modalias[32];
+};
+struct i2s_board_info {
+ /* the device name and module name are coupled, like platform_bus;
+ * "modalias" is normally the driver name.
+ *
+ * platform_data goes to i2s_device.dev.platform_data,
+ */
+ char modalias[32];
+ const void *platform_data;
+ u16 id;
+ u16 chip_select;
+};
+
+#ifdef CONFIG_STM_I2S
+extern int
+i2s_register_board_info(struct i2s_board_info const *info, unsigned n);
+#else
+/* board init code may ignore whether I2S is configured or not */
+static inline int
+i2s_register_board_info(struct i2s_board_info const *info, unsigned n)
+{
+ return 0;
+}
+#endif
+
+static inline struct i2s_device *to_i2s_device(struct device *dev)
+{
+ return dev ? container_of(dev, struct i2s_device, dev) : NULL;
+}
+
+static inline struct i2s_device *i2s_dev_get(struct i2s_device *i2s)
+{
+ return (i2s && get_device(&i2s->dev)) ? i2s : NULL;
+}
+
+static inline void i2s_dev_put(struct i2s_device *i2s)
+{
+ if (i2s)
+ put_device(&i2s->dev);
+}
+
+static inline void i2s_set_drvdata(struct i2s_device *i2s, void *data)
+{
+ dev_set_drvdata(&i2s->dev, data);
+}
+
+static inline void *i2s_get_drvdata(struct i2s_device *i2s)
+{
+ return dev_get_drvdata(&i2s->dev);
+}
+
+struct i2s_device_id {
+ char name[I2S_NAME_SIZE];
+ /*currently not used may be used in future */
+ u32 device_id;
+ u32 vendor_id;
+};
+
+/**
+ * struct i2s_driver - Host side "protocol" driver
+ */
+struct i2s_driver {
+ int (*probe) (struct i2s_device *i2s);
+ int (*remove) (struct i2s_device *i2s);
+ void (*shutdown) (struct i2s_device *i2s);
+ int (*suspend) (struct i2s_device *i2s, pm_message_t mesg);
+ int (*resume) (struct i2s_device *i2s);
+ struct device_driver driver;
+ const struct i2s_device_id *id_table;
+
+};
+
+static inline struct i2s_driver *to_i2s_driver(struct device_driver *drv)
+{
+ return drv ? container_of(drv, struct i2s_driver, driver) : NULL;
+}
+
+extern int i2s_register_driver(struct i2s_driver *sdrv);
+
+/**
+ * i2s_unregister_driver - reverse effect of i2s_register_driver
+ * @sdrv: the driver to unregister
+ * Context: can sleep
+ */
+static inline void i2s_unregister_driver(struct i2s_driver *sdrv)
+{
+ if (sdrv)
+ driver_unregister(&sdrv->driver);
+}
+
+/**I2S controller parameters*/
+
+enum i2s_direction_t {
+ I2S_DIRECTION_TX = 0,
+ I2S_DIRECTION_RX = 1,
+ I2S_DIRECTION_BOTH = 2
+};
+
+enum i2s_transfer_mode_t {
+ I2S_TRANSFER_MODE_SINGLE_DMA = 0,
+ I2S_TRANSFER_MODE_CYCLIC_DMA = 1,
+ I2S_TRANSFER_MODE_INF_LOOPBACK = 2,
+ I2S_TRANSFER_MODE_NON_DMA = 4,
+};
+
+struct i2s_message {
+ enum i2s_transfer_mode_t i2s_transfer_mode;
+ enum i2s_direction_t i2s_direction;
+ void *txdata;
+ void *rxdata;
+ size_t txbytes;
+ size_t rxbytes;
+ int dma_flag;
+ int tx_offset;
+ int rx_offset;
+ bool cyclic_dma;
+ struct scatterlist *sg;
+ int sg_len;
+};
+
+typedef enum {
+ DISABLE_ALL = 0,
+ DISABLE_TRANSMIT = 1,
+ DISABLE_RECEIVE = 2,
+} i2s_flag;
+
+struct i2s_algorithm {
+ int (*cont_setup) (struct i2s_controller *i2s_cont, void *config);
+ int (*cont_transfer) (struct i2s_controller *i2s_cont,
+ struct i2s_message *message);
+ int (*cont_cleanup) (struct i2s_controller *i2s_cont, i2s_flag flag);
+ int (*cont_hw_status) (struct i2s_controller *i2s_cont);
+ dma_addr_t (*cont_get_pointer) (struct i2s_controller *i2s_cont,
+ enum i2s_direction_t i2s_direction);
+};
+
+struct i2s_controller {
+ struct module *owner;
+ unsigned int id;
+ unsigned int class;
+ const struct i2s_algorithm *algo; /* the algorithm to access the bus */
+ void *data;
+ struct mutex bus_lock;
+ struct device dev; /* the controller device */
+ char name[48];
+};
+#define to_i2s_controller(d) container_of(d, struct i2s_controller, dev)
+
+static inline void *i2s_get_contdata(struct i2s_controller *dev)
+{
+ return dev_get_drvdata(&dev->dev);
+}
+
+static inline void i2s_set_contdata(struct i2s_controller *dev, void *data)
+{
+ dev_set_drvdata(&dev->dev, data);
+}
+
+extern int i2s_add_controller(struct i2s_controller *controller);
+extern int i2s_del_controller(struct i2s_controller *controller);
+extern int i2s_setup(struct i2s_controller *i2s_cont, void *config);
+extern int i2s_transfer(struct i2s_controller *i2s_cont,
+ struct i2s_message *message);
+extern int i2s_cleanup(struct i2s_controller *i2s_cont, i2s_flag flag);
+extern int i2s_hw_status(struct i2s_controller *i2s_cont);
+extern dma_addr_t i2s_get_pointer(struct i2s_controller *i2s_cont,
+ enum i2s_direction_t i2s_direction);
+
+extern struct i2s_device *i2s_alloc_device(struct device *dev);
+
+extern int i2s_add_device(struct i2s_device *i2s);
+
+static inline void i2s_unregister_device(struct i2s_device *i2s)
+{
+ if (i2s)
+ device_unregister(&i2s->dev);
+}
+
+#endif /* __LINUX_I2S_H */
diff --git a/include/linux/i2s/i2s_test_prot.h b/include/linux/i2s/i2s_test_prot.h
new file mode 100644
index 00000000000..003d0e6e3ab
--- /dev/null
+++ b/include/linux/i2s/i2s_test_prot.h
@@ -0,0 +1,44 @@
+/*
+ * Copyright (C) ST-Ericsson SA 2010
+ *
+ * License terms:
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as published
+ * by the Free Software Foundation.
+ */
+
+#ifndef __I2S_TEST_PROT_DRIVER_IF_H__
+#define __I2S_TEST_PROT_DRIVER_IF_H__
+#include <mach/msp.h>
+struct test_prot_config {
+ u32 tx_config_desc;
+ u32 rx_config_desc;
+ u32 frame_freq;
+ u32 frame_size;
+ u32 data_size;
+ u32 direction;
+ u32 protocol;
+ u32 work_mode;
+ struct msp_protocol_desc protocol_desc;
+ void (*handler) (void *data);
+ void *tx_callback_data;
+ void *rx_callback_data;
+ int multichannel_configured;
+ struct msp_multichannel_config multichannel_config;
+};
+
+int i2s_testprot_drv_open(int i2s_device_num);
+int i2s_testprot_drv_configure(int i2s_device_num,
+ struct test_prot_config *config);
+int i2s_config_default_protocol(int i2s_device_num,
+ struct test_prot_config *config);
+int __i2s_testprot_drv_configure(int i2s_device_num,
+ struct test_prot_config *config,
+ bool use_default);
+int i2s_testprot_drv_transfer(int i2s_device_num, void *txdata, size_t txbytes,
+ void *rxdata, size_t rxbytes,
+ enum i2s_transfer_mode_t transfer_mode);
+int i2s_testprot_drv_close(int i2s_device_num);
+
+#endif