Ondrej Zary | 3491a88 | 2012-05-17 04:55:01 -0300 | [diff] [blame] | 1 | /* SF16-FMR2 and SF16-FMD2 radio driver for Linux |
Ondrej Zary | 9e8fa0e | 2011-06-01 16:57:11 -0300 | [diff] [blame] | 2 | * Copyright (c) 2011 Ondrej Zary |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3 | * |
Ondrej Zary | 9e8fa0e | 2011-06-01 16:57:11 -0300 | [diff] [blame] | 4 | * Original driver was (c) 2000-2002 Ziglio Frediano, freddy77@angelfire.com |
| 5 | * but almost nothing remained here after conversion to generic TEA575x |
| 6 | * implementation |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | */ |
| 8 | |
Ondrej Zary | 9e8fa0e | 2011-06-01 16:57:11 -0300 | [diff] [blame] | 9 | #include <linux/delay.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | #include <linux/module.h> /* Modules */ |
| 11 | #include <linux/init.h> /* Initdata */ |
Hans Verkuil | d4ecc83 | 2012-02-27 05:30:13 -0300 | [diff] [blame] | 12 | #include <linux/slab.h> |
Peter Osterlund | fb911ee | 2005-09-13 01:25:15 -0700 | [diff] [blame] | 13 | #include <linux/ioport.h> /* request_region */ |
Hans Verkuil | c32a9d7 | 2009-03-06 13:53:26 -0300 | [diff] [blame] | 14 | #include <linux/io.h> /* outb, outb_p */ |
Hans Verkuil | d4ecc83 | 2012-02-27 05:30:13 -0300 | [diff] [blame] | 15 | #include <linux/isa.h> |
Ondrej Zary | 3491a88 | 2012-05-17 04:55:01 -0300 | [diff] [blame] | 16 | #include <linux/pnp.h> |
Ondrej Zary | 9e8fa0e | 2011-06-01 16:57:11 -0300 | [diff] [blame] | 17 | #include <sound/tea575x-tuner.h> |
Hans Verkuil | c32a9d7 | 2009-03-06 13:53:26 -0300 | [diff] [blame] | 18 | |
Ondrej Zary | 9e8fa0e | 2011-06-01 16:57:11 -0300 | [diff] [blame] | 19 | MODULE_AUTHOR("Ondrej Zary"); |
Ondrej Zary | 3491a88 | 2012-05-17 04:55:01 -0300 | [diff] [blame] | 20 | MODULE_DESCRIPTION("MediaForte SF16-FMR2 and SF16-FMD2 FM radio card driver"); |
Hans Verkuil | c32a9d7 | 2009-03-06 13:53:26 -0300 | [diff] [blame] | 21 | MODULE_LICENSE("GPL"); |
| 22 | |
Ondrej Zary | 3491a88 | 2012-05-17 04:55:01 -0300 | [diff] [blame] | 23 | /* these cards can only use two different ports (0x384 and 0x284) */ |
| 24 | #define FMR2_MAX 2 |
| 25 | |
| 26 | static int radio_nr[FMR2_MAX] = { [0 ... (FMR2_MAX - 1)] = -1 }; |
| 27 | module_param_array(radio_nr, int, NULL, 0444); |
| 28 | MODULE_PARM_DESC(radio_nr, "Radio device numbers"); |
Hans Verkuil | d4ecc83 | 2012-02-27 05:30:13 -0300 | [diff] [blame] | 29 | |
Ondrej Zary | 9e8fa0e | 2011-06-01 16:57:11 -0300 | [diff] [blame] | 30 | struct fmr2 { |
Hans Verkuil | c32a9d7 | 2009-03-06 13:53:26 -0300 | [diff] [blame] | 31 | int io; |
Hans Verkuil | d4ecc83 | 2012-02-27 05:30:13 -0300 | [diff] [blame] | 32 | struct v4l2_device v4l2_dev; |
Ondrej Zary | 9e8fa0e | 2011-06-01 16:57:11 -0300 | [diff] [blame] | 33 | struct snd_tea575x tea; |
| 34 | struct v4l2_ctrl *volume; |
| 35 | struct v4l2_ctrl *balance; |
Ondrej Zary | 3491a88 | 2012-05-17 04:55:01 -0300 | [diff] [blame] | 36 | bool is_fmd2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | }; |
| 38 | |
Ondrej Zary | 3491a88 | 2012-05-17 04:55:01 -0300 | [diff] [blame] | 39 | static int num_fmr2_cards; |
| 40 | static struct fmr2 *fmr2_cards[FMR2_MAX]; |
| 41 | static bool isa_registered; |
| 42 | static bool pnp_registered; |
| 43 | |
| 44 | /* the port is hardwired on SF16-FMR2 */ |
Ondrej Zary | 9e8fa0e | 2011-06-01 16:57:11 -0300 | [diff] [blame] | 45 | #define FMR2_PORT 0x384 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | |
Ondrej Zary | 9e8fa0e | 2011-06-01 16:57:11 -0300 | [diff] [blame] | 47 | /* TEA575x tuner pins */ |
| 48 | #define STR_DATA (1 << 0) |
| 49 | #define STR_CLK (1 << 1) |
| 50 | #define STR_WREN (1 << 2) |
| 51 | #define STR_MOST (1 << 3) |
| 52 | /* PT2254A/TC9154A volume control pins */ |
| 53 | #define PT_ST (1 << 4) |
| 54 | #define PT_CK (1 << 5) |
| 55 | #define PT_DATA (1 << 6) |
| 56 | /* volume control presence pin */ |
| 57 | #define FMR2_HASVOL (1 << 7) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | |
Ondrej Zary | 9e8fa0e | 2011-06-01 16:57:11 -0300 | [diff] [blame] | 59 | static void fmr2_tea575x_set_pins(struct snd_tea575x *tea, u8 pins) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | { |
Ondrej Zary | 9e8fa0e | 2011-06-01 16:57:11 -0300 | [diff] [blame] | 61 | struct fmr2 *fmr2 = tea->private_data; |
| 62 | u8 bits = 0; |
| 63 | |
| 64 | bits |= (pins & TEA575X_DATA) ? STR_DATA : 0; |
| 65 | bits |= (pins & TEA575X_CLK) ? STR_CLK : 0; |
| 66 | /* WRITE_ENABLE is inverted, DATA must be high during read */ |
| 67 | bits |= (pins & TEA575X_WREN) ? 0 : STR_WREN | STR_DATA; |
| 68 | |
| 69 | outb(bits, fmr2->io); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | } |
| 71 | |
Ondrej Zary | 9e8fa0e | 2011-06-01 16:57:11 -0300 | [diff] [blame] | 72 | static u8 fmr2_tea575x_get_pins(struct snd_tea575x *tea) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | { |
Ondrej Zary | 9e8fa0e | 2011-06-01 16:57:11 -0300 | [diff] [blame] | 74 | struct fmr2 *fmr2 = tea->private_data; |
| 75 | u8 bits = inb(fmr2->io); |
Hans Verkuil | c32a9d7 | 2009-03-06 13:53:26 -0300 | [diff] [blame] | 76 | |
Ondrej Zary | 9e8fa0e | 2011-06-01 16:57:11 -0300 | [diff] [blame] | 77 | return (bits & STR_DATA) ? TEA575X_DATA : 0 | |
| 78 | (bits & STR_MOST) ? TEA575X_MOST : 0; |
| 79 | } |
| 80 | |
| 81 | static void fmr2_tea575x_set_direction(struct snd_tea575x *tea, bool output) |
| 82 | { |
| 83 | } |
| 84 | |
| 85 | static struct snd_tea575x_ops fmr2_tea_ops = { |
| 86 | .set_pins = fmr2_tea575x_set_pins, |
| 87 | .get_pins = fmr2_tea575x_get_pins, |
| 88 | .set_direction = fmr2_tea575x_set_direction, |
| 89 | }; |
| 90 | |
| 91 | /* TC9154A/PT2254A volume control */ |
| 92 | |
| 93 | /* 18-bit shift register bit definitions */ |
| 94 | #define TC9154A_ATT_MAJ_0DB (1 << 0) |
| 95 | #define TC9154A_ATT_MAJ_10DB (1 << 1) |
| 96 | #define TC9154A_ATT_MAJ_20DB (1 << 2) |
| 97 | #define TC9154A_ATT_MAJ_30DB (1 << 3) |
| 98 | #define TC9154A_ATT_MAJ_40DB (1 << 4) |
| 99 | #define TC9154A_ATT_MAJ_50DB (1 << 5) |
| 100 | #define TC9154A_ATT_MAJ_60DB (1 << 6) |
| 101 | |
| 102 | #define TC9154A_ATT_MIN_0DB (1 << 7) |
| 103 | #define TC9154A_ATT_MIN_2DB (1 << 8) |
| 104 | #define TC9154A_ATT_MIN_4DB (1 << 9) |
| 105 | #define TC9154A_ATT_MIN_6DB (1 << 10) |
| 106 | #define TC9154A_ATT_MIN_8DB (1 << 11) |
| 107 | /* bit 12 is ignored */ |
| 108 | #define TC9154A_CHANNEL_LEFT (1 << 13) |
| 109 | #define TC9154A_CHANNEL_RIGHT (1 << 14) |
| 110 | /* bits 15, 16, 17 must be 0 */ |
| 111 | |
| 112 | #define TC9154A_ATT_MAJ(x) (1 << x) |
| 113 | #define TC9154A_ATT_MIN(x) (1 << (7 + x)) |
| 114 | |
| 115 | static void tc9154a_set_pins(struct fmr2 *fmr2, u8 pins) |
| 116 | { |
| 117 | if (!fmr2->tea.mute) |
| 118 | pins |= STR_WREN; |
| 119 | |
| 120 | outb(pins, fmr2->io); |
| 121 | } |
| 122 | |
| 123 | static void tc9154a_set_attenuation(struct fmr2 *fmr2, int att, u32 channel) |
| 124 | { |
| 125 | int i; |
| 126 | u32 reg; |
| 127 | u8 bit; |
| 128 | |
| 129 | reg = TC9154A_ATT_MAJ(att / 10) | TC9154A_ATT_MIN((att % 10) / 2); |
| 130 | reg |= channel; |
| 131 | /* write 18-bit shift register, LSB first */ |
| 132 | for (i = 0; i < 18; i++) { |
| 133 | bit = reg & (1 << i) ? PT_DATA : 0; |
| 134 | tc9154a_set_pins(fmr2, bit); |
| 135 | udelay(5); |
| 136 | tc9154a_set_pins(fmr2, bit | PT_CK); |
| 137 | udelay(5); |
| 138 | tc9154a_set_pins(fmr2, bit); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 139 | } |
Ondrej Zary | 9e8fa0e | 2011-06-01 16:57:11 -0300 | [diff] [blame] | 140 | |
| 141 | /* latch register data */ |
| 142 | udelay(5); |
| 143 | tc9154a_set_pins(fmr2, PT_ST); |
| 144 | udelay(5); |
| 145 | tc9154a_set_pins(fmr2, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 146 | } |
| 147 | |
Ondrej Zary | 9e8fa0e | 2011-06-01 16:57:11 -0300 | [diff] [blame] | 148 | static int fmr2_s_ctrl(struct v4l2_ctrl *ctrl) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 149 | { |
Ondrej Zary | 9e8fa0e | 2011-06-01 16:57:11 -0300 | [diff] [blame] | 150 | struct snd_tea575x *tea = container_of(ctrl->handler, struct snd_tea575x, ctrl_handler); |
| 151 | struct fmr2 *fmr2 = tea->private_data; |
| 152 | int volume, balance, left, right; |
Douglas Landgraf | 34ab962 | 2007-04-23 17:51:37 -0300 | [diff] [blame] | 153 | |
| 154 | switch (ctrl->id) { |
Douglas Landgraf | 34ab962 | 2007-04-23 17:51:37 -0300 | [diff] [blame] | 155 | case V4L2_CID_AUDIO_VOLUME: |
Ondrej Zary | 9e8fa0e | 2011-06-01 16:57:11 -0300 | [diff] [blame] | 156 | volume = ctrl->val; |
| 157 | balance = fmr2->balance->cur.val; |
Douglas Landgraf | 34ab962 | 2007-04-23 17:51:37 -0300 | [diff] [blame] | 158 | break; |
Ondrej Zary | 9e8fa0e | 2011-06-01 16:57:11 -0300 | [diff] [blame] | 159 | case V4L2_CID_AUDIO_BALANCE: |
| 160 | balance = ctrl->val; |
| 161 | volume = fmr2->volume->cur.val; |
Douglas Landgraf | 34ab962 | 2007-04-23 17:51:37 -0300 | [diff] [blame] | 162 | break; |
| 163 | default: |
| 164 | return -EINVAL; |
| 165 | } |
| 166 | |
Ondrej Zary | 9e8fa0e | 2011-06-01 16:57:11 -0300 | [diff] [blame] | 167 | left = right = volume; |
| 168 | if (balance < 0) |
| 169 | right = max(0, right + balance); |
| 170 | if (balance > 0) |
| 171 | left = max(0, left - balance); |
Douglas Landgraf | 34ab962 | 2007-04-23 17:51:37 -0300 | [diff] [blame] | 172 | |
Ondrej Zary | 9e8fa0e | 2011-06-01 16:57:11 -0300 | [diff] [blame] | 173 | tc9154a_set_attenuation(fmr2, abs(left - 68), TC9154A_CHANNEL_LEFT); |
| 174 | tc9154a_set_attenuation(fmr2, abs(right - 68), TC9154A_CHANNEL_RIGHT); |
| 175 | |
Douglas Landgraf | 34ab962 | 2007-04-23 17:51:37 -0300 | [diff] [blame] | 176 | return 0; |
| 177 | } |
| 178 | |
Ondrej Zary | 9e8fa0e | 2011-06-01 16:57:11 -0300 | [diff] [blame] | 179 | static const struct v4l2_ctrl_ops fmr2_ctrl_ops = { |
| 180 | .s_ctrl = fmr2_s_ctrl, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 181 | }; |
| 182 | |
Ondrej Zary | 9e8fa0e | 2011-06-01 16:57:11 -0300 | [diff] [blame] | 183 | static int fmr2_tea_ext_init(struct snd_tea575x *tea) |
| 184 | { |
| 185 | struct fmr2 *fmr2 = tea->private_data; |
| 186 | |
Ondrej Zary | 3491a88 | 2012-05-17 04:55:01 -0300 | [diff] [blame] | 187 | /* FMR2 can have volume control, FMD2 can't (uses SB16 mixer) */ |
| 188 | if (!fmr2->is_fmd2 && inb(fmr2->io) & FMR2_HASVOL) { |
Ondrej Zary | 9e8fa0e | 2011-06-01 16:57:11 -0300 | [diff] [blame] | 189 | fmr2->volume = v4l2_ctrl_new_std(&tea->ctrl_handler, &fmr2_ctrl_ops, V4L2_CID_AUDIO_VOLUME, 0, 68, 2, 56); |
| 190 | fmr2->balance = v4l2_ctrl_new_std(&tea->ctrl_handler, &fmr2_ctrl_ops, V4L2_CID_AUDIO_BALANCE, -68, 68, 2, 0); |
| 191 | if (tea->ctrl_handler.error) { |
Masanari Iida | bdb2c41 | 2012-02-14 10:06:09 -0300 | [diff] [blame] | 192 | printk(KERN_ERR "radio-sf16fmr2: can't initialize controls\n"); |
Ondrej Zary | 9e8fa0e | 2011-06-01 16:57:11 -0300 | [diff] [blame] | 193 | return tea->ctrl_handler.error; |
| 194 | } |
| 195 | } |
| 196 | |
| 197 | return 0; |
| 198 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 199 | |
Greg Kroah-Hartman | 4c62e97 | 2012-12-21 13:17:53 -0800 | [diff] [blame] | 200 | static struct pnp_device_id fmr2_pnp_ids[] = { |
Ondrej Zary | 3491a88 | 2012-05-17 04:55:01 -0300 | [diff] [blame] | 201 | { .id = "MFRad13" }, /* tuner subdevice of SF16-FMD2 */ |
| 202 | { .id = "" } |
| 203 | }; |
| 204 | MODULE_DEVICE_TABLE(pnp, fmr2_pnp_ids); |
| 205 | |
Greg Kroah-Hartman | 4c62e97 | 2012-12-21 13:17:53 -0800 | [diff] [blame] | 206 | static int fmr2_probe(struct fmr2 *fmr2, struct device *pdev, int io) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 207 | { |
Ondrej Zary | 3491a88 | 2012-05-17 04:55:01 -0300 | [diff] [blame] | 208 | int err, i; |
| 209 | char *card_name = fmr2->is_fmd2 ? "SF16-FMD2" : "SF16-FMR2"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 210 | |
Ondrej Zary | 3491a88 | 2012-05-17 04:55:01 -0300 | [diff] [blame] | 211 | /* avoid errors if a card was already registered at given port */ |
| 212 | for (i = 0; i < num_fmr2_cards; i++) |
| 213 | if (io == fmr2_cards[i]->io) |
| 214 | return -EBUSY; |
Hans Verkuil | d4ecc83 | 2012-02-27 05:30:13 -0300 | [diff] [blame] | 215 | |
Ondrej Zary | 3491a88 | 2012-05-17 04:55:01 -0300 | [diff] [blame] | 216 | strlcpy(fmr2->v4l2_dev.name, "radio-sf16fmr2", |
| 217 | sizeof(fmr2->v4l2_dev.name)), |
| 218 | fmr2->io = io; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 219 | |
Hans Verkuil | d4ecc83 | 2012-02-27 05:30:13 -0300 | [diff] [blame] | 220 | if (!request_region(fmr2->io, 2, fmr2->v4l2_dev.name)) { |
Ondrej Zary | 9e8fa0e | 2011-06-01 16:57:11 -0300 | [diff] [blame] | 221 | printk(KERN_ERR "radio-sf16fmr2: I/O port 0x%x already in use\n", fmr2->io); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 222 | return -EBUSY; |
| 223 | } |
| 224 | |
Hans Verkuil | d4ecc83 | 2012-02-27 05:30:13 -0300 | [diff] [blame] | 225 | dev_set_drvdata(pdev, fmr2); |
| 226 | err = v4l2_device_register(pdev, &fmr2->v4l2_dev); |
| 227 | if (err < 0) { |
| 228 | v4l2_err(&fmr2->v4l2_dev, "Could not register v4l2_device\n"); |
| 229 | release_region(fmr2->io, 2); |
Hans Verkuil | d4ecc83 | 2012-02-27 05:30:13 -0300 | [diff] [blame] | 230 | return err; |
| 231 | } |
| 232 | fmr2->tea.v4l2_dev = &fmr2->v4l2_dev; |
Ondrej Zary | 9e8fa0e | 2011-06-01 16:57:11 -0300 | [diff] [blame] | 233 | fmr2->tea.private_data = fmr2; |
Ondrej Zary | 3491a88 | 2012-05-17 04:55:01 -0300 | [diff] [blame] | 234 | fmr2->tea.radio_nr = radio_nr[num_fmr2_cards]; |
Ondrej Zary | 9e8fa0e | 2011-06-01 16:57:11 -0300 | [diff] [blame] | 235 | fmr2->tea.ops = &fmr2_tea_ops; |
| 236 | fmr2->tea.ext_init = fmr2_tea_ext_init; |
Ondrej Zary | 3491a88 | 2012-05-17 04:55:01 -0300 | [diff] [blame] | 237 | strlcpy(fmr2->tea.card, card_name, sizeof(fmr2->tea.card)); |
| 238 | snprintf(fmr2->tea.bus_info, sizeof(fmr2->tea.bus_info), "%s:%s", |
| 239 | fmr2->is_fmd2 ? "PnP" : "ISA", dev_name(pdev)); |
Ondrej Zary | 9e8fa0e | 2011-06-01 16:57:11 -0300 | [diff] [blame] | 240 | |
Hans de Goede | 5daf53a | 2012-05-19 07:57:03 -0300 | [diff] [blame] | 241 | if (snd_tea575x_init(&fmr2->tea, THIS_MODULE)) { |
Ondrej Zary | 9e8fa0e | 2011-06-01 16:57:11 -0300 | [diff] [blame] | 242 | printk(KERN_ERR "radio-sf16fmr2: Unable to detect TEA575x tuner\n"); |
Hans Verkuil | c32a9d7 | 2009-03-06 13:53:26 -0300 | [diff] [blame] | 243 | release_region(fmr2->io, 2); |
Ondrej Zary | 9e8fa0e | 2011-06-01 16:57:11 -0300 | [diff] [blame] | 244 | return -ENODEV; |
Hans Verkuil | c32a9d7 | 2009-03-06 13:53:26 -0300 | [diff] [blame] | 245 | } |
| 246 | |
Ondrej Zary | 3491a88 | 2012-05-17 04:55:01 -0300 | [diff] [blame] | 247 | printk(KERN_INFO "radio-sf16fmr2: %s radio card at 0x%x.\n", |
| 248 | card_name, fmr2->io); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 249 | return 0; |
| 250 | } |
| 251 | |
Greg Kroah-Hartman | 4c62e97 | 2012-12-21 13:17:53 -0800 | [diff] [blame] | 252 | static int fmr2_isa_match(struct device *pdev, unsigned int ndev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 253 | { |
Ondrej Zary | 3491a88 | 2012-05-17 04:55:01 -0300 | [diff] [blame] | 254 | struct fmr2 *fmr2 = kzalloc(sizeof(*fmr2), GFP_KERNEL); |
| 255 | if (!fmr2) |
| 256 | return 0; |
Hans Verkuil | c32a9d7 | 2009-03-06 13:53:26 -0300 | [diff] [blame] | 257 | |
Ondrej Zary | 3491a88 | 2012-05-17 04:55:01 -0300 | [diff] [blame] | 258 | if (fmr2_probe(fmr2, pdev, FMR2_PORT)) { |
| 259 | kfree(fmr2); |
| 260 | return 0; |
| 261 | } |
| 262 | dev_set_drvdata(pdev, fmr2); |
| 263 | fmr2_cards[num_fmr2_cards++] = fmr2; |
| 264 | |
| 265 | return 1; |
| 266 | } |
| 267 | |
Greg Kroah-Hartman | 4c62e97 | 2012-12-21 13:17:53 -0800 | [diff] [blame] | 268 | static int fmr2_pnp_probe(struct pnp_dev *pdev, const struct pnp_device_id *id) |
Ondrej Zary | 3491a88 | 2012-05-17 04:55:01 -0300 | [diff] [blame] | 269 | { |
| 270 | int ret; |
| 271 | struct fmr2 *fmr2 = kzalloc(sizeof(*fmr2), GFP_KERNEL); |
| 272 | if (!fmr2) |
| 273 | return -ENOMEM; |
| 274 | |
| 275 | fmr2->is_fmd2 = true; |
| 276 | ret = fmr2_probe(fmr2, &pdev->dev, pnp_port_start(pdev, 0)); |
| 277 | if (ret) { |
| 278 | kfree(fmr2); |
| 279 | return ret; |
| 280 | } |
| 281 | pnp_set_drvdata(pdev, fmr2); |
| 282 | fmr2_cards[num_fmr2_cards++] = fmr2; |
| 283 | |
| 284 | return 0; |
| 285 | } |
| 286 | |
Greg Kroah-Hartman | 4c62e97 | 2012-12-21 13:17:53 -0800 | [diff] [blame] | 287 | static void fmr2_remove(struct fmr2 *fmr2) |
Ondrej Zary | 3491a88 | 2012-05-17 04:55:01 -0300 | [diff] [blame] | 288 | { |
Ondrej Zary | 9e8fa0e | 2011-06-01 16:57:11 -0300 | [diff] [blame] | 289 | snd_tea575x_exit(&fmr2->tea); |
Hans Verkuil | c32a9d7 | 2009-03-06 13:53:26 -0300 | [diff] [blame] | 290 | release_region(fmr2->io, 2); |
Hans Verkuil | d4ecc83 | 2012-02-27 05:30:13 -0300 | [diff] [blame] | 291 | v4l2_device_unregister(&fmr2->v4l2_dev); |
| 292 | kfree(fmr2); |
Ondrej Zary | 3491a88 | 2012-05-17 04:55:01 -0300 | [diff] [blame] | 293 | } |
| 294 | |
Greg Kroah-Hartman | 4c62e97 | 2012-12-21 13:17:53 -0800 | [diff] [blame] | 295 | static int fmr2_isa_remove(struct device *pdev, unsigned int ndev) |
Ondrej Zary | 3491a88 | 2012-05-17 04:55:01 -0300 | [diff] [blame] | 296 | { |
| 297 | fmr2_remove(dev_get_drvdata(pdev)); |
| 298 | dev_set_drvdata(pdev, NULL); |
| 299 | |
Hans Verkuil | d4ecc83 | 2012-02-27 05:30:13 -0300 | [diff] [blame] | 300 | return 0; |
| 301 | } |
| 302 | |
Greg Kroah-Hartman | 4c62e97 | 2012-12-21 13:17:53 -0800 | [diff] [blame] | 303 | static void fmr2_pnp_remove(struct pnp_dev *pdev) |
Ondrej Zary | 3491a88 | 2012-05-17 04:55:01 -0300 | [diff] [blame] | 304 | { |
| 305 | fmr2_remove(pnp_get_drvdata(pdev)); |
| 306 | pnp_set_drvdata(pdev, NULL); |
| 307 | } |
| 308 | |
| 309 | struct isa_driver fmr2_isa_driver = { |
| 310 | .match = fmr2_isa_match, |
Greg Kroah-Hartman | 4c62e97 | 2012-12-21 13:17:53 -0800 | [diff] [blame] | 311 | .remove = fmr2_isa_remove, |
Hans Verkuil | d4ecc83 | 2012-02-27 05:30:13 -0300 | [diff] [blame] | 312 | .driver = { |
| 313 | .name = "radio-sf16fmr2", |
| 314 | }, |
| 315 | }; |
| 316 | |
Ondrej Zary | 3491a88 | 2012-05-17 04:55:01 -0300 | [diff] [blame] | 317 | struct pnp_driver fmr2_pnp_driver = { |
| 318 | .name = "radio-sf16fmr2", |
| 319 | .id_table = fmr2_pnp_ids, |
| 320 | .probe = fmr2_pnp_probe, |
Greg Kroah-Hartman | 4c62e97 | 2012-12-21 13:17:53 -0800 | [diff] [blame] | 321 | .remove = fmr2_pnp_remove, |
Ondrej Zary | 3491a88 | 2012-05-17 04:55:01 -0300 | [diff] [blame] | 322 | }; |
| 323 | |
Hans Verkuil | d4ecc83 | 2012-02-27 05:30:13 -0300 | [diff] [blame] | 324 | static int __init fmr2_init(void) |
| 325 | { |
Ondrej Zary | 3491a88 | 2012-05-17 04:55:01 -0300 | [diff] [blame] | 326 | int ret; |
| 327 | |
| 328 | ret = pnp_register_driver(&fmr2_pnp_driver); |
| 329 | if (!ret) |
| 330 | pnp_registered = true; |
| 331 | ret = isa_register_driver(&fmr2_isa_driver, 1); |
| 332 | if (!ret) |
| 333 | isa_registered = true; |
| 334 | |
| 335 | return (pnp_registered || isa_registered) ? 0 : ret; |
Hans Verkuil | d4ecc83 | 2012-02-27 05:30:13 -0300 | [diff] [blame] | 336 | } |
| 337 | |
| 338 | static void __exit fmr2_exit(void) |
| 339 | { |
Ondrej Zary | 3491a88 | 2012-05-17 04:55:01 -0300 | [diff] [blame] | 340 | if (pnp_registered) |
| 341 | pnp_unregister_driver(&fmr2_pnp_driver); |
| 342 | if (isa_registered) |
| 343 | isa_unregister_driver(&fmr2_isa_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 344 | } |
| 345 | |
| 346 | module_init(fmr2_init); |
Hans Verkuil | c32a9d7 | 2009-03-06 13:53:26 -0300 | [diff] [blame] | 347 | module_exit(fmr2_exit); |