2 * dim2_hdm.c - MediaLB DIM2 Hardware Dependent Module
4 * Copyright (C) 2015-2016, 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>
31 #include "dim2_errors.h"
32 #include "dim2_sysfs.h"
34 #define DMA_CHANNELS (32 - 1) /* channel 0 is a system channel */
36 #define MAX_BUFFERS_PACKET 32
37 #define MAX_BUFFERS_STREAMING 32
38 #define MAX_BUF_SIZE_PACKET 2048
39 #define MAX_BUF_SIZE_STREAMING (8 * 1024)
41 /* command line parameter to select clock speed */
42 static char *clock_speed;
43 module_param(clock_speed, charp, 0000);
44 MODULE_PARM_DESC(clock_speed, "MediaLB Clock Speed");
47 * The parameter representing the number of frames per sub-buffer for
48 * synchronous channels. Valid values: [0 .. 6].
50 * The values 0, 1, 2, 3, 4, 5, 6 represent corresponding number of frames per
51 * sub-buffer 1, 2, 4, 8, 16, 32, 64.
53 static u8 fcnt = 4; /* (1 << fcnt) frames per subbuffer */
54 module_param(fcnt, byte, 0000);
55 MODULE_PARM_DESC(fcnt, "Num of frames per sub-buffer for sync channels as a power of 2");
57 static DEFINE_SPINLOCK(dim_lock);
59 static void dim2_tasklet_fn(unsigned long data);
60 static DECLARE_TASKLET(dim2_tasklet, dim2_tasklet_fn, 0);
63 * struct hdm_channel - private structure to keep channel specific data
64 * @is_initialized: identifier to know whether the channel is initialized
65 * @ch: HAL specific channel data
66 * @pending_list: list to keep MBO's before starting transfer
67 * @started_list: list to keep MBO's after starting transfer
68 * @direction: channel direction (TX or RX)
69 * @data_type: channel data type
72 char name[sizeof "caNNN"];
74 struct dim_channel ch;
75 struct list_head pending_list; /* before dim_enqueue_buffer() */
76 struct list_head started_list; /* after dim_enqueue_buffer() */
77 enum most_channel_direction direction;
78 enum most_channel_data_type data_type;
82 * struct dim2_hdm - private structure to keep interface specific data
83 * @hch: an array of channel specific data
84 * @most_iface: most interface structure
85 * @capabilities: an array of channel capability data
86 * @io_base: I/O register base address
87 * @clk_speed: user selectable (through command line parameter) clock speed
88 * @netinfo_task: thread to deliver network status
89 * @netinfo_waitq: waitq for the thread to sleep
90 * @deliver_netinfo: to identify whether network status received
91 * @mac_addrs: INIC mac address
92 * @link_state: network link state
93 * @atx_idx: index of async tx channel
96 struct hdm_channel hch[DMA_CHANNELS];
97 struct most_channel_capability capabilities[DMA_CHANNELS];
98 struct most_interface most_iface;
99 char name[16 + sizeof "dim2-"];
100 void __iomem *io_base;
102 struct task_struct *netinfo_task;
103 wait_queue_head_t netinfo_waitq;
105 unsigned char mac_addrs[6];
106 unsigned char link_state;
108 struct medialb_bus bus;
109 void (*on_netinfo)(struct most_interface *,
110 unsigned char, unsigned char *);
113 #define iface_to_hdm(iface) container_of(iface, struct dim2_hdm, most_iface)
115 /* Macro to identify a network status message */
116 #define PACKET_IS_NET_INFO(p) \
117 (((p)[1] == 0x18) && ((p)[2] == 0x05) && ((p)[3] == 0x0C) && \
118 ((p)[13] == 0x3C) && ((p)[14] == 0x00) && ((p)[15] == 0x0A))
120 bool dim2_sysfs_get_state_cb(void)
125 spin_lock_irqsave(&dim_lock, flags);
126 state = dim_get_lock_state();
127 spin_unlock_irqrestore(&dim_lock, flags);
133 * dimcb_io_read - callback from HAL to read an I/O register
134 * @ptr32: register address
136 u32 dimcb_io_read(u32 __iomem *ptr32)
142 * dimcb_io_write - callback from HAL to write value to an I/O register
143 * @ptr32: register address
144 * @value: value to write
146 void dimcb_io_write(u32 __iomem *ptr32, u32 value)
148 writel(value, ptr32);
152 * dimcb_on_error - callback from HAL to report miscommunication between
154 * @error_id: Error ID
155 * @error_message: Error message. Some text in a free format
157 void dimcb_on_error(u8 error_id, const char *error_message)
159 pr_err("dimcb_on_error: error_id - %d, error_message - %s\n", error_id,
164 * startup_dim - initialize the dim2 interface
165 * @pdev: platform device
167 * Get the value of command line parameter "clock_speed" if given or use the
168 * default value, enable the clock and PLL, and initialize the dim2 interface.
170 static int startup_dim(struct platform_device *pdev)
172 struct dim2_hdm *dev = platform_get_drvdata(pdev);
173 struct dim2_platform_data *pdata = pdev->dev.platform_data;
179 if (!strcmp(clock_speed, "256fs"))
180 dev->clk_speed = CLK_256FS;
181 else if (!strcmp(clock_speed, "512fs"))
182 dev->clk_speed = CLK_512FS;
183 else if (!strcmp(clock_speed, "1024fs"))
184 dev->clk_speed = CLK_1024FS;
185 else if (!strcmp(clock_speed, "2048fs"))
186 dev->clk_speed = CLK_2048FS;
187 else if (!strcmp(clock_speed, "3072fs"))
188 dev->clk_speed = CLK_3072FS;
189 else if (!strcmp(clock_speed, "4096fs"))
190 dev->clk_speed = CLK_4096FS;
191 else if (!strcmp(clock_speed, "6144fs"))
192 dev->clk_speed = CLK_6144FS;
193 else if (!strcmp(clock_speed, "8192fs"))
194 dev->clk_speed = CLK_8192FS;
197 if (dev->clk_speed == -1) {
198 pr_info("Bad or missing clock speed parameter, using default value: 3072fs\n");
199 dev->clk_speed = CLK_3072FS;
201 pr_info("Selected clock speed: %s\n", clock_speed);
203 if (pdata && pdata->init) {
204 int ret = pdata->init(pdata, dev->io_base, dev->clk_speed);
210 pr_info("sync: num of frames per sub-buffer: %u\n", fcnt);
211 hal_ret = dim_startup(dev->io_base, dev->clk_speed, fcnt);
212 if (hal_ret != DIM_NO_ERROR) {
213 pr_err("dim_startup failed: %d\n", hal_ret);
214 if (pdata && pdata->destroy)
215 pdata->destroy(pdata);
223 * try_start_dim_transfer - try to transfer a buffer on a channel
224 * @hdm_ch: channel specific data
226 * Transfer a buffer from pending_list if the channel is ready
228 static int try_start_dim_transfer(struct hdm_channel *hdm_ch)
231 struct list_head *head = &hdm_ch->pending_list;
234 struct dim_ch_state_t st;
237 BUG_ON(!hdm_ch->is_initialized);
239 spin_lock_irqsave(&dim_lock, flags);
240 if (list_empty(head)) {
241 spin_unlock_irqrestore(&dim_lock, flags);
245 if (!dim_get_channel_state(&hdm_ch->ch, &st)->ready) {
246 spin_unlock_irqrestore(&dim_lock, flags);
250 mbo = list_first_entry(head, struct mbo, list);
251 buf_size = mbo->buffer_length;
253 if (dim_dbr_space(&hdm_ch->ch) < buf_size) {
254 spin_unlock_irqrestore(&dim_lock, flags);
258 BUG_ON(mbo->bus_address == 0);
259 if (!dim_enqueue_buffer(&hdm_ch->ch, mbo->bus_address, buf_size)) {
260 list_del(head->next);
261 spin_unlock_irqrestore(&dim_lock, flags);
262 mbo->processed_length = 0;
263 mbo->status = MBO_E_INVAL;
268 list_move_tail(head->next, &hdm_ch->started_list);
269 spin_unlock_irqrestore(&dim_lock, flags);
275 * deliver_netinfo_thread - thread to deliver network status to mostcore
276 * @data: private data
278 * Wait for network status and deliver it to mostcore once it is received
280 static int deliver_netinfo_thread(void *data)
282 struct dim2_hdm *dev = data;
284 while (!kthread_should_stop()) {
285 wait_event_interruptible(dev->netinfo_waitq,
286 dev->deliver_netinfo ||
287 kthread_should_stop());
289 if (dev->deliver_netinfo) {
290 dev->deliver_netinfo--;
291 if (dev->on_netinfo) {
292 dev->on_netinfo(&dev->most_iface,
303 * retrieve_netinfo - retrieve network status from received buffer
307 * Parse the message in buffer and get node address, link state, MAC address.
308 * Wake up a thread to deliver this status to mostcore
310 static void retrieve_netinfo(struct dim2_hdm *dev, struct mbo *mbo)
312 u8 *data = mbo->virt_address;
314 pr_info("Node Address: 0x%03x\n", (u16)data[16] << 8 | data[17]);
315 dev->link_state = data[18];
316 pr_info("NIState: %d\n", dev->link_state);
317 memcpy(dev->mac_addrs, data + 19, 6);
318 dev->deliver_netinfo++;
319 wake_up_interruptible(&dev->netinfo_waitq);
323 * service_done_flag - handle completed buffers
325 * @ch_idx: channel index
327 * Return back the completed buffers to mostcore, using completion callback
329 static void service_done_flag(struct dim2_hdm *dev, int ch_idx)
331 struct hdm_channel *hdm_ch = dev->hch + ch_idx;
332 struct dim_ch_state_t st;
333 struct list_head *head;
340 BUG_ON(!hdm_ch->is_initialized);
342 spin_lock_irqsave(&dim_lock, flags);
344 done_buffers = dim_get_channel_state(&hdm_ch->ch, &st)->done_buffers;
346 spin_unlock_irqrestore(&dim_lock, flags);
350 if (!dim_detach_buffers(&hdm_ch->ch, done_buffers)) {
351 spin_unlock_irqrestore(&dim_lock, flags);
354 spin_unlock_irqrestore(&dim_lock, flags);
356 head = &hdm_ch->started_list;
358 while (done_buffers) {
359 spin_lock_irqsave(&dim_lock, flags);
360 if (list_empty(head)) {
361 spin_unlock_irqrestore(&dim_lock, flags);
362 pr_crit("hard error: started_mbo list is empty whereas DIM2 has sent buffers\n");
366 mbo = list_first_entry(head, struct mbo, list);
367 list_del(head->next);
368 spin_unlock_irqrestore(&dim_lock, flags);
370 data = mbo->virt_address;
372 if (hdm_ch->data_type == MOST_CH_ASYNC &&
373 hdm_ch->direction == MOST_CH_RX &&
374 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) {
383 u32 const data_size =
384 (u32)data[0] * 256 + data[1] + 2;
386 mbo->processed_length =
387 min_t(u32, data_size,
390 mbo->processed_length = mbo->buffer_length;
392 mbo->status = MBO_SUCCESS;
400 static struct dim_channel **get_active_channels(struct dim2_hdm *dev,
401 struct dim_channel **buffer)
406 for (ch_idx = 0; ch_idx < DMA_CHANNELS; ch_idx++) {
407 if (dev->hch[ch_idx].is_initialized)
408 buffer[idx++] = &dev->hch[ch_idx].ch;
410 buffer[idx++] = NULL;
415 static irqreturn_t dim2_mlb_isr(int irq, void *_dev)
417 struct dim2_hdm *dev = _dev;
420 spin_lock_irqsave(&dim_lock, flags);
421 dim_service_mlb_int_irq();
422 spin_unlock_irqrestore(&dim_lock, flags);
424 if (dev->atx_idx >= 0 && dev->hch[dev->atx_idx].is_initialized)
425 while (!try_start_dim_transfer(dev->hch + dev->atx_idx))
432 * dim2_tasklet_fn - tasklet function
433 * @data: private data
435 * Service each initialized channel, if needed
437 static void dim2_tasklet_fn(unsigned long data)
439 struct dim2_hdm *dev = (struct dim2_hdm *)data;
443 for (ch_idx = 0; ch_idx < DMA_CHANNELS; ch_idx++) {
444 if (!dev->hch[ch_idx].is_initialized)
447 spin_lock_irqsave(&dim_lock, flags);
448 dim_service_channel(&dev->hch[ch_idx].ch);
449 spin_unlock_irqrestore(&dim_lock, flags);
451 service_done_flag(dev, ch_idx);
452 while (!try_start_dim_transfer(dev->hch + ch_idx))
458 * dim2_ahb_isr - interrupt service routine
460 * @_dev: private data
462 * Acknowledge the interrupt and schedule a tasklet to service channels.
463 * Return IRQ_HANDLED.
465 static irqreturn_t dim2_ahb_isr(int irq, void *_dev)
467 struct dim2_hdm *dev = _dev;
468 struct dim_channel *buffer[DMA_CHANNELS + 1];
471 spin_lock_irqsave(&dim_lock, flags);
472 dim_service_ahb_int_irq(get_active_channels(dev, buffer));
473 spin_unlock_irqrestore(&dim_lock, flags);
475 dim2_tasklet.data = (unsigned long)dev;
476 tasklet_schedule(&dim2_tasklet);
481 * complete_all_mbos - complete MBO's in a list
484 * Delete all the entries in list and return back MBO's to mostcore using
485 * completion call back.
487 static void complete_all_mbos(struct list_head *head)
493 spin_lock_irqsave(&dim_lock, flags);
494 if (list_empty(head)) {
495 spin_unlock_irqrestore(&dim_lock, flags);
499 mbo = list_first_entry(head, struct mbo, list);
500 list_del(head->next);
501 spin_unlock_irqrestore(&dim_lock, flags);
503 mbo->processed_length = 0;
504 mbo->status = MBO_E_CLOSE;
510 * configure_channel - initialize a channel
511 * @iface: interface the channel belongs to
512 * @channel: channel to be configured
513 * @channel_config: structure that holds the configuration information
515 * Receives configuration information from mostcore and initialize
516 * the corresponding channel. Return 0 on success, negative on failure.
518 static int configure_channel(struct most_interface *most_iface, int ch_idx,
519 struct most_channel_config *ccfg)
521 struct dim2_hdm *dev = iface_to_hdm(most_iface);
522 bool const is_tx = ccfg->direction == MOST_CH_TX;
523 u16 const sub_size = ccfg->subbuffer_size;
524 u16 const buf_size = ccfg->buffer_size;
528 int const ch_addr = ch_idx * 2 + 2;
529 struct hdm_channel *const hdm_ch = dev->hch + ch_idx;
531 BUG_ON(ch_idx < 0 || ch_idx >= DMA_CHANNELS);
533 if (hdm_ch->is_initialized)
536 switch (ccfg->data_type) {
537 case MOST_CH_CONTROL:
538 new_size = dim_norm_ctrl_async_buffer_size(buf_size);
540 pr_err("%s: too small buffer size\n", hdm_ch->name);
543 ccfg->buffer_size = new_size;
544 if (new_size != buf_size)
545 pr_warn("%s: fixed buffer size (%d -> %d)\n",
546 hdm_ch->name, buf_size, new_size);
547 spin_lock_irqsave(&dim_lock, flags);
548 hal_ret = dim_init_control(&hdm_ch->ch, is_tx, ch_addr,
549 is_tx ? new_size * 2 : new_size);
552 new_size = dim_norm_ctrl_async_buffer_size(buf_size);
554 pr_err("%s: too small buffer size\n", hdm_ch->name);
557 ccfg->buffer_size = new_size;
558 if (new_size != buf_size)
559 pr_warn("%s: fixed buffer size (%d -> %d)\n",
560 hdm_ch->name, buf_size, new_size);
561 spin_lock_irqsave(&dim_lock, flags);
562 hal_ret = dim_init_async(&hdm_ch->ch, is_tx, ch_addr,
563 is_tx ? new_size * 2 : new_size);
566 new_size = dim_norm_isoc_buffer_size(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_init_isoc(&hdm_ch->ch, is_tx, ch_addr, sub_size);
580 new_size = dim_norm_sync_buffer_size(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_init_sync(&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,
662 void (*on_netinfo)(struct most_interface *,
663 unsigned char, unsigned char *))
665 struct dim2_hdm *dev = iface_to_hdm(most_iface);
669 dev->on_netinfo = on_netinfo;
673 if (dev->atx_idx < 0) {
674 pr_err("Async Tx Not initialized\n");
678 mbo = most_get_mbo(&dev->most_iface, dev->atx_idx, NULL);
682 mbo->buffer_length = 5;
684 data = mbo->virt_address;
686 data[0] = 0x00; /* PML High byte */
687 data[1] = 0x03; /* PML Low byte */
688 data[2] = 0x02; /* PMHL */
689 data[3] = 0x08; /* FPH */
690 data[4] = 0x40; /* FMF (FIFO cmd msg - Triggers NAOverMDP) */
692 most_submit_mbo(mbo);
696 * poison_channel - poison buffers of a channel
697 * @iface: pointer to the interface the channel to be poisoned belongs to
698 * @channel_id: corresponding channel ID
700 * Destroy a channel and complete all the buffers in both started_list &
701 * pending_list. Return 0 on success, negative on failure.
703 static int poison_channel(struct most_interface *most_iface, int ch_idx)
705 struct dim2_hdm *dev = iface_to_hdm(most_iface);
706 struct hdm_channel *hdm_ch = dev->hch + ch_idx;
711 BUG_ON(ch_idx < 0 || ch_idx >= DMA_CHANNELS);
713 if (!hdm_ch->is_initialized)
716 tasklet_disable(&dim2_tasklet);
717 spin_lock_irqsave(&dim_lock, flags);
718 hal_ret = dim_destroy_channel(&hdm_ch->ch);
719 hdm_ch->is_initialized = false;
720 if (ch_idx == dev->atx_idx)
722 spin_unlock_irqrestore(&dim_lock, flags);
723 tasklet_enable(&dim2_tasklet);
724 if (hal_ret != DIM_NO_ERROR) {
725 pr_err("HAL Failed to close channel %s\n", hdm_ch->name);
729 complete_all_mbos(&hdm_ch->started_list);
730 complete_all_mbos(&hdm_ch->pending_list);
736 * dim2_probe - dim2 probe handler
737 * @pdev: platform device structure
739 * Register the dim2 interface with mostcore and initialize it.
740 * Return 0 on success, negative on failure.
742 static int dim2_probe(struct platform_device *pdev)
744 struct dim2_hdm *dev;
745 struct resource *res;
747 struct kobject *kobj;
750 dev = devm_kzalloc(&pdev->dev, sizeof(*dev), GFP_KERNEL);
756 platform_set_drvdata(pdev, dev);
757 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
758 dev->io_base = devm_ioremap_resource(&pdev->dev, res);
759 if (IS_ERR(dev->io_base))
760 return PTR_ERR(dev->io_base);
762 irq = platform_get_irq(pdev, 0);
764 dev_err(&pdev->dev, "failed to get ahb0_int irq: %d\n", irq);
768 ret = devm_request_irq(&pdev->dev, irq, dim2_ahb_isr, 0,
769 "dim2_ahb0_int", dev);
771 dev_err(&pdev->dev, "failed to request ahb0_int irq %d\n", irq);
775 irq = platform_get_irq(pdev, 1);
777 dev_err(&pdev->dev, "failed to get mlb_int irq: %d\n", irq);
781 ret = devm_request_irq(&pdev->dev, irq, dim2_mlb_isr, 0,
782 "dim2_mlb_int", dev);
784 dev_err(&pdev->dev, "failed to request mlb_int irq %d\n", irq);
788 init_waitqueue_head(&dev->netinfo_waitq);
789 dev->deliver_netinfo = 0;
790 dev->netinfo_task = kthread_run(&deliver_netinfo_thread, (void *)dev,
792 if (IS_ERR(dev->netinfo_task))
793 return PTR_ERR(dev->netinfo_task);
795 for (i = 0; i < DMA_CHANNELS; i++) {
796 struct most_channel_capability *cap = dev->capabilities + i;
797 struct hdm_channel *hdm_ch = dev->hch + i;
799 INIT_LIST_HEAD(&hdm_ch->pending_list);
800 INIT_LIST_HEAD(&hdm_ch->started_list);
801 hdm_ch->is_initialized = false;
802 snprintf(hdm_ch->name, sizeof(hdm_ch->name), "ca%d", i * 2 + 2);
804 cap->name_suffix = hdm_ch->name;
805 cap->direction = MOST_CH_RX | MOST_CH_TX;
806 cap->data_type = MOST_CH_CONTROL | MOST_CH_ASYNC |
807 MOST_CH_ISOC | MOST_CH_SYNC;
808 cap->num_buffers_packet = MAX_BUFFERS_PACKET;
809 cap->buffer_size_packet = MAX_BUF_SIZE_PACKET;
810 cap->num_buffers_streaming = MAX_BUFFERS_STREAMING;
811 cap->buffer_size_streaming = MAX_BUF_SIZE_STREAMING;
817 if (sizeof(res->start) == sizeof(long long))
818 fmt = "dim2-%016llx";
819 else if (sizeof(res->start) == sizeof(long))
824 snprintf(dev->name, sizeof(dev->name), fmt, res->start);
827 dev->most_iface.interface = ITYPE_MEDIALB_DIM2;
828 dev->most_iface.description = dev->name;
829 dev->most_iface.num_channels = DMA_CHANNELS;
830 dev->most_iface.channel_vector = dev->capabilities;
831 dev->most_iface.configure = configure_channel;
832 dev->most_iface.enqueue = enqueue;
833 dev->most_iface.poison_channel = poison_channel;
834 dev->most_iface.request_netinfo = request_netinfo;
836 kobj = most_register_interface(&dev->most_iface);
839 dev_err(&pdev->dev, "failed to register MOST interface\n");
840 goto err_stop_thread;
843 ret = dim2_sysfs_probe(&dev->bus, kobj);
845 goto err_unreg_iface;
847 ret = startup_dim(pdev);
849 dev_err(&pdev->dev, "failed to initialize DIM2\n");
850 goto err_destroy_bus;
856 dim2_sysfs_destroy(&dev->bus);
858 most_deregister_interface(&dev->most_iface);
860 kthread_stop(dev->netinfo_task);
866 * dim2_remove - dim2 remove handler
867 * @pdev: platform device structure
869 * Unregister the interface from mostcore
871 static int dim2_remove(struct platform_device *pdev)
873 struct dim2_hdm *dev = platform_get_drvdata(pdev);
874 struct dim2_platform_data *pdata = pdev->dev.platform_data;
877 spin_lock_irqsave(&dim_lock, flags);
879 spin_unlock_irqrestore(&dim_lock, flags);
881 if (pdata && pdata->destroy)
882 pdata->destroy(pdata);
884 dim2_sysfs_destroy(&dev->bus);
885 most_deregister_interface(&dev->most_iface);
886 kthread_stop(dev->netinfo_task);
889 * break link to local platform_device_id struct
890 * to prevent crash by unload platform device module
892 pdev->id_entry = NULL;
897 static const struct platform_device_id dim2_id[] = {
899 { }, /* Terminating entry */
902 MODULE_DEVICE_TABLE(platform, dim2_id);
904 static struct platform_driver dim2_driver = {
906 .remove = dim2_remove,
913 module_platform_driver(dim2_driver);
915 MODULE_AUTHOR("Jain Roy Ambi <JainRoy.Ambi@microchip.com>");
916 MODULE_AUTHOR("Andrey Shvetsov <andrey.shvetsov@k2l.de>");
917 MODULE_DESCRIPTION("MediaLB DIM2 Hardware Dependent Module");
918 MODULE_LICENSE("GPL");