blob: 32a7b673cbc87532dd15170210c06127755fb01b [file] [log] [blame]
Takashi Sakamoto3f471522015-12-22 09:15:39 +09001/*
2 * oxfw-scs1x.c - a part of driver for OXFW970/971 based devices
3 *
4 * Copyright (c) Clemens Ladisch <clemens@ladisch.de>
5 * Copyright (c) 2015 Takashi Sakamoto <o-takashi@sakamocchi.jp>
6 *
7 * Licensed under the terms of the GNU General Public License, version 2.
8 */
9
10#include "oxfw.h"
11
Takashi Sakamotoe3315b42015-12-22 09:15:40 +090012#define HSS1394_ADDRESS 0xc007dedadadaULL
13#define HSS1394_MAX_PACKET_SIZE 64
14#define HSS1394_TAG_CHANGE_ADDRESS 0xf1
15
16struct fw_scs1x {
17 struct fw_address_handler hss_handler;
18};
19
20static void handle_hss(struct fw_card *card, struct fw_request *request,
21 int tcode, int destination, int source, int generation,
22 unsigned long long offset, void *data, size_t length,
23 void *callback_data)
24{
25 fw_send_response(card, request, RCODE_COMPLETE);
26}
27
28static int register_address(struct snd_oxfw *oxfw)
29{
30 struct fw_scs1x *scs = oxfw->spec;
31 __be64 data;
32
33 data = cpu_to_be64(((u64)HSS1394_TAG_CHANGE_ADDRESS << 56) |
34 scs->hss_handler.offset);
35 return snd_fw_transaction(oxfw->unit, TCODE_WRITE_BLOCK_REQUEST,
36 HSS1394_ADDRESS, &data, sizeof(data), 0);
37}
38
39static void remove_scs1x(struct snd_rawmidi *rmidi)
40{
41 struct fw_scs1x *scs = rmidi->private_data;
42
43 fw_core_remove_address_handler(&scs->hss_handler);
44}
45
46void snd_oxfw_scs1x_update(struct snd_oxfw *oxfw)
47{
48 register_address(oxfw);
49}
50
Takashi Sakamoto3f471522015-12-22 09:15:39 +090051int snd_oxfw_scs1x_add(struct snd_oxfw *oxfw)
52{
53 struct snd_rawmidi *rmidi;
Takashi Sakamotoe3315b42015-12-22 09:15:40 +090054 struct fw_scs1x *scs;
Takashi Sakamoto3f471522015-12-22 09:15:39 +090055 int err;
56
Takashi Sakamotoe3315b42015-12-22 09:15:40 +090057 scs = kzalloc(sizeof(struct fw_scs1x), GFP_KERNEL);
58 if (scs == NULL)
59 return -ENOMEM;
60 oxfw->spec = scs;
61
62 /* Allocate own handler for imcoming asynchronous transaction. */
63 scs->hss_handler.length = HSS1394_MAX_PACKET_SIZE;
64 scs->hss_handler.address_callback = handle_hss;
65 scs->hss_handler.callback_data = scs;
66 err = fw_core_add_address_handler(&scs->hss_handler,
67 &fw_high_memory_region);
68 if (err < 0)
69 return err;
70
71 err = register_address(oxfw);
72 if (err < 0)
73 goto err_allocated;
74
Takashi Sakamoto3f471522015-12-22 09:15:39 +090075 /* Use unique name for backward compatibility to scs1x module. */
76 err = snd_rawmidi_new(oxfw->card, "SCS.1x", 0, 0, 0, &rmidi);
77 if (err < 0)
Takashi Sakamotoe3315b42015-12-22 09:15:40 +090078 goto err_allocated;
79 rmidi->private_data = scs;
80 rmidi->private_free = remove_scs1x;
Takashi Sakamoto3f471522015-12-22 09:15:39 +090081
82 snprintf(rmidi->name, sizeof(rmidi->name),
83 "%s MIDI", oxfw->card->shortname);
84
Takashi Sakamotoe3315b42015-12-22 09:15:40 +090085 return 0;
86err_allocated:
87 fw_core_remove_address_handler(&scs->hss_handler);
Takashi Sakamoto3f471522015-12-22 09:15:39 +090088 return err;
89}