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 * startup_dim - initialize the dim2 interface
170 * @pdev: platform device
172 * Get the value of command line parameter "clock_speed" if given or use the
173 * default value, enable the clock and PLL, and initialize the dim2 interface.
175 static int startup_dim(struct platform_device *pdev)
177 struct dim2_hdm *dev = platform_get_drvdata(pdev);
178 struct dim2_platform_data *pdata = pdev->dev.platform_data;
184 if (!strcmp(clock_speed, "256fs"))
185 dev->clk_speed = CLK_256FS;
186 else if (!strcmp(clock_speed, "512fs"))
187 dev->clk_speed = CLK_512FS;
188 else if (!strcmp(clock_speed, "1024fs"))
189 dev->clk_speed = CLK_1024FS;
190 else if (!strcmp(clock_speed, "2048fs"))
191 dev->clk_speed = CLK_2048FS;
192 else if (!strcmp(clock_speed, "3072fs"))
193 dev->clk_speed = CLK_3072FS;
194 else if (!strcmp(clock_speed, "4096fs"))
195 dev->clk_speed = CLK_4096FS;
196 else if (!strcmp(clock_speed, "6144fs"))
197 dev->clk_speed = CLK_6144FS;
198 else if (!strcmp(clock_speed, "8192fs"))
199 dev->clk_speed = CLK_8192FS;
202 if (dev->clk_speed == -1) {
203 pr_info("Bad or missing clock speed parameter, using default value: 3072fs\n");
204 dev->clk_speed = CLK_3072FS;
206 pr_info("Selected clock speed: %s\n", clock_speed);
208 if (pdata && pdata->init) {
209 int ret = pdata->init(pdata, dev->io_base, dev->clk_speed);
215 hal_ret = DIM_Startup(dev->io_base, dev->clk_speed);
216 if (hal_ret != DIM_NO_ERROR) {
217 pr_err("DIM_Startup failed: %d\n", hal_ret);
218 if (pdata && pdata->destroy)
219 pdata->destroy(pdata);
227 * try_start_dim_transfer - try to transfer a buffer on a channel
228 * @hdm_ch: channel specific data
230 * Transfer a buffer from pending_list if the channel is ready
232 static int try_start_dim_transfer(struct hdm_channel *hdm_ch)
235 struct list_head *head = &hdm_ch->pending_list;
238 struct dim_ch_state_t st;
241 BUG_ON(!hdm_ch->is_initialized);
243 spin_lock_irqsave(&dim_lock, flags);
244 if (list_empty(head)) {
245 spin_unlock_irqrestore(&dim_lock, flags);
249 if (!DIM_GetChannelState(&hdm_ch->ch, &st)->ready) {
250 spin_unlock_irqrestore(&dim_lock, flags);
254 mbo = list_entry(head->next, struct mbo, list);
255 buf_size = mbo->buffer_length;
257 BUG_ON(mbo->bus_address == 0);
258 if (!DIM_EnqueueBuffer(&hdm_ch->ch, mbo->bus_address, buf_size)) {
259 list_del(head->next);
260 spin_unlock_irqrestore(&dim_lock, flags);
261 mbo->processed_length = 0;
262 mbo->status = MBO_E_INVAL;
267 list_move_tail(head->next, &hdm_ch->started_list);
268 spin_unlock_irqrestore(&dim_lock, flags);
274 * deliver_netinfo_thread - thread to deliver network status to mostcore
275 * @data: private data
277 * Wait for network status and deliver it to mostcore once it is received
279 static int deliver_netinfo_thread(void *data)
281 struct dim2_hdm *dev = data;
283 while (!kthread_should_stop()) {
284 wait_event_interruptible(dev->netinfo_waitq,
285 dev->deliver_netinfo ||
286 kthread_should_stop());
288 if (dev->deliver_netinfo) {
289 dev->deliver_netinfo--;
290 most_deliver_netinfo(&dev->most_iface, dev->link_state,
299 * retrieve_netinfo - retrieve network status from received buffer
303 * Parse the message in buffer and get node address, link state, MAC address.
304 * Wake up a thread to deliver this status to mostcore
306 static void retrieve_netinfo(struct dim2_hdm *dev, struct mbo *mbo)
308 u8 *data = mbo->virt_address;
309 u8 *mac = dev->mac_addrs;
311 pr_info("Node Address: 0x%03x\n", (u16)data[16] << 8 | data[17]);
312 dev->link_state = data[18];
313 pr_info("NIState: %d\n", dev->link_state);
314 memcpy(mac, data + 19, 6);
315 pr_info("MAC address: %02X:%02X:%02X:%02X:%02X:%02X\n",
316 mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
317 dev->deliver_netinfo++;
318 wake_up_interruptible(&dev->netinfo_waitq);
322 * service_done_flag - handle completed buffers
324 * @ch_idx: channel index
326 * Return back the completed buffers to mostcore, using completion callback
328 static void service_done_flag(struct dim2_hdm *dev, int ch_idx)
330 struct hdm_channel *hdm_ch = dev->hch + ch_idx;
331 struct dim_ch_state_t st;
332 struct list_head *head;
339 BUG_ON(!hdm_ch->is_initialized);
341 spin_lock_irqsave(&dim_lock, flags);
343 done_buffers = DIM_GetChannelState(&hdm_ch->ch, &st)->done_buffers;
345 spin_unlock_irqrestore(&dim_lock, flags);
349 if (!DIM_DetachBuffers(&hdm_ch->ch, done_buffers)) {
350 spin_unlock_irqrestore(&dim_lock, flags);
353 spin_unlock_irqrestore(&dim_lock, flags);
355 head = &hdm_ch->started_list;
357 while (done_buffers) {
358 spin_lock_irqsave(&dim_lock, flags);
359 if (list_empty(head)) {
360 spin_unlock_irqrestore(&dim_lock, flags);
361 pr_crit("hard error: started_mbo list is empty whereas DIM2 has sent buffers\n");
365 mbo = list_entry(head->next, struct mbo, list);
366 list_del(head->next);
367 spin_unlock_irqrestore(&dim_lock, flags);
369 data = mbo->virt_address;
371 if (hdm_ch->data_type == MOST_CH_ASYNC &&
372 hdm_ch->direction == MOST_CH_RX &&
373 PACKET_IS_NET_INFO(data)) {
375 retrieve_netinfo(dev, mbo);
377 spin_lock_irqsave(&dim_lock, flags);
378 list_add_tail(&mbo->list, &hdm_ch->pending_list);
379 spin_unlock_irqrestore(&dim_lock, flags);
381 if (hdm_ch->data_type == MOST_CH_CONTROL ||
382 hdm_ch->data_type == MOST_CH_ASYNC) {
384 u32 const data_size =
385 (u32)data[0] * 256 + data[1] + 2;
387 mbo->processed_length =
388 min_t(u32, data_size,
391 mbo->processed_length = mbo->buffer_length;
393 mbo->status = MBO_SUCCESS;
401 static struct dim_channel **get_active_channels(struct dim2_hdm *dev,
402 struct dim_channel **buffer)
407 for (ch_idx = 0; ch_idx < DMA_CHANNELS; ch_idx++) {
408 if (dev->hch[ch_idx].is_initialized)
409 buffer[idx++] = &dev->hch[ch_idx].ch;
411 buffer[idx++] = NULL;
417 * dim2_tasklet_fn - tasklet function
418 * @data: private data
420 * Service each initialized channel, if needed
422 static void dim2_tasklet_fn(unsigned long data)
424 struct dim2_hdm *dev = (struct dim2_hdm *)data;
428 for (ch_idx = 0; ch_idx < DMA_CHANNELS; ch_idx++) {
429 if (!dev->hch[ch_idx].is_initialized)
432 spin_lock_irqsave(&dim_lock, flags);
433 DIM_ServiceChannel(&dev->hch[ch_idx].ch);
434 spin_unlock_irqrestore(&dim_lock, flags);
436 service_done_flag(dev, ch_idx);
437 while (!try_start_dim_transfer(dev->hch + ch_idx))
443 * dim2_ahb_isr - interrupt service routine
445 * @_dev: private data
447 * Acknowledge the interrupt and schedule a tasklet to service channels.
448 * Return IRQ_HANDLED.
450 static irqreturn_t dim2_ahb_isr(int irq, void *_dev)
452 struct dim2_hdm *dev = _dev;
453 struct dim_channel *buffer[DMA_CHANNELS + 1];
456 spin_lock_irqsave(&dim_lock, flags);
457 DIM_ServiceIrq(get_active_channels(dev, buffer));
458 spin_unlock_irqrestore(&dim_lock, flags);
460 #if !defined(ENABLE_HDM_TEST)
461 dim2_tasklet.data = (unsigned long)dev;
462 tasklet_schedule(&dim2_tasklet);
464 dim2_tasklet_fn((unsigned long)dev);
469 #if defined(ENABLE_HDM_TEST)
472 * Utility function used by HAL-simu for calling DIM interrupt handler.
473 * It is used only for TEST PURPOSE.
475 void raise_dim_interrupt(void)
477 (void)dim2_ahb_isr(0, test_dev);
482 * complete_all_mbos - complete MBO's in a list
485 * Delete all the entries in list and return back MBO's to mostcore using
486 * completion call back.
488 static void complete_all_mbos(struct list_head *head)
494 spin_lock_irqsave(&dim_lock, flags);
495 if (list_empty(head)) {
496 spin_unlock_irqrestore(&dim_lock, flags);
500 mbo = list_entry(head->next, struct mbo, list);
501 list_del(head->next);
502 spin_unlock_irqrestore(&dim_lock, flags);
504 mbo->processed_length = 0;
505 mbo->status = MBO_E_CLOSE;
511 * configure_channel - initialize a channel
512 * @iface: interface the channel belongs to
513 * @channel: channel to be configured
514 * @channel_config: structure that holds the configuration information
516 * Receives configuration information from mostcore and initialize
517 * the corresponding channel. Return 0 on success, negative on failure.
519 static int configure_channel(struct most_interface *most_iface, int ch_idx,
520 struct most_channel_config *ccfg)
522 struct dim2_hdm *dev = iface_to_hdm(most_iface);
523 bool const is_tx = ccfg->direction == MOST_CH_TX;
524 u16 const sub_size = ccfg->subbuffer_size;
525 u16 const buf_size = ccfg->buffer_size;
529 int const ch_addr = ch_idx * 2 + 2;
530 struct hdm_channel *const hdm_ch = dev->hch + ch_idx;
532 BUG_ON(ch_idx < 0 || ch_idx >= DMA_CHANNELS);
534 if (hdm_ch->is_initialized)
537 switch (ccfg->data_type) {
538 case MOST_CH_CONTROL:
539 new_size = DIM_NormCtrlAsyncBufferSize(buf_size);
541 pr_err("%s: too small buffer size\n", hdm_ch->name);
544 ccfg->buffer_size = new_size;
545 if (new_size != buf_size)
546 pr_warn("%s: fixed buffer size (%d -> %d)\n",
547 hdm_ch->name, buf_size, new_size);
548 spin_lock_irqsave(&dim_lock, flags);
549 hal_ret = DIM_InitControl(&hdm_ch->ch, is_tx, ch_addr,
553 new_size = DIM_NormCtrlAsyncBufferSize(buf_size);
555 pr_err("%s: too small buffer size\n", hdm_ch->name);
558 ccfg->buffer_size = new_size;
559 if (new_size != buf_size)
560 pr_warn("%s: fixed buffer size (%d -> %d)\n",
561 hdm_ch->name, buf_size, new_size);
562 spin_lock_irqsave(&dim_lock, flags);
563 hal_ret = DIM_InitAsync(&hdm_ch->ch, is_tx, ch_addr, buf_size);
565 case MOST_CH_ISOC_AVP:
566 new_size = DIM_NormIsocBufferSize(buf_size, sub_size);
568 pr_err("%s: invalid sub-buffer size or too small buffer size\n",
572 ccfg->buffer_size = new_size;
573 if (new_size != buf_size)
574 pr_warn("%s: fixed buffer size (%d -> %d)\n",
575 hdm_ch->name, buf_size, new_size);
576 spin_lock_irqsave(&dim_lock, flags);
577 hal_ret = DIM_InitIsoc(&hdm_ch->ch, is_tx, ch_addr, sub_size);
580 new_size = DIM_NormSyncBufferSize(buf_size, sub_size);
582 pr_err("%s: invalid sub-buffer size or too small buffer size\n",
586 ccfg->buffer_size = new_size;
587 if (new_size != buf_size)
588 pr_warn("%s: fixed buffer size (%d -> %d)\n",
589 hdm_ch->name, buf_size, new_size);
590 spin_lock_irqsave(&dim_lock, flags);
591 hal_ret = DIM_InitSync(&hdm_ch->ch, is_tx, ch_addr, sub_size);
594 pr_err("%s: configure failed, bad channel type: %d\n",
595 hdm_ch->name, ccfg->data_type);
599 if (hal_ret != DIM_NO_ERROR) {
600 spin_unlock_irqrestore(&dim_lock, flags);
601 pr_err("%s: configure failed (%d), type: %d, is_tx: %d\n",
602 hdm_ch->name, hal_ret, ccfg->data_type, (int)is_tx);
606 hdm_ch->data_type = ccfg->data_type;
607 hdm_ch->direction = ccfg->direction;
608 hdm_ch->is_initialized = true;
610 if (hdm_ch->data_type == MOST_CH_ASYNC &&
611 hdm_ch->direction == MOST_CH_TX &&
613 dev->atx_idx = ch_idx;
615 spin_unlock_irqrestore(&dim_lock, flags);
621 * enqueue - enqueue a buffer for data transfer
622 * @iface: intended interface
623 * @channel: ID of the channel the buffer is intended for
624 * @mbo: pointer to the buffer object
626 * Push the buffer into pending_list and try to transfer one buffer from
627 * pending_list. Return 0 on success, negative on failure.
629 static int enqueue(struct most_interface *most_iface, int ch_idx,
632 struct dim2_hdm *dev = iface_to_hdm(most_iface);
633 struct hdm_channel *hdm_ch = dev->hch + ch_idx;
636 BUG_ON(ch_idx < 0 || ch_idx >= DMA_CHANNELS);
638 if (!hdm_ch->is_initialized)
641 if (mbo->bus_address == 0)
644 spin_lock_irqsave(&dim_lock, flags);
645 list_add_tail(&mbo->list, &hdm_ch->pending_list);
646 spin_unlock_irqrestore(&dim_lock, flags);
648 (void)try_start_dim_transfer(hdm_ch);
654 * request_netinfo - triggers retrieving of network info
655 * @iface: pointer to the interface
656 * @channel_id: corresponding channel ID
658 * Send a command to INIC which triggers retrieving of network info by means of
659 * "Message exchange over MDP/MEP". Return 0 on success, negative on failure.
661 static void request_netinfo(struct most_interface *most_iface, int ch_idx)
663 struct dim2_hdm *dev = iface_to_hdm(most_iface);
667 if (dev->atx_idx < 0) {
668 pr_err("Async Tx Not initialized\n");
672 mbo = most_get_mbo(&dev->most_iface, dev->atx_idx, NULL);
676 mbo->buffer_length = 5;
678 data = mbo->virt_address;
680 data[0] = 0x00; /* PML High byte */
681 data[1] = 0x03; /* PML Low byte */
682 data[2] = 0x02; /* PMHL */
683 data[3] = 0x08; /* FPH */
684 data[4] = 0x40; /* FMF (FIFO cmd msg - Triggers NAOverMDP) */
686 most_submit_mbo(mbo);
690 * poison_channel - poison buffers of a channel
691 * @iface: pointer to the interface the channel to be poisoned belongs to
692 * @channel_id: corresponding channel ID
694 * Destroy a channel and complete all the buffers in both started_list &
695 * pending_list. Return 0 on success, negative on failure.
697 static int poison_channel(struct most_interface *most_iface, int ch_idx)
699 struct dim2_hdm *dev = iface_to_hdm(most_iface);
700 struct hdm_channel *hdm_ch = dev->hch + ch_idx;
705 BUG_ON(ch_idx < 0 || ch_idx >= DMA_CHANNELS);
707 if (!hdm_ch->is_initialized)
710 spin_lock_irqsave(&dim_lock, flags);
711 hal_ret = DIM_DestroyChannel(&hdm_ch->ch);
712 hdm_ch->is_initialized = false;
713 if (ch_idx == dev->atx_idx)
715 spin_unlock_irqrestore(&dim_lock, flags);
716 if (hal_ret != DIM_NO_ERROR) {
717 pr_err("HAL Failed to close channel %s\n", hdm_ch->name);
721 complete_all_mbos(&hdm_ch->started_list);
722 complete_all_mbos(&hdm_ch->pending_list);
728 * dim2_probe - dim2 probe handler
729 * @pdev: platform device structure
731 * Register the dim2 interface with mostcore and initialize it.
732 * Return 0 on success, negative on failure.
734 static int dim2_probe(struct platform_device *pdev)
736 struct dim2_hdm *dev;
737 struct resource *res;
739 struct kobject *kobj;
741 dev = kzalloc(sizeof(*dev), GFP_KERNEL);
747 platform_set_drvdata(pdev, dev);
748 #if defined(ENABLE_HDM_TEST)
751 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
753 pr_err("no memory region defined\n");
758 if (!request_mem_region(res->start, resource_size(res), pdev->name)) {
759 pr_err("failed to request mem region\n");
764 dev->io_base = ioremap(res->start, resource_size(res));
766 pr_err("failed to ioremap\n");
768 goto err_release_mem;
771 ret = platform_get_irq(pdev, 0);
773 pr_err("failed to get irq\n");
778 ret = request_irq(dev->irq_ahb0, dim2_ahb_isr, 0, "mlb_ahb0", dev);
780 pr_err("failed to request IRQ: %d, err: %d\n",
785 init_waitqueue_head(&dev->netinfo_waitq);
786 dev->deliver_netinfo = 0;
787 dev->netinfo_task = kthread_run(&deliver_netinfo_thread, (void *)dev,
789 if (IS_ERR(dev->netinfo_task)) {
790 ret = PTR_ERR(dev->netinfo_task);
794 for (i = 0; i < DMA_CHANNELS; i++) {
795 struct most_channel_capability *cap = dev->capabilities + i;
796 struct hdm_channel *hdm_ch = dev->hch + i;
798 INIT_LIST_HEAD(&hdm_ch->pending_list);
799 INIT_LIST_HEAD(&hdm_ch->started_list);
800 hdm_ch->is_initialized = false;
801 snprintf(hdm_ch->name, sizeof(hdm_ch->name), "ca%d", i * 2 + 2);
803 cap->name_suffix = hdm_ch->name;
804 cap->direction = MOST_CH_RX | MOST_CH_TX;
805 cap->data_type = MOST_CH_CONTROL | MOST_CH_ASYNC |
806 MOST_CH_ISOC_AVP | MOST_CH_SYNC;
807 cap->num_buffers_packet = MAX_BUFFERS_PACKET;
808 cap->buffer_size_packet = MAX_BUF_SIZE_PACKET;
809 cap->num_buffers_streaming = MAX_BUFFERS_STREAMING;
810 cap->buffer_size_streaming = MAX_BUF_SIZE_STREAMING;
816 if (sizeof(res->start) == sizeof(long long))
817 fmt = "dim2-%016llx";
818 else if (sizeof(res->start) == sizeof(long))
823 snprintf(dev->name, sizeof(dev->name), fmt, res->start);
826 dev->most_iface.interface = ITYPE_MEDIALB_DIM2;
827 dev->most_iface.description = dev->name;
828 dev->most_iface.num_channels = DMA_CHANNELS;
829 dev->most_iface.channel_vector = dev->capabilities;
830 dev->most_iface.configure = configure_channel;
831 dev->most_iface.enqueue = enqueue;
832 dev->most_iface.poison_channel = poison_channel;
833 dev->most_iface.request_netinfo = request_netinfo;
835 kobj = most_register_interface(&dev->most_iface);
838 pr_err("failed to register MOST interface\n");
839 goto err_stop_thread;
842 ret = dim2_sysfs_probe(&dev->bus, kobj);
844 goto err_unreg_iface;
846 ret = startup_dim(pdev);
848 pr_err("failed to initialize DIM2\n");
849 goto err_destroy_bus;
855 dim2_sysfs_destroy(&dev->bus);
857 most_deregister_interface(&dev->most_iface);
859 kthread_stop(dev->netinfo_task);
861 #if !defined(ENABLE_HDM_TEST)
862 free_irq(dev->irq_ahb0, dev);
864 iounmap(dev->io_base);
866 release_mem_region(res->start, resource_size(res));
875 * dim2_remove - dim2 remove handler
876 * @pdev: platform device structure
878 * Unregister the interface from mostcore
880 static int dim2_remove(struct platform_device *pdev)
882 struct dim2_hdm *dev = platform_get_drvdata(pdev);
883 struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
884 struct dim2_platform_data *pdata = pdev->dev.platform_data;
887 spin_lock_irqsave(&dim_lock, flags);
889 spin_unlock_irqrestore(&dim_lock, flags);
891 if (pdata && pdata->destroy)
892 pdata->destroy(pdata);
894 dim2_sysfs_destroy(&dev->bus);
895 most_deregister_interface(&dev->most_iface);
896 kthread_stop(dev->netinfo_task);
897 #if !defined(ENABLE_HDM_TEST)
898 free_irq(dev->irq_ahb0, dev);
899 iounmap(dev->io_base);
900 release_mem_region(res->start, resource_size(res));
903 platform_set_drvdata(pdev, NULL);
906 * break link to local platform_device_id struct
907 * to prevent crash by unload platform device module
909 pdev->id_entry = NULL;
914 static struct platform_device_id dim2_id[] = {
916 { }, /* Terminating entry */
919 MODULE_DEVICE_TABLE(platform, dim2_id);
921 static struct platform_driver dim2_driver = {
923 .remove = dim2_remove,
930 module_platform_driver(dim2_driver);
932 MODULE_AUTHOR("Jain Roy Ambi <JainRoy.Ambi@microchip.com>");
933 MODULE_AUTHOR("Andrey Shvetsov <andrey.shvetsov@k2l.de>");
934 MODULE_DESCRIPTION("MediaLB DIM2 Hardware Dependent Module");
935 MODULE_LICENSE("GPL");