UCC TDM driver for QE based MPC83xx platforms.
Subsystems (3)
PATCH 1/1 UCC TDM driver for QE based MPC83xx platforms.
From: Poonam Agarwal-b10812 <[email protected]>
The UCC TDM driver basically multiplexes and demultiplexes data from different channels. It can interface with for example SLIC kind of devices to receive TDM data demultiplex it and send to upper modules. At the transmit end it receives data for different channels multiplexes it and sends them on the TDM channel. It internally uses TSA( Time Slot Assigner) which does multiplexing and demultiplexing, UCC to perform SDMA between host buffers and the TSA, CMX to connect TSA to UCC.
It can be used by a kernel module which can call tdm_register_client to get access to a TDM device.
The driver is right now a misc driver with no subsystem as such. There can be a platform independent TDM layer which is planned to be done after this. TDM bus sort of thing.
The dts file keeps a track of the TDM devices present on the board. Depending on them the TDM driver initializes those many driver instances while coming up.
The driver on the upper level can plug to more than one tdm clients depending on the availablity of TDM devices. At every new request of a TDM client to bind with a TDM device, a free driver instance is allocated to the client.
The interface can be described as follows.
tdm_register_client(struct tdm_client *)
This API returns a pointer to the structure tdm_client which is of
type
struct tdm_client {
u32 client_id;
u32 (*tdm_read)(u32 client_id, short chn_id, short
*pcm_buffer, short len);
u32 (*tdm_write)(u32 client_id, short chn_id, short
*pcm_buffer, short len);
wait_queue_head_t *wakeup_event;
}It consists of:
- client_id: It is basically to identify the particular TDM
device/driver instance.
- tdm_read: It is a function pointer returned by the TDM driver to be
used to read TDM data from a particular TDM channel.
- tdm_write: It is a function pointer returned by the TDM driver to be
used to write TDM data to a particular TDM channel.
- wakeup_event: It is address of a wait_queue event on which the client
keeps on sleeping, and the TDM driver wakes it up periodically. The driver is configured to
wake up the client after every 10ms.
Once the TDM client gets registered to a TDM driver instance and a TDM device, it interfaces with the driver using tdm_read, tdm_write and wakeup_event.
This driver will run on MPC8323E-RDB platforms.
--- drivers/misc/Kconfig | 14 + drivers/misc/Makefile | 1 + drivers/misc/ucc_tdm.c | 1000 ++++++++++++++++++++++++++++++++++++++++++++++++ drivers/misc/ucc_tdm.h | 221 +++++++++++ 4 files changed, 1236 insertions(+), 0 deletions(-) create mode 100644 drivers/misc/ucc_tdm.c create mode 100644 drivers/misc/ucc_tdm.h
drivers/misc/Kconfig +14 -0
@@ -232,4 +232,18 @@ config ATMEL_SSC If unsure, say N. +config UCC_TDM + bool "Freescale UCC TDM Driver" + depends on QUICC_ENGINE && UCC_FAST + default n + ---help--- + The TDM driver is for UCC based TDM devices for example, TDM device on + MPC832x RDB. Select it to run PowerVoIP on MPC832x RDB board. + The TDM driver can interface with SLIC kind of devices to transmit + and receive TDM samples. The TDM driver receives Time Division + multiplexed samples(for different channels) from the SLIC device, + demutiplexes them and sends them to the upper layers. At the transmit + end the TDM drivers receives samples for different channels, it + multiplexes them and sends them to the SLIC device. + endif # MISC_DEVICES
drivers/misc/Makefile +1 -0
@@ -17,3 +17,4 @@ obj-$(CONFIG_SONY_LAPTOP) += sony-laptop.o obj-$(CONFIG_THINKPAD_ACPI) += thinkpad_acpi.o obj-$(CONFIG_FUJITSU_LAPTOP) += fujitsu-laptop.o obj-$(CONFIG_EEPROM_93CX6) += eeprom_93cx6.o +obj-$(CONFIG_UCC_TDM) += ucc_tdm.o
drivers/misc/ucc_tdm.c new file +1000 -0
1,000 lines not on this page · raw message
drivers/misc/ucc_tdm.h new file +221 -0
221 lines not on this page · raw message
Signature · 1 line
1.5.2.4
drivers/misc/ucc_tdm.c line 782
Quoted 9 lines · On Thu, 24 Jan 2008 10:16:42 +0530 (IST) Poonam_Aggrwal-b10812…
drivers/misc/ucc_tdm.c new file +8
-0+static int ucc_tdm_probe (struct of_device *ofdev, +const struct of_device_id *match) +{ +struct device_node *np = ofdev->node; +struct resource res; +const unsigned int *prop; +u32 ucc_num, device_num, err, ret =0 ; +struct device_node *np_tmp =NULL ;
You don't need to initialise this.
drivers/misc/ucc_tdm.c line 787
Quoted 5 lines
drivers/misc/ucc_tdm.c new file +5
-0+dma_addr_t physaddr; +void *tdm_buff; +struct ucc_tdm_info *ut_info; + + prop =of_get_property (np,"device-id" ,NULL );
You should check for (prop == NULL).
drivers/misc/ucc_tdm.c line 793
Quoted 6 lines
drivers/misc/ucc_tdm.c new file +6
-0+ ucc_num = *prop -1 ; +if ((ucc_num <0 ) || (ucc_num >7 )) +return -ENODEV ; + + ut_info = &utdm_info[ucc_num]; +if (ut_info ==NULL ) {
This cannot be NULL as you have just taken the address of an array element.
drivers/misc/ucc_tdm.c line 820
Quoted 3 lines
drivers/misc/ucc_tdm.c new file +3
-0+ tdm_ctrl[device_num]->ut_info = ut_info; + + tdm_ctrl[device_num]->ut_info->uf_info.ucc_num = ucc_num;
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
This is the same as "ut_info".
drivers/misc/ucc_tdm.c line 844
Quoted 2 lines
drivers/misc/ucc_tdm.c new file +2
-0+ tdm_ctrl[device_num]->ut_info->uf_info.tdm_tx_clk = + (char *)of_get_property (np,"fsl,tdm-tx-clk" ,NULL );
^
We don't normall put spaces here.
drivers/misc/ucc_tdm.c line 851
Quoted 2 lines
drivers/misc/ucc_tdm.c new file +2
-0+ tdm_ctrl[device_num]->ut_info->uf_info.tdm_rx_clk = + (char *)of_get_property (np,"fsl,tdm-rx-clk" ,NULL );
^
Ditto. And later as well.
drivers/misc/ucc_tdm.c line 875
Quoted 5 lines
drivers/misc/ucc_tdm.c new file +5
-0+ tdm_ctrl[device_num]->ut_info->uf_info.irq = +irq_of_parse_and_map (np,0 ); + err =of_address_to_resource (np,0 , &res); +if (err) { + ret =EINVAL ;
This should be -EINVAL or err.
Review
Quoted 1 line
(quoted diff) +1
-0+ goto get_property_error;
You need to do something about unmapping the irq in the error path.
drivers/misc/ucc_tdm.c line 885
Quoted 7 lines
drivers/misc/ucc_tdm.c new file +7
-0+ tdm_ctrl[device_num]->uf_regs =of_iomap (np,0 ); + + np_tmp =of_find_compatible_node (np_tmp,"slic" ,"legerity-slic" ); +if (np_tmp !=NULL ) + tdm_ctrl[device_num]->leg_slic =1 ; +else + tdm_ctrl[device_num]->leg_slic =0 ;
of_node_ut(np_tmp);
drivers/misc/ucc_tdm.c line 896
Quoted 8 lines
drivers/misc/ucc_tdm.c new file +8
-0+ tdm_buff =dma_alloc_coherent (NULL ,2 *NR_BUFS *SAMPLE_DEPTH * + tdm_ctrl[device_num]->cfg_ctrl.active_num_ts, + &physaddr,GFP_KERNEL ); +if (!tdm_buff) { +printk (KERN_ERR "ucc-tdm: could not allocate buffer" +"descriptors\n" ); + ret = -ENOMEM ; + goto get_property_error;
You need to unmap the uf_regs in the error path.
drivers/misc/ucc_tdm.c line 931
Quoted 2 lines
drivers/misc/ucc_tdm.c new file +2
-0+get_property_error: +kfree (tdm_ctrl[device_num]);
Do you need to set "tdm_ctrl[device_num]" to NULL and decrement num_tdm_devices?
drivers/misc/ucc_tdm.c line 941
Quoted 10 lines
drivers/misc/ucc_tdm.c new file +10
-0+return ret; +} + +static int ucc_tdm_remove (struct of_device *ofdev) +{ +struct tdm_ctrl *tdm_c; +struct ucc_tdm_info *ut_info; +u32 ucc_num; + + tdm_c =dev_get_drvdata (&(ofdev->dev));
dev_set_drvdata(&of_dev->dev, NULL);
drivers/misc/ucc_tdm.c line 953
Quoted 12 lines
drivers/misc/ucc_tdm.c new file +12
-0+ ucc_num = tdm_c->ut_info->uf_info.ucc_num; + ut_info = &utdm_info[ucc_num]; +tdm_stop (tdm_c); +tdm_deinit (tdm_c); + +ucc_fast_free (tdm_c->uf_private); + +dma_free_coherent (NULL ,2 *NR_BUFS *SAMPLE_DEPTH * + tdm_c->cfg_ctrl.active_num_ts, + tdm_c->tdm_input_data, + tdm_c->dma_input_addr); +
You need to unmap the uf_reg and the irq.
Quoted 1 line
+static struct
of_device_iducc_tdm_match[] = {
const, please.
drivers/misc/ucc_tdm.c line 967
Quoted 4 lines
drivers/misc/ucc_tdm.c new file +4
-0+ { + .type = "tdm", + .compatible = "fsl,ucc-tdm", + }, {},
We euld normall format this like:
{ .type = "tdm", .compatible = "fsl,ucc-tdm", },
{},Quoted 1 line
+static struct
of_platform_driverucc_tdm_driver= {
.driver = {drivers/misc/ucc_tdm.c line 973
Quoted 1 line
drivers/misc/ucc_tdm.c new file +1
-0+ .name = DRV_NAME,
},
Signature · 3 lines
Cheers, Stephen Rothwell [email protected] http://www.canb.auug.org.au/~sfr/
Quoted 4 lines · Stephen Rothwell
drivers/misc/ucc_tdm.c line 844
Quoted 2 lines
drivers/misc/ucc_tdm.c new file +2
-0+ tdm_ctrl[device_num]->ut_info->uf_info.tdm_tx_clk = + (char *)of_get_property (np,"fsl,tdm-tx-clk" ,NULL );^We don't normall put spaces here.
Since when?
Signature · 2 lines
Timur Tabi Linux kernel developer at Freescale