2 * dim2_hdm.c - MediaLB DIM2 Hardware Dependent Module
4 * Copyright (C) 2015, Microchip Technology Germany II GmbH & Co. KG
6 * This program is distributed in the hope that it will be useful,
7 * but WITHOUT ANY WARRANTY; without even the implied warranty of
8 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9 * GNU General Public License for more details.
11 * This file is licensed under GPLv2.
14 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
16 #include <linux/module.h>
17 #include <linux/printk.h>
18 #include <linux/kernel.h>
19 #include <linux/init.h>
20 #include <linux/platform_device.h>
21 #include <linux/interrupt.h>
22 #include <linux/slab.h>
24 #include <linux/dma-mapping.h>
25 #include <linux/sched.h>
26 #include <linux/kthread.h>
29 #include <networking.h>
32 #include "dim2_errors.h"
33 #include "dim2_sysfs.h"
35 #define DMA_CHANNELS (32 - 1) /* channel 0 is a system channel */
37 #define MAX_BUFFERS_PACKET 32
38 #define MAX_BUFFERS_STREAMING 32
39 #define MAX_BUF_SIZE_PACKET 2048
40 #define MAX_BUF_SIZE_STREAMING (8*1024)
42 /* command line parameter to select clock speed */
43 static char *clock_speed;
44 module_param(clock_speed, charp, 0);
45 MODULE_PARM_DESC(clock_speed, "MediaLB Clock Speed");
48 * #############################################################################
50 * The define below activates an utility function used by HAL-simu
51 * for calling DIM interrupt handler.
52 * It is used only for TEST PURPOSE and shall be commented before release.
54 * #############################################################################
56 /* #define ENABLE_HDM_TEST */
58 static DEFINE_SPINLOCK(dim_lock);
60 static void dim2_tasklet_fn(unsigned long data);
61 static DECLARE_TASKLET(dim2_tasklet, dim2_tasklet_fn, 0);
64 * struct hdm_channel - private structure to keep channel specific data
65 * @is_initialized: identifier to know whether the channel is initialized
66 * @ch: HAL specific channel data
67 * @pending_list: list to keep MBO's before starting transfer
68 * @started_list: list to keep MBO's after starting transfer
69 * @direction: channel direction (TX or RX)
70 * @data_type: channel data type
73 char name[sizeof "caNNN"];
75 struct dim_channel ch;
76 struct list_head pending_list; /* before DIM_EnqueueBuffer() */
77 struct list_head started_list; /* after DIM_EnqueueBuffer() */
78 enum most_channel_direction direction;
79 enum most_channel_data_type data_type;
83 * struct dim2_hdm - private structure to keep interface specific data
84 * @hch: an array of channel specific data
85 * @most_iface: most interface structure
86 * @capabilities: an array of channel capability data
87 * @io_base: I/O register base address
88 * @irq_ahb0: dim2 AHB0 irq number
89 * @clk_speed: user selectable (through command line parameter) clock speed
90 * @netinfo_task: thread to deliver network status
91 * @netinfo_waitq: waitq for the thread to sleep
92 * @deliver_netinfo: to identify whether network status received
93 * @mac_addrs: INIC mac address
94 * @link_state: network link state
95 * @atx_idx: index of async tx channel
98 struct hdm_channel hch[DMA_CHANNELS];
99 struct most_channel_capability capabilities[DMA_CHANNELS];
100 struct most_interface most_iface;
101 char name[16 + sizeof "dim2-"];
103 unsigned int irq_ahb0;
105 struct task_struct *netinfo_task;
106 wait_queue_head_t netinfo_waitq;
108 unsigned char mac_addrs[6];
109 unsigned char link_state;
111 struct medialb_bus bus;
114 #define iface_to_hdm(iface) container_of(iface, struct dim2_hdm, most_iface)
116 /* Macro to identify a network status message */
117 #define PACKET_IS_NET_INFO(p) \
118 (((p)[1] == 0x18) && ((p)[2] == 0x05) && ((p)[3] == 0x0C) && \
119 ((p)[13] == 0x3C) && ((p)[14] == 0x00) && ((p)[15] == 0x0A))
121 #if defined(ENABLE_HDM_TEST)
122 static struct dim2_hdm *test_dev;
125 bool dim2_sysfs_get_state_cb(void)
130 spin_lock_irqsave(&dim_lock, flags);
131 state = DIM_GetLockState();
132 spin_unlock_irqrestore(&dim_lock, flags);
138 * DIMCB_IoRead - callback from HAL to read an I/O register
139 * @ptr32: register address
141 u32 DIMCB_IoRead(u32 *ptr32)
143 return __raw_readl(ptr32);
147 * DIMCB_IoWrite - callback from HAL to write value to an I/O register
148 * @ptr32: register address
149 * @value: value to write
151 void DIMCB_IoWrite(u32 *ptr32, u32 value)
153 __raw_writel(value, ptr32);
157 * DIMCB_OnError - callback from HAL to report miscommunication between
159 * @error_id: Error ID
160 * @error_message: Error message. Some text in a free format
162 void DIMCB_OnError(u8 error_id, const char *error_message)
164 pr_err("DIMCB_OnError: error_id - %d, error_message - %s\n", error_id,
169 * DIMCB_OnFail - callback from HAL to report unrecoverable errors
170 * @filename: Source file where the error happened
171 * @linenum: Line number of the file where the error happened
173 void DIMCB_OnFail(const char *filename, int linenum)
175 pr_err("DIMCB_OnFail: file - %s, line no. - %d\n", filename, linenum);
179 * startup_dim - initialize the dim2 interface
180 * @pdev: platform device
182 * Get the value of command line parameter "clock_speed" if given or use the
183 * default value, enable the clock and PLL, and initialize the dim2 interface.
185 static int startup_dim(struct platform_device *pdev)
187 struct dim2_hdm *dev = platform_get_drvdata(pdev);
188 struct dim2_platform_data *pdata = pdev->dev.platform_data;
194 if (!strcmp(clock_speed, "256fs"))
195 dev->clk_speed = CLK_256FS;
196 else if (!strcmp(clock_speed, "512fs"))
197 dev->clk_speed = CLK_512FS;
198 else if (!strcmp(clock_speed, "1024fs"))
199 dev->clk_speed = CLK_1024FS;
200 else if (!strcmp(clock_speed, "2048fs"))
201 dev->clk_speed = CLK_2048FS;
202 else if (!strcmp(clock_speed, "3072fs"))
203 dev->clk_speed = CLK_3072FS;
204 else if (!strcmp(clock_speed, "4096fs"))
205 dev->clk_speed = CLK_4096FS;
206 else if (!strcmp(clock_speed, "6144fs"))
207 dev->clk_speed = CLK_6144FS;
208 else if (!strcmp(clock_speed, "8192fs"))
209 dev->clk_speed = CLK_8192FS;
212 if (dev->clk_speed == -1) {
213 pr_info("Bad or missing clock speed parameter,"
214 " using default value: 3072fs\n");
215 dev->clk_speed = CLK_3072FS;
217 pr_info("Selected clock speed: %s\n", clock_speed);
219 if (pdata && pdata->init) {
220 int ret = pdata->init(pdata, dev->io_base, dev->clk_speed);
226 hal_ret = DIM_Startup(dev->io_base, dev->clk_speed);
227 if (hal_ret != DIM_NO_ERROR) {
228 pr_err("DIM_Startup failed: %d\n", hal_ret);
229 if (pdata && pdata->destroy)
230 pdata->destroy(pdata);
238 * try_start_dim_transfer - try to transfer a buffer on a channel
239 * @hdm_ch: channel specific data
241 * Transfer a buffer from pending_list if the channel is ready
243 static int try_start_dim_transfer(struct hdm_channel *hdm_ch)
246 struct list_head *head = &hdm_ch->pending_list;
249 struct dim_ch_state_t st;
252 BUG_ON(!hdm_ch->is_initialized);
254 spin_lock_irqsave(&dim_lock, flags);
255 if (list_empty(head)) {
256 spin_unlock_irqrestore(&dim_lock, flags);
260 if (!DIM_GetChannelState(&hdm_ch->ch, &st)->ready) {
261 spin_unlock_irqrestore(&dim_lock, flags);
265 mbo = list_entry(head->next, struct mbo, list);
266 buf_size = mbo->buffer_length;
268 BUG_ON(mbo->bus_address == 0);
269 if (!DIM_EnqueueBuffer(&hdm_ch->ch, mbo->bus_address, buf_size)) {
270 list_del(head->next);
271 spin_unlock_irqrestore(&dim_lock, flags);
272 mbo->processed_length = 0;
273 mbo->status = MBO_E_INVAL;
278 list_move_tail(head->next, &hdm_ch->started_list);
279 spin_unlock_irqrestore(&dim_lock, flags);
285 * deliver_netinfo_thread - thread to deliver network status to mostcore
286 * @data: private data
288 * Wait for network status and deliver it to mostcore once it is received
290 static int deliver_netinfo_thread(void *data)
292 struct dim2_hdm *dev = (struct dim2_hdm *)data;
294 while (!kthread_should_stop()) {
295 wait_event_interruptible(dev->netinfo_waitq,
296 dev->deliver_netinfo ||
297 kthread_should_stop());
299 if (dev->deliver_netinfo) {
300 dev->deliver_netinfo--;
301 most_deliver_netinfo(&dev->most_iface, dev->link_state,
310 * retrieve_netinfo - retrieve network status from received buffer
314 * Parse the message in buffer and get node address, link state, MAC address.
315 * Wake up a thread to deliver this status to mostcore
317 static void retrieve_netinfo(struct dim2_hdm *dev, struct mbo *mbo)
319 u8 *data = mbo->virt_address;
320 u8 *mac = dev->mac_addrs;
322 pr_info("Node Address: 0x%03x\n", (u16)data[16] << 8 | data[17]);
323 dev->link_state = data[18];
324 pr_info("NIState: %d\n", dev->link_state);
325 memcpy(mac, data + 19, 6);
326 pr_info("MAC address: %02X:%02X:%02X:%02X:%02X:%02X\n",
327 mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
328 dev->deliver_netinfo++;
329 wake_up_interruptible(&dev->netinfo_waitq);
333 * service_done_flag - handle completed buffers
335 * @ch_idx: channel index
337 * Return back the completed buffers to mostcore, using completion callback
339 static void service_done_flag(struct dim2_hdm *dev, int ch_idx)
341 struct hdm_channel *hdm_ch = dev->hch + ch_idx;
342 struct dim_ch_state_t st;
343 struct list_head *head;
350 BUG_ON(!hdm_ch->is_initialized);
352 spin_lock_irqsave(&dim_lock, flags);
354 done_buffers = DIM_GetChannelState(&hdm_ch->ch, &st)->done_buffers;
356 spin_unlock_irqrestore(&dim_lock, flags);
360 if (!DIM_DetachBuffers(&hdm_ch->ch, done_buffers)) {
361 spin_unlock_irqrestore(&dim_lock, flags);
364 spin_unlock_irqrestore(&dim_lock, flags);
366 head = &hdm_ch->started_list;
368 while (done_buffers) {
369 spin_lock_irqsave(&dim_lock, flags);
370 if (list_empty(head)) {
371 spin_unlock_irqrestore(&dim_lock, flags);
372 pr_crit("hard error: started_mbo list is empty "
373 "whereas DIM2 has sent buffers\n");
377 mbo = list_entry(head->next, struct mbo, list);
378 list_del(head->next);
379 spin_unlock_irqrestore(&dim_lock, flags);
381 data = mbo->virt_address;
383 if (hdm_ch->data_type == MOST_CH_ASYNC &&
384 hdm_ch->direction == MOST_CH_RX &&
385 PACKET_IS_NET_INFO(data)) {
387 retrieve_netinfo(dev, mbo);
389 spin_lock_irqsave(&dim_lock, flags);
390 list_add_tail(&mbo->list, &hdm_ch->pending_list);
391 spin_unlock_irqrestore(&dim_lock, flags);
393 if (hdm_ch->data_type == MOST_CH_CONTROL ||
394 hdm_ch->data_type == MOST_CH_ASYNC) {
396 u32 const data_size =
397 (u32)data[0] * 256 + data[1] + 2;
399 mbo->processed_length =
400 min(data_size, (u32)mbo->buffer_length);
402 mbo->processed_length = mbo->buffer_length;
404 mbo->status = MBO_SUCCESS;
412 static struct dim_channel **get_active_channels(struct dim2_hdm *dev,
413 struct dim_channel **buffer)
418 for (ch_idx = 0; ch_idx < DMA_CHANNELS; ch_idx++) {
419 if (dev->hch[ch_idx].is_initialized)
420 buffer[idx++] = &dev->hch[ch_idx].ch;
428 * dim2_tasklet_fn - tasklet function
429 * @data: private data
431 * Service each initialized channel, if needed
433 static void dim2_tasklet_fn(unsigned long data)
435 struct dim2_hdm *dev = (struct dim2_hdm *)data;
439 for (ch_idx = 0; ch_idx < DMA_CHANNELS; ch_idx++) {
440 if (!dev->hch[ch_idx].is_initialized)
443 spin_lock_irqsave(&dim_lock, flags);
444 DIM_ServiceChannel(&(dev->hch[ch_idx].ch));
445 spin_unlock_irqrestore(&dim_lock, flags);
447 service_done_flag(dev, ch_idx);
448 while (!try_start_dim_transfer(dev->hch + ch_idx))
454 * dim2_ahb_isr - interrupt service routine
456 * @_dev: private data
458 * Acknowledge the interrupt and schedule a tasklet to service channels.
459 * Return IRQ_HANDLED.
461 static irqreturn_t dim2_ahb_isr(int irq, void *_dev)
463 struct dim2_hdm *dev = (struct dim2_hdm *)_dev;
464 struct dim_channel *buffer[DMA_CHANNELS + 1];
467 spin_lock_irqsave(&dim_lock, flags);
468 DIM_ServiceIrq(get_active_channels(dev, buffer));
469 spin_unlock_irqrestore(&dim_lock, flags);
471 #if !defined(ENABLE_HDM_TEST)
472 dim2_tasklet.data = (unsigned long)dev;
473 tasklet_schedule(&dim2_tasklet);
475 dim2_tasklet_fn((unsigned long)dev);
480 #if defined(ENABLE_HDM_TEST)
483 * Utility function used by HAL-simu for calling DIM interrupt handler.
484 * It is used only for TEST PURPOSE.
486 void raise_dim_interrupt(void)
488 (void)dim2_ahb_isr(0, test_dev);
493 * complete_all_mbos - complete MBO's in a list
496 * Delete all the entries in list and return back MBO's to mostcore using
497 * completion call back.
499 static void complete_all_mbos(struct list_head *head)
505 spin_lock_irqsave(&dim_lock, flags);
506 if (list_empty(head)) {
507 spin_unlock_irqrestore(&dim_lock, flags);
511 mbo = list_entry(head->next, struct mbo, list);
512 list_del(head->next);
513 spin_unlock_irqrestore(&dim_lock, flags);
515 mbo->processed_length = 0;
516 mbo->status = MBO_E_CLOSE;
522 * configure_channel - initialize a channel
523 * @iface: interface the channel belongs to
524 * @channel: channel to be configured
525 * @channel_config: structure that holds the configuration information
527 * Receives configuration information from mostcore and initialize
528 * the corresponding channel. Return 0 on success, negative on failure.
530 static int configure_channel(struct most_interface *most_iface, int ch_idx,
531 struct most_channel_config *ccfg)
533 struct dim2_hdm *dev = iface_to_hdm(most_iface);
534 bool const is_tx = ccfg->direction == MOST_CH_TX;
535 u16 const sub_size = ccfg->subbuffer_size;
536 u16 const buf_size = ccfg->buffer_size;
540 int const ch_addr = ch_idx * 2 + 2;
541 struct hdm_channel *const hdm_ch = dev->hch + ch_idx;
543 BUG_ON(ch_idx < 0 || ch_idx >= DMA_CHANNELS);
545 if (hdm_ch->is_initialized)
548 switch (ccfg->data_type) {
549 case MOST_CH_CONTROL:
550 new_size = DIM_NormCtrlAsyncBufferSize(buf_size);
552 pr_err("%s: too small buffer size\n", hdm_ch->name);
555 ccfg->buffer_size = new_size;
556 if (new_size != buf_size)
557 pr_warn("%s: fixed buffer size (%d -> %d)\n",
558 hdm_ch->name, buf_size, new_size);
559 spin_lock_irqsave(&dim_lock, flags);
560 hal_ret = DIM_InitControl(&hdm_ch->ch, is_tx, ch_addr, buf_size);
563 new_size = DIM_NormCtrlAsyncBufferSize(buf_size);
565 pr_err("%s: too small buffer size\n", hdm_ch->name);
568 ccfg->buffer_size = new_size;
569 if (new_size != buf_size)
570 pr_warn("%s: fixed buffer size (%d -> %d)\n",
571 hdm_ch->name, buf_size, new_size);
572 spin_lock_irqsave(&dim_lock, flags);
573 hal_ret = DIM_InitAsync(&hdm_ch->ch, is_tx, ch_addr, buf_size);
575 case MOST_CH_ISOC_AVP:
576 new_size = DIM_NormIsocBufferSize(buf_size, sub_size);
578 pr_err("%s: invalid sub-buffer size or "
579 "too small buffer size\n", hdm_ch->name);
582 ccfg->buffer_size = new_size;
583 if (new_size != buf_size)
584 pr_warn("%s: fixed buffer size (%d -> %d)\n",
585 hdm_ch->name, buf_size, new_size);
586 spin_lock_irqsave(&dim_lock, flags);
587 hal_ret = DIM_InitIsoc(&hdm_ch->ch, is_tx, ch_addr, sub_size);
590 new_size = DIM_NormSyncBufferSize(buf_size, sub_size);
592 pr_err("%s: invalid sub-buffer size or "
593 "too small buffer size\n", hdm_ch->name);
596 ccfg->buffer_size = new_size;
597 if (new_size != buf_size)
598 pr_warn("%s: fixed buffer size (%d -> %d)\n",
599 hdm_ch->name, buf_size, new_size);
600 spin_lock_irqsave(&dim_lock, flags);
601 hal_ret = DIM_InitSync(&hdm_ch->ch, is_tx, ch_addr, sub_size);
604 pr_err("%s: configure failed, bad channel type: %d\n",
605 hdm_ch->name, ccfg->data_type);
609 if (hal_ret != DIM_NO_ERROR) {
610 spin_unlock_irqrestore(&dim_lock, flags);
611 pr_err("%s: configure failed (%d), type: %d, is_tx: %d\n",
612 hdm_ch->name, hal_ret, ccfg->data_type, (int)is_tx);
616 hdm_ch->data_type = ccfg->data_type;
617 hdm_ch->direction = ccfg->direction;
618 hdm_ch->is_initialized = true;
620 if (hdm_ch->data_type == MOST_CH_ASYNC &&
621 hdm_ch->direction == MOST_CH_TX &&
623 dev->atx_idx = ch_idx;
625 spin_unlock_irqrestore(&dim_lock, flags);
631 * enqueue - enqueue a buffer for data transfer
632 * @iface: intended interface
633 * @channel: ID of the channel the buffer is intended for
634 * @mbo: pointer to the buffer object
636 * Push the buffer into pending_list and try to transfer one buffer from
637 * pending_list. Return 0 on success, negative on failure.
639 static int enqueue(struct most_interface *most_iface, int ch_idx,
642 struct dim2_hdm *dev = iface_to_hdm(most_iface);
643 struct hdm_channel *hdm_ch = dev->hch + ch_idx;
646 BUG_ON(ch_idx < 0 || ch_idx >= DMA_CHANNELS);
648 if (!hdm_ch->is_initialized)
651 if (mbo->bus_address == 0)
654 spin_lock_irqsave(&dim_lock, flags);
655 list_add_tail(&mbo->list, &hdm_ch->pending_list);
656 spin_unlock_irqrestore(&dim_lock, flags);
658 (void)try_start_dim_transfer(hdm_ch);
664 * request_netinfo - triggers retrieving of network info
665 * @iface: pointer to the interface
666 * @channel_id: corresponding channel ID
668 * Send a command to INIC which triggers retrieving of network info by means of
669 * "Message exchange over MDP/MEP". Return 0 on success, negative on failure.
671 static void request_netinfo(struct most_interface *most_iface, int ch_idx)
673 struct dim2_hdm *dev = iface_to_hdm(most_iface);
677 if (dev->atx_idx < 0) {
678 pr_err("Async Tx Not initialized\n");
682 mbo = most_get_mbo(&dev->most_iface, dev->atx_idx);
686 mbo->buffer_length = 5;
688 data = mbo->virt_address;
690 data[0] = 0x00; /* PML High byte */
691 data[1] = 0x03; /* PML Low byte */
692 data[2] = 0x02; /* PMHL */
693 data[3] = 0x08; /* FPH */
694 data[4] = 0x40; /* FMF (FIFO cmd msg - Triggers NAOverMDP) */
696 most_submit_mbo(mbo);
700 * poison_channel - poison buffers of a channel
701 * @iface: pointer to the interface the channel to be poisoned belongs to
702 * @channel_id: corresponding channel ID
704 * Destroy a channel and complete all the buffers in both started_list &
705 * pending_list. Return 0 on success, negative on failure.
707 static int poison_channel(struct most_interface *most_iface, int ch_idx)
709 struct dim2_hdm *dev = iface_to_hdm(most_iface);
710 struct hdm_channel *hdm_ch = dev->hch + ch_idx;
715 BUG_ON(ch_idx < 0 || ch_idx >= DMA_CHANNELS);
717 if (!hdm_ch->is_initialized)
720 spin_lock_irqsave(&dim_lock, flags);
721 hal_ret = DIM_DestroyChannel(&hdm_ch->ch);
722 hdm_ch->is_initialized = false;
723 if (ch_idx == dev->atx_idx)
725 spin_unlock_irqrestore(&dim_lock, flags);
726 if (hal_ret != DIM_NO_ERROR) {
727 pr_err("HAL Failed to close channel %s\n", hdm_ch->name);
731 complete_all_mbos(&hdm_ch->started_list);
732 complete_all_mbos(&hdm_ch->pending_list);
738 * dim2_probe - dim2 probe handler
739 * @pdev: platform device structure
741 * Register the dim2 interface with mostcore and initialize it.
742 * Return 0 on success, negative on failure.
744 static int dim2_probe(struct platform_device *pdev)
746 struct dim2_hdm *dev;
747 struct resource *res;
749 struct kobject *kobj;
751 dev = kzalloc(sizeof(*dev), GFP_KERNEL);
757 platform_set_drvdata(pdev, dev);
758 #if defined(ENABLE_HDM_TEST)
761 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
763 pr_err("no memory region defined\n");
768 if (!request_mem_region(res->start, resource_size(res), pdev->name)) {
769 pr_err("failed to request mem region\n");
774 dev->io_base = ioremap(res->start, resource_size(res));
776 pr_err("failed to ioremap\n");
778 goto err_release_mem;
781 ret = platform_get_irq(pdev, 0);
783 pr_err("failed to get irq\n");
788 ret = request_irq(dev->irq_ahb0, dim2_ahb_isr, 0, "mlb_ahb0", dev);
790 pr_err("failed to request IRQ: %d, err: %d\n", dev->irq_ahb0, ret);
794 init_waitqueue_head(&dev->netinfo_waitq);
795 dev->deliver_netinfo = 0;
796 dev->netinfo_task = kthread_run(&deliver_netinfo_thread, (void *)dev,
798 if (IS_ERR(dev->netinfo_task)) {
799 ret = PTR_ERR(dev->netinfo_task);
803 for (i = 0; i < DMA_CHANNELS; i++) {
804 struct most_channel_capability *cap = dev->capabilities + i;
805 struct hdm_channel *hdm_ch = dev->hch + i;
807 INIT_LIST_HEAD(&hdm_ch->pending_list);
808 INIT_LIST_HEAD(&hdm_ch->started_list);
809 hdm_ch->is_initialized = false;
810 snprintf(hdm_ch->name, sizeof(hdm_ch->name), "ca%d", i * 2 + 2);
812 cap->name_suffix = hdm_ch->name;
813 cap->direction = MOST_CH_RX | MOST_CH_TX;
814 cap->data_type = MOST_CH_CONTROL | MOST_CH_ASYNC |
815 MOST_CH_ISOC_AVP | MOST_CH_SYNC;
816 cap->num_buffers_packet = MAX_BUFFERS_PACKET;
817 cap->buffer_size_packet = MAX_BUF_SIZE_PACKET;
818 cap->num_buffers_streaming = MAX_BUFFERS_STREAMING;
819 cap->buffer_size_streaming = MAX_BUF_SIZE_STREAMING;
825 if (sizeof(res->start) == sizeof(long long))
826 fmt = "dim2-%016llx";
827 else if (sizeof(res->start) == sizeof(long))
832 snprintf(dev->name, sizeof(dev->name), fmt, res->start);
835 dev->most_iface.interface = ITYPE_MEDIALB_DIM2;
836 dev->most_iface.description = dev->name;
837 dev->most_iface.num_channels = DMA_CHANNELS;
838 dev->most_iface.channel_vector = dev->capabilities;
839 dev->most_iface.configure = configure_channel;
840 dev->most_iface.enqueue = enqueue;
841 dev->most_iface.poison_channel = poison_channel;
842 dev->most_iface.request_netinfo = request_netinfo;
844 kobj = most_register_interface(&dev->most_iface);
847 pr_err("failed to register MOST interface\n");
848 goto err_stop_thread;
851 ret = dim2_sysfs_probe(&dev->bus, kobj);
853 goto err_unreg_iface;
855 ret = startup_dim(pdev);
857 pr_err("failed to initialize DIM2\n");
858 goto err_destroy_bus;
864 dim2_sysfs_destroy(&dev->bus);
866 most_deregister_interface(&dev->most_iface);
868 kthread_stop(dev->netinfo_task);
870 #if !defined(ENABLE_HDM_TEST)
871 free_irq(dev->irq_ahb0, dev);
873 iounmap(dev->io_base);
875 release_mem_region(res->start, resource_size(res));
884 * dim2_remove - dim2 remove handler
885 * @pdev: platform device structure
887 * Unregister the interface from mostcore
889 static int dim2_remove(struct platform_device *pdev)
891 struct dim2_hdm *dev = platform_get_drvdata(pdev);
892 struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
893 struct dim2_platform_data *pdata = pdev->dev.platform_data;
896 spin_lock_irqsave(&dim_lock, flags);
898 spin_unlock_irqrestore(&dim_lock, flags);
900 if (pdata && pdata->destroy)
901 pdata->destroy(pdata);
903 dim2_sysfs_destroy(&dev->bus);
904 most_deregister_interface(&dev->most_iface);
905 kthread_stop(dev->netinfo_task);
906 #if !defined(ENABLE_HDM_TEST)
907 free_irq(dev->irq_ahb0, dev);
908 iounmap(dev->io_base);
909 release_mem_region(res->start, resource_size(res));
912 platform_set_drvdata(pdev, NULL);
915 * break link to local platform_device_id struct
916 * to prevent crash by unload platform device module
923 static struct platform_device_id dim2_id[] = {
925 { }, /* Terminating entry */
928 MODULE_DEVICE_TABLE(platform, dim2_id);
930 static struct platform_driver dim2_driver = {
932 .remove = dim2_remove,
936 .owner = THIS_MODULE,
941 * dim2_hdm_init - Driver Registration Routine
943 static int __init dim2_hdm_init(void)
945 pr_info("dim2_hdm_init()\n");
946 return platform_driver_register(&dim2_driver);
950 * dim2_hdm_exit - Driver Cleanup Routine
952 static void __exit dim2_hdm_exit(void)
954 pr_info("dim2_hdm_exit()\n");
955 platform_driver_unregister(&dim2_driver);
958 module_init(dim2_hdm_init);
959 module_exit(dim2_hdm_exit);
961 MODULE_AUTHOR("Jain Roy Ambi <JainRoy.Ambi@microchip.com>");
962 MODULE_AUTHOR("Andrey Shvetsov <andrey.shvetsov@k2l.de>");
963 MODULE_DESCRIPTION("MediaLB DIM2 Hardware Dependent Module");
964 MODULE_LICENSE("GPL");