2013-11-10 17:24:09 +01:00
|
|
|
/****************************************************************************
|
2018-08-27 15:26:22 +02:00
|
|
|
* drivers/i2s/i2schar.c
|
2013-11-10 17:24:09 +01:00
|
|
|
*
|
2021-03-04 07:10:42 +01:00
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed with
|
|
|
|
* this work for additional information regarding copyright ownership. The
|
|
|
|
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
|
|
|
* "License"); you may not use this file except in compliance with the
|
|
|
|
* License. You may obtain a copy of the License at
|
2013-11-10 17:24:09 +01:00
|
|
|
*
|
2021-03-04 07:10:42 +01:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2013-11-10 17:24:09 +01:00
|
|
|
*
|
2021-03-04 07:10:42 +01:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
* License for the specific language governing permissions and limitations
|
|
|
|
* under the License.
|
2013-11-10 17:24:09 +01:00
|
|
|
*
|
2021-03-04 07:10:42 +01:00
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
2013-11-10 17:24:09 +01:00
|
|
|
*
|
2021-03-04 07:10:42 +01:00
|
|
|
* This is a simple character driver for testing I2C. It is not an audio
|
|
|
|
* driver but does conform to some of the buffer management heuristics of an
|
|
|
|
* audio driver. It is not suitable for use in any real driver application
|
|
|
|
* in its current form.
|
2013-11-10 17:24:09 +01:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <string.h>
|
2021-05-18 08:59:14 +02:00
|
|
|
#include <assert.h>
|
2013-11-10 17:24:09 +01:00
|
|
|
#include <debug.h>
|
|
|
|
#include <errno.h>
|
|
|
|
|
2022-09-06 08:18:45 +02:00
|
|
|
#include <nuttx/mutex.h>
|
2013-11-10 17:24:09 +01:00
|
|
|
#include <nuttx/kmalloc.h>
|
|
|
|
#include <nuttx/fs/fs.h>
|
|
|
|
#include <nuttx/audio/audio.h>
|
|
|
|
#include <nuttx/audio/i2s.h>
|
|
|
|
|
|
|
|
/****************************************************************************
|
2015-04-08 15:15:32 +02:00
|
|
|
* Pre-processor Definitions
|
2013-11-10 17:24:09 +01:00
|
|
|
****************************************************************************/
|
2021-02-25 21:03:17 +01:00
|
|
|
|
2013-11-12 17:18:49 +01:00
|
|
|
/* Configuration ************************************************************/
|
2013-11-10 17:24:09 +01:00
|
|
|
|
2013-11-12 17:18:49 +01:00
|
|
|
#ifndef CONFIG_AUDIO_I2SCHAR_RXTIMEOUT
|
|
|
|
# define CONFIG_AUDIO_I2SCHAR_RXTIMEOUT 0
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef CONFIG_AUDIO_I2SCHAR_TXTIMEOUT
|
|
|
|
# define CONFIG_AUDIO_I2SCHAR_TXTIMEOUT 0
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Device naming ************************************************************/
|
2013-11-10 17:24:09 +01:00
|
|
|
#define DEVNAME_FMT "/dev/i2schar%d"
|
|
|
|
#define DEVNAME_FMTLEN (12 + 3 + 1)
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Types
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
struct i2schar_dev_s
|
|
|
|
{
|
|
|
|
FAR struct i2s_dev_s *i2s; /* The lower half i2s driver */
|
2022-09-06 08:18:45 +02:00
|
|
|
mutex_t lock; /* Assures mutually exclusive access */
|
2013-11-10 17:24:09 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Function Prototypes
|
|
|
|
****************************************************************************/
|
2021-02-25 21:03:17 +01:00
|
|
|
|
2013-11-10 17:24:09 +01:00
|
|
|
/* I2S callback function */
|
|
|
|
|
2021-02-25 21:03:17 +01:00
|
|
|
static void i2schar_rxcallback(FAR struct i2s_dev_s *dev,
|
|
|
|
FAR struct ap_buffer_s *apb,
|
|
|
|
FAR void *arg,
|
|
|
|
int result);
|
|
|
|
static void i2schar_txcallback(FAR struct i2s_dev_s *dev,
|
|
|
|
FAR struct ap_buffer_s *apb,
|
|
|
|
FAR void *arg,
|
|
|
|
int result);
|
2013-11-10 17:24:09 +01:00
|
|
|
|
|
|
|
/* Character driver methods */
|
|
|
|
|
|
|
|
static ssize_t i2schar_read(FAR struct file *filep, FAR char *buffer,
|
2021-02-25 21:03:17 +01:00
|
|
|
size_t buflen);
|
2013-11-10 17:24:09 +01:00
|
|
|
static ssize_t i2schar_write(FAR struct file *filep, FAR const char *buffer,
|
2021-02-25 21:03:17 +01:00
|
|
|
size_t buflen);
|
|
|
|
static int i2schar_ioctl(FAR struct file *filep, int cmd, unsigned long arg);
|
2018-06-05 18:34:22 +02:00
|
|
|
|
2013-11-10 17:24:09 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Private Data
|
|
|
|
****************************************************************************/
|
|
|
|
|
2023-04-22 16:43:07 +02:00
|
|
|
static const struct file_operations g_i2schar_fops =
|
2013-11-10 17:24:09 +01:00
|
|
|
{
|
|
|
|
NULL, /* open */
|
|
|
|
NULL, /* close */
|
|
|
|
i2schar_read, /* read */
|
|
|
|
i2schar_write, /* write */
|
|
|
|
NULL, /* seek */
|
2018-06-05 18:34:22 +02:00
|
|
|
i2schar_ioctl, /* ioctl */
|
2013-11-10 17:24:09 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: i2schar_rxcallback
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* I2S RX transfer complete callback.
|
|
|
|
*
|
|
|
|
* NOTE: In this test driver, the RX is simply dumped in the bit bucket.
|
|
|
|
* You would not do this in a real application. You would return the
|
|
|
|
* received data to the caller via some IPC.
|
|
|
|
*
|
|
|
|
* Also, the test buffer is simply freed. This will work if this driver
|
|
|
|
* has the sole reference to buffer; in that case the buffer will be freed.
|
2021-02-25 14:34:37 +01:00
|
|
|
* Otherwise -- memory leak! A more efficient design would recycle the
|
2013-11-10 17:24:09 +01:00
|
|
|
* audio buffers.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static void i2schar_rxcallback(FAR struct i2s_dev_s *dev,
|
2013-11-10 21:51:33 +01:00
|
|
|
FAR struct ap_buffer_s *apb,
|
2013-11-10 17:24:09 +01:00
|
|
|
FAR void *arg, int result)
|
|
|
|
{
|
|
|
|
FAR struct i2schar_dev_s *priv = (FAR struct i2schar_dev_s *)arg;
|
|
|
|
|
2018-06-17 23:26:18 +02:00
|
|
|
DEBUGASSERT(priv != NULL && apb != NULL);
|
|
|
|
UNUSED(priv);
|
|
|
|
|
2016-06-11 19:59:51 +02:00
|
|
|
i2sinfo("apb=%p nbytes=%d result=%d\n", apb, apb->nbytes, result);
|
2013-11-10 17:24:09 +01:00
|
|
|
|
2013-11-10 21:51:33 +01:00
|
|
|
/* REVISIT: If you want this to actually do something other than
|
|
|
|
* test I2S data transfer, then this is the point where you would
|
|
|
|
* want to pass the received I2S to some application.
|
2013-11-10 17:24:09 +01:00
|
|
|
*/
|
|
|
|
|
2013-11-10 21:51:33 +01:00
|
|
|
/* Release our reference to the audio buffer. Hopefully it will be freed
|
|
|
|
* now.
|
|
|
|
*/
|
2013-11-10 17:24:09 +01:00
|
|
|
|
2016-06-11 19:59:51 +02:00
|
|
|
i2sinfo("Freeing apb=%p crefs=%d\n", apb, apb->crefs);
|
2013-11-10 21:51:33 +01:00
|
|
|
apb_free(apb);
|
2013-11-10 17:24:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: i2schar_txcallback
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* I2S TX transfer complete callback
|
|
|
|
*
|
|
|
|
* NOTE: The test buffer is simply freed. This will work if this driver
|
|
|
|
* has the sole reference to buffer; in that case the buffer will be freed.
|
2021-02-25 14:34:37 +01:00
|
|
|
* Otherwise -- memory leak! A more efficient design would recycle the
|
2013-11-10 17:24:09 +01:00
|
|
|
* audio buffers.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static void i2schar_txcallback(FAR struct i2s_dev_s *dev,
|
2013-11-10 21:51:33 +01:00
|
|
|
FAR struct ap_buffer_s *apb,
|
2013-11-10 17:24:09 +01:00
|
|
|
FAR void *arg, int result)
|
|
|
|
{
|
|
|
|
FAR struct i2schar_dev_s *priv = (FAR struct i2schar_dev_s *)arg;
|
|
|
|
|
2018-06-17 23:26:18 +02:00
|
|
|
DEBUGASSERT(priv != NULL && apb != NULL);
|
|
|
|
UNUSED(priv);
|
|
|
|
|
2016-06-11 19:59:51 +02:00
|
|
|
i2sinfo("apb=%p nbytes=%d result=%d\n", apb, apb->nbytes, result);
|
2013-11-10 17:24:09 +01:00
|
|
|
|
2013-11-10 21:51:33 +01:00
|
|
|
/* REVISIT: If you want this to actually do something other than
|
|
|
|
* test I2S data transfer, then this is the point where you would
|
|
|
|
* want to let some application know that the transfer has complete.
|
2013-11-10 17:24:09 +01:00
|
|
|
*/
|
|
|
|
|
2013-11-10 21:51:33 +01:00
|
|
|
/* Release our reference to the audio buffer. Hopefully it will be freed
|
|
|
|
* now.
|
|
|
|
*/
|
2013-11-10 17:24:09 +01:00
|
|
|
|
2016-06-11 19:59:51 +02:00
|
|
|
i2sinfo("Freeing apb=%p crefs=%d\n", apb, apb->crefs);
|
2013-11-10 21:51:33 +01:00
|
|
|
apb_free(apb);
|
2013-11-10 17:24:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: i2schar_read
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Standard character driver read method
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static ssize_t i2schar_read(FAR struct file *filep, FAR char *buffer,
|
|
|
|
size_t buflen)
|
|
|
|
{
|
2018-06-11 15:00:27 +02:00
|
|
|
FAR struct inode *inode;
|
2013-11-10 17:24:09 +01:00
|
|
|
FAR struct i2schar_dev_s *priv;
|
|
|
|
FAR struct ap_buffer_s *apb;
|
|
|
|
size_t nbytes;
|
|
|
|
int ret;
|
|
|
|
|
2016-06-11 19:59:51 +02:00
|
|
|
i2sinfo("buffer=%p buflen=%d\n", buffer, (int)buflen);
|
2013-11-10 17:24:09 +01:00
|
|
|
|
|
|
|
/* Get our private data structure */
|
|
|
|
|
2023-08-28 11:17:05 +02:00
|
|
|
DEBUGASSERT(buffer != NULL);
|
2013-11-10 17:24:09 +01:00
|
|
|
|
|
|
|
inode = filep->f_inode;
|
|
|
|
|
2023-08-29 06:16:49 +02:00
|
|
|
priv = inode->i_private;
|
2018-06-17 23:26:18 +02:00
|
|
|
DEBUGASSERT(priv != NULL);
|
2013-11-10 17:24:09 +01:00
|
|
|
|
|
|
|
/* Verify that the buffer refers to one, correctly sized audio buffer */
|
|
|
|
|
|
|
|
DEBUGASSERT(buflen >= sizeof(struct ap_buffer_s));
|
|
|
|
|
|
|
|
apb = (FAR struct ap_buffer_s *)buffer;
|
|
|
|
nbytes = apb->nmaxbytes;
|
|
|
|
DEBUGASSERT(buflen >= (sizeof(struct ap_buffer_s) + nbytes));
|
|
|
|
|
2013-11-10 21:51:33 +01:00
|
|
|
/* Add a reference to the audio buffer */
|
2013-11-10 17:24:09 +01:00
|
|
|
|
|
|
|
apb_reference(apb);
|
|
|
|
|
|
|
|
/* Get exclusive access to i2c character driver */
|
|
|
|
|
2022-09-06 08:18:45 +02:00
|
|
|
ret = nxmutex_lock(&priv->lock);
|
2013-11-10 17:24:09 +01:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
2017-10-04 23:22:27 +02:00
|
|
|
i2serr("ERROR: nxsem_wait returned: %d\n", ret);
|
2013-11-10 17:24:09 +01:00
|
|
|
goto errout_with_reference;
|
|
|
|
}
|
|
|
|
|
2013-11-10 21:51:33 +01:00
|
|
|
/* Give the buffer to the I2S driver */
|
2013-11-10 17:24:09 +01:00
|
|
|
|
2013-11-12 17:18:49 +01:00
|
|
|
ret = I2S_RECEIVE(priv->i2s, apb, i2schar_rxcallback, priv,
|
|
|
|
CONFIG_AUDIO_I2SCHAR_RXTIMEOUT);
|
2013-11-10 17:24:09 +01:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
2016-06-11 23:50:49 +02:00
|
|
|
i2serr("ERROR: I2S_RECEIVE returned: %d\n", ret);
|
2013-11-10 17:24:09 +01:00
|
|
|
goto errout_with_reference;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Lie to the caller and tell them that all of the bytes have been
|
|
|
|
* received
|
|
|
|
*/
|
|
|
|
|
2022-09-06 08:18:45 +02:00
|
|
|
nxmutex_unlock(&priv->lock);
|
2013-11-11 22:18:57 +01:00
|
|
|
return sizeof(struct ap_buffer_s) + nbytes;
|
2013-11-10 17:24:09 +01:00
|
|
|
|
|
|
|
errout_with_reference:
|
|
|
|
apb_free(apb);
|
2022-09-06 08:18:45 +02:00
|
|
|
nxmutex_unlock(&priv->lock);
|
2013-11-10 17:24:09 +01:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2014-02-12 20:00:24 +01:00
|
|
|
* Name: i2schar_write
|
2013-11-10 17:24:09 +01:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Standard character driver write method
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static ssize_t i2schar_write(FAR struct file *filep, FAR const char *buffer,
|
|
|
|
size_t buflen)
|
|
|
|
{
|
2018-06-11 15:00:27 +02:00
|
|
|
FAR struct inode *inode;
|
2013-11-10 17:24:09 +01:00
|
|
|
FAR struct i2schar_dev_s *priv;
|
|
|
|
FAR struct ap_buffer_s *apb;
|
|
|
|
size_t nbytes;
|
|
|
|
int ret;
|
|
|
|
|
2016-06-11 19:59:51 +02:00
|
|
|
i2sinfo("buffer=%p buflen=%d\n", buffer, (int)buflen);
|
2013-11-10 17:24:09 +01:00
|
|
|
|
|
|
|
/* Get our private data structure */
|
|
|
|
|
2023-08-28 11:17:05 +02:00
|
|
|
DEBUGASSERT(buffer);
|
2013-11-10 17:24:09 +01:00
|
|
|
|
|
|
|
inode = filep->f_inode;
|
|
|
|
|
2023-08-29 06:16:49 +02:00
|
|
|
priv = inode->i_private;
|
2013-11-10 17:24:09 +01:00
|
|
|
DEBUGASSERT(priv);
|
|
|
|
|
|
|
|
/* Verify that the buffer refers to one, correctly sized audio buffer */
|
|
|
|
|
|
|
|
DEBUGASSERT(buflen >= sizeof(struct ap_buffer_s));
|
|
|
|
|
|
|
|
apb = (FAR struct ap_buffer_s *)buffer;
|
|
|
|
nbytes = apb->nmaxbytes;
|
|
|
|
DEBUGASSERT(buflen >= (sizeof(struct ap_buffer_s) + nbytes));
|
|
|
|
|
2013-11-10 21:51:33 +01:00
|
|
|
/* Add a reference to the audio buffer */
|
2013-11-10 17:24:09 +01:00
|
|
|
|
|
|
|
apb_reference(apb);
|
|
|
|
|
|
|
|
/* Get exclusive access to i2c character driver */
|
|
|
|
|
2022-09-06 08:18:45 +02:00
|
|
|
ret = nxmutex_lock(&priv->lock);
|
2013-11-10 17:24:09 +01:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
2017-10-04 23:22:27 +02:00
|
|
|
i2serr("ERROR: nxsem_wait returned: %d\n", ret);
|
2013-11-10 17:24:09 +01:00
|
|
|
goto errout_with_reference;
|
|
|
|
}
|
|
|
|
|
2013-11-10 21:51:33 +01:00
|
|
|
/* Give the audio buffer to the I2S driver */
|
2013-11-10 17:24:09 +01:00
|
|
|
|
2013-11-12 17:18:49 +01:00
|
|
|
ret = I2S_SEND(priv->i2s, apb, i2schar_txcallback, priv,
|
|
|
|
CONFIG_AUDIO_I2SCHAR_TXTIMEOUT);
|
2013-11-10 17:24:09 +01:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
2016-06-11 23:50:49 +02:00
|
|
|
i2serr("ERROR: I2S_SEND returned: %d\n", ret);
|
2013-11-10 17:24:09 +01:00
|
|
|
goto errout_with_reference;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Lie to the caller and tell them that all of the bytes have been
|
|
|
|
* sent.
|
|
|
|
*/
|
|
|
|
|
2022-09-06 08:18:45 +02:00
|
|
|
nxmutex_unlock(&priv->lock);
|
2013-11-11 22:18:57 +01:00
|
|
|
return sizeof(struct ap_buffer_s) + nbytes;
|
2013-11-10 17:24:09 +01:00
|
|
|
|
|
|
|
errout_with_reference:
|
|
|
|
apb_free(apb);
|
2022-09-06 08:18:45 +02:00
|
|
|
nxmutex_unlock(&priv->lock);
|
2013-11-10 17:24:09 +01:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2021-02-25 21:03:17 +01:00
|
|
|
/****************************************************************************
|
2018-06-05 18:34:22 +02:00
|
|
|
* Name: i2char_ioctl
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Perform I2S device ioctl if exists
|
|
|
|
*
|
2021-02-25 21:03:17 +01:00
|
|
|
****************************************************************************/
|
2018-06-05 18:34:22 +02:00
|
|
|
|
|
|
|
static int i2schar_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
|
|
|
|
{
|
2018-06-11 15:00:27 +02:00
|
|
|
FAR struct inode *inode;
|
2018-06-05 18:34:22 +02:00
|
|
|
FAR struct i2schar_dev_s *priv;
|
|
|
|
int ret = -ENOTTY;
|
|
|
|
|
|
|
|
/* Get our private data structure */
|
|
|
|
|
|
|
|
inode = filep->f_inode;
|
|
|
|
|
2023-08-29 06:16:49 +02:00
|
|
|
priv = inode->i_private;
|
2018-06-17 23:26:18 +02:00
|
|
|
DEBUGASSERT(priv != NULL && priv->i2s && priv->i2s->ops);
|
2018-06-05 18:34:22 +02:00
|
|
|
|
|
|
|
if (priv->i2s->ops->i2s_ioctl)
|
|
|
|
{
|
|
|
|
ret = priv->i2s->ops->i2s_ioctl(priv->i2s, cmd, arg);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2013-11-10 17:24:09 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: i2schar_register
|
|
|
|
*
|
|
|
|
* Description:
|
2013-11-11 22:18:57 +01:00
|
|
|
* Create and register the I2S character driver.
|
|
|
|
*
|
|
|
|
* The I2S character driver is a simple character driver that supports I2S
|
|
|
|
* transfers via a read() and write(). The intent of this driver is to
|
|
|
|
* support I2S testing. It is not an audio driver but does conform to some
|
|
|
|
* of the buffer management heuristics of an audio driver. It is not
|
|
|
|
* suitable for use in any real driver application in its current form.
|
2013-11-10 17:24:09 +01:00
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* i2s - An instance of the lower half I2S driver
|
|
|
|
* minor - The device minor number. The I2S character device will be
|
|
|
|
* registers as /dev/i2scharN where N is the minor number
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* OK if the driver was successfully register; A negated errno value is
|
|
|
|
* returned on any failure.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
int i2schar_register(FAR struct i2s_dev_s *i2s, int minor)
|
|
|
|
{
|
|
|
|
FAR struct i2schar_dev_s *priv;
|
|
|
|
char devname[DEVNAME_FMTLEN];
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
/* Sanity check */
|
|
|
|
|
|
|
|
DEBUGASSERT(i2s != NULL && (unsigned)minor < 1000);
|
|
|
|
|
|
|
|
/* Allocate a I2S character device structure */
|
|
|
|
|
2021-02-25 21:03:17 +01:00
|
|
|
size_t dev_size = sizeof(struct i2schar_dev_s);
|
2023-08-28 09:39:47 +02:00
|
|
|
priv = kmm_zalloc(dev_size);
|
2013-11-10 17:24:09 +01:00
|
|
|
if (priv)
|
|
|
|
{
|
|
|
|
/* Initialize the I2S character device structure */
|
|
|
|
|
|
|
|
priv->i2s = i2s;
|
2022-09-06 08:18:45 +02:00
|
|
|
nxmutex_init(&priv->lock);
|
2013-11-10 17:24:09 +01:00
|
|
|
|
|
|
|
/* Create the character device name */
|
|
|
|
|
2024-08-24 18:54:12 +02:00
|
|
|
snprintf(devname, sizeof(devname), DEVNAME_FMT, minor);
|
2023-04-22 16:43:07 +02:00
|
|
|
ret = register_driver(devname, &g_i2schar_fops, 0666, priv);
|
2013-11-10 17:24:09 +01:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
/* Free the device structure if we failed to create the character
|
|
|
|
* device.
|
|
|
|
*/
|
|
|
|
|
2022-10-16 18:50:59 +02:00
|
|
|
nxmutex_destroy(&priv->lock);
|
2014-09-01 01:04:02 +02:00
|
|
|
kmm_free(priv);
|
2019-11-04 02:31:49 +01:00
|
|
|
return ret;
|
2013-11-10 17:24:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Return the result of the registration */
|
|
|
|
|
|
|
|
return OK;
|
|
|
|
}
|
2014-04-13 22:32:20 +02:00
|
|
|
|
2013-11-10 17:24:09 +01:00
|
|
|
return -ENOMEM;
|
|
|
|
}
|