Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 1 | /* |
| 2 | * Driver for the Auvitek USB bridge |
| 3 | * |
Steven Toth | 6d89761 | 2008-09-03 17:12:12 -0300 | [diff] [blame] | 4 | * Copyright (c) 2008 Steven Toth <stoth@linuxtv.org> |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; either version 2 of the License, or |
| 9 | * (at your option) any later version. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * |
| 15 | * GNU General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License |
| 18 | * along with this program; if not, write to the Free Software |
| 19 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 20 | */ |
| 21 | |
Mauro Carvalho Chehab | 83afb32 | 2014-08-09 21:47:17 -0300 | [diff] [blame] | 22 | #include "au0828.h" |
Shuah Khan | f90c5d7 | 2016-02-11 21:41:34 -0200 | [diff] [blame] | 23 | #include "au8522.h" |
Mauro Carvalho Chehab | 83afb32 | 2014-08-09 21:47:17 -0300 | [diff] [blame] | 24 | |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 25 | #include <linux/module.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 26 | #include <linux/slab.h> |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 27 | #include <linux/videodev2.h> |
| 28 | #include <media/v4l2-common.h> |
| 29 | #include <linux/mutex.h> |
| 30 | |
Mauro Carvalho Chehab | 188d2d5 | 2015-08-31 13:23:03 -0300 | [diff] [blame] | 31 | /* Due to enum tuner_pad_index */ |
| 32 | #include <media/tuner.h> |
| 33 | |
Steven Toth | bc3c613 | 2008-04-18 21:39:11 -0300 | [diff] [blame] | 34 | /* |
| 35 | * 1 = General debug messages |
| 36 | * 2 = USB handling |
| 37 | * 4 = I2C related |
| 38 | * 8 = Bridge related |
Mauro Carvalho Chehab | 2fcfd31 | 2014-07-24 22:49:02 -0300 | [diff] [blame] | 39 | * 16 = IR related |
Steven Toth | bc3c613 | 2008-04-18 21:39:11 -0300 | [diff] [blame] | 40 | */ |
Adrian Bunk | b33d24c | 2008-04-25 19:06:03 -0300 | [diff] [blame] | 41 | int au0828_debug; |
| 42 | module_param_named(debug, au0828_debug, int, 0644); |
Mauro Carvalho Chehab | 2fcfd31 | 2014-07-24 22:49:02 -0300 | [diff] [blame] | 43 | MODULE_PARM_DESC(debug, |
| 44 | "set debug bitmask: 1=general, 2=USB, 4=I2C, 8=bridge, 16=IR"); |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 45 | |
Devin Heitmueller | d6a9a43 | 2009-05-27 23:46:17 -0300 | [diff] [blame] | 46 | static unsigned int disable_usb_speed_check; |
| 47 | module_param(disable_usb_speed_check, int, 0444); |
| 48 | MODULE_PARM_DESC(disable_usb_speed_check, |
| 49 | "override min bandwidth requirement of 480M bps"); |
| 50 | |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 51 | #define _AU0828_BULKPIPE 0x03 |
| 52 | #define _BULKPIPESIZE 0xffff |
| 53 | |
| 54 | static int send_control_msg(struct au0828_dev *dev, u16 request, u32 value, |
Devin Heitmueller | 8ff63de | 2012-08-06 22:47:05 -0300 | [diff] [blame] | 55 | u16 index); |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 56 | static int recv_control_msg(struct au0828_dev *dev, u16 request, u32 value, |
| 57 | u16 index, unsigned char *cp, u16 size); |
| 58 | |
| 59 | /* USB Direction */ |
| 60 | #define CMD_REQUEST_IN 0x00 |
| 61 | #define CMD_REQUEST_OUT 0x01 |
| 62 | |
| 63 | u32 au0828_readreg(struct au0828_dev *dev, u16 reg) |
| 64 | { |
Devin Heitmueller | 77fc286 | 2012-08-06 22:47:07 -0300 | [diff] [blame] | 65 | u8 result = 0; |
| 66 | |
| 67 | recv_control_msg(dev, CMD_REQUEST_IN, 0, reg, &result, 1); |
| 68 | dprintk(8, "%s(0x%04x) = 0x%02x\n", __func__, reg, result); |
| 69 | |
| 70 | return result; |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 71 | } |
| 72 | |
| 73 | u32 au0828_writereg(struct au0828_dev *dev, u16 reg, u32 val) |
| 74 | { |
Devin Heitmueller | b80f770 | 2009-03-11 03:00:57 -0300 | [diff] [blame] | 75 | dprintk(8, "%s(0x%04x, 0x%02x)\n", __func__, reg, val); |
Devin Heitmueller | 8ff63de | 2012-08-06 22:47:05 -0300 | [diff] [blame] | 76 | return send_control_msg(dev, CMD_REQUEST_OUT, val, reg); |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 77 | } |
| 78 | |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 79 | static int send_control_msg(struct au0828_dev *dev, u16 request, u32 value, |
Devin Heitmueller | 8ff63de | 2012-08-06 22:47:05 -0300 | [diff] [blame] | 80 | u16 index) |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 81 | { |
| 82 | int status = -ENODEV; |
Devin Heitmueller | 8ff63de | 2012-08-06 22:47:05 -0300 | [diff] [blame] | 83 | |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 84 | if (dev->usbdev) { |
| 85 | |
| 86 | /* cp must be memory that has been allocated by kmalloc */ |
| 87 | status = usb_control_msg(dev->usbdev, |
| 88 | usb_sndctrlpipe(dev->usbdev, 0), |
| 89 | request, |
Steven Toth | a8eb912 | 2008-10-16 20:19:41 -0300 | [diff] [blame] | 90 | USB_DIR_OUT | USB_TYPE_VENDOR | |
| 91 | USB_RECIP_DEVICE, |
Devin Heitmueller | 8ff63de | 2012-08-06 22:47:05 -0300 | [diff] [blame] | 92 | value, index, NULL, 0, 1000); |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 93 | |
| 94 | status = min(status, 0); |
| 95 | |
| 96 | if (status < 0) { |
Mauro Carvalho Chehab | 83afb32 | 2014-08-09 21:47:17 -0300 | [diff] [blame] | 97 | pr_err("%s() Failed sending control message, error %d.\n", |
Michael Krufky | f07e8e4 | 2008-04-18 21:42:30 -0300 | [diff] [blame] | 98 | __func__, status); |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 99 | } |
| 100 | |
| 101 | } |
Devin Heitmueller | 8ff63de | 2012-08-06 22:47:05 -0300 | [diff] [blame] | 102 | |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 103 | return status; |
| 104 | } |
| 105 | |
| 106 | static int recv_control_msg(struct au0828_dev *dev, u16 request, u32 value, |
| 107 | u16 index, unsigned char *cp, u16 size) |
| 108 | { |
| 109 | int status = -ENODEV; |
| 110 | mutex_lock(&dev->mutex); |
| 111 | if (dev->usbdev) { |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 112 | status = usb_control_msg(dev->usbdev, |
| 113 | usb_rcvctrlpipe(dev->usbdev, 0), |
| 114 | request, |
| 115 | USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE, |
| 116 | value, index, |
Devin Heitmueller | 77fc286 | 2012-08-06 22:47:07 -0300 | [diff] [blame] | 117 | dev->ctrlmsg, size, 1000); |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 118 | |
| 119 | status = min(status, 0); |
| 120 | |
| 121 | if (status < 0) { |
Mauro Carvalho Chehab | 83afb32 | 2014-08-09 21:47:17 -0300 | [diff] [blame] | 122 | pr_err("%s() Failed receiving control message, error %d.\n", |
Michael Krufky | f07e8e4 | 2008-04-18 21:42:30 -0300 | [diff] [blame] | 123 | __func__, status); |
Devin Heitmueller | 77fc286 | 2012-08-06 22:47:07 -0300 | [diff] [blame] | 124 | } |
| 125 | |
| 126 | /* the host controller requires heap allocated memory, which |
| 127 | is why we didn't just pass "cp" into usb_control_msg */ |
| 128 | memcpy(cp, dev->ctrlmsg, size); |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 129 | } |
| 130 | mutex_unlock(&dev->mutex); |
| 131 | return status; |
| 132 | } |
Steven Toth | a9c36aa | 2008-04-17 21:41:28 -0300 | [diff] [blame] | 133 | |
Mauro Carvalho Chehab | bc5ccdb | 2016-03-16 05:04:04 -0700 | [diff] [blame] | 134 | #ifdef CONFIG_MEDIA_CONTROLLER |
| 135 | static void au0828_media_graph_notify(struct media_entity *new, |
| 136 | void *notify_data); |
| 137 | #endif |
| 138 | |
Rafael Lourenço de Lima Chehab | bed6919 | 2015-06-08 22:20:46 -0300 | [diff] [blame] | 139 | static void au0828_unregister_media_device(struct au0828_dev *dev) |
| 140 | { |
Rafael Lourenço de Lima Chehab | bed6919 | 2015-06-08 22:20:46 -0300 | [diff] [blame] | 141 | #ifdef CONFIG_MEDIA_CONTROLLER |
Mauro Carvalho Chehab | bc5ccdb | 2016-03-16 05:04:04 -0700 | [diff] [blame] | 142 | struct media_device *mdev = dev->media_dev; |
| 143 | struct media_entity_notify *notify, *nextp; |
Shuah Khan | ffa8576 | 2016-03-13 00:57:40 -0300 | [diff] [blame] | 144 | |
Mauro Carvalho Chehab | a087ce7 | 2016-04-27 19:28:26 -0300 | [diff] [blame] | 145 | if (!mdev || !media_devnode_is_registered(mdev->devnode)) |
Mauro Carvalho Chehab | bc5ccdb | 2016-03-16 05:04:04 -0700 | [diff] [blame] | 146 | return; |
| 147 | |
| 148 | /* Remove au0828 entity_notify callbacks */ |
| 149 | list_for_each_entry_safe(notify, nextp, &mdev->entity_notify, list) { |
| 150 | if (notify->notify != au0828_media_graph_notify) |
| 151 | continue; |
| 152 | media_device_unregister_entity_notify(mdev, notify); |
Rafael Lourenço de Lima Chehab | bed6919 | 2015-06-08 22:20:46 -0300 | [diff] [blame] | 153 | } |
Mauro Carvalho Chehab | bc5ccdb | 2016-03-16 05:04:04 -0700 | [diff] [blame] | 154 | |
| 155 | /* clear enable_source, disable_source */ |
| 156 | dev->media_dev->source_priv = NULL; |
| 157 | dev->media_dev->enable_source = NULL; |
| 158 | dev->media_dev->disable_source = NULL; |
| 159 | |
| 160 | media_device_unregister(dev->media_dev); |
| 161 | media_device_cleanup(dev->media_dev); |
| 162 | kfree(dev->media_dev); |
| 163 | dev->media_dev = NULL; |
Rafael Lourenço de Lima Chehab | bed6919 | 2015-06-08 22:20:46 -0300 | [diff] [blame] | 164 | #endif |
| 165 | } |
| 166 | |
Mauro Carvalho Chehab | 7b606ff | 2016-02-09 15:53:39 -0200 | [diff] [blame] | 167 | void au0828_usb_release(struct au0828_dev *dev) |
Hans Verkuil | 823beb7 | 2013-03-11 10:16:45 -0300 | [diff] [blame] | 168 | { |
Rafael Lourenço de Lima Chehab | bed6919 | 2015-06-08 22:20:46 -0300 | [diff] [blame] | 169 | au0828_unregister_media_device(dev); |
| 170 | |
Hans Verkuil | 823beb7 | 2013-03-11 10:16:45 -0300 | [diff] [blame] | 171 | /* I2C */ |
| 172 | au0828_i2c_unregister(dev); |
| 173 | |
| 174 | kfree(dev); |
| 175 | } |
| 176 | |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 177 | static void au0828_usb_disconnect(struct usb_interface *interface) |
| 178 | { |
| 179 | struct au0828_dev *dev = usb_get_intfdata(interface); |
| 180 | |
Michael Krufky | f07e8e4 | 2008-04-18 21:42:30 -0300 | [diff] [blame] | 181 | dprintk(1, "%s()\n", __func__); |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 182 | |
Shuah Khan | eb336ea | 2014-11-21 21:17:08 -0300 | [diff] [blame] | 183 | /* there is a small window after disconnect, before |
| 184 | dev->usbdev is NULL, for poll (e.g: IR) try to access |
| 185 | the device and fill the dmesg with error messages. |
| 186 | Set the status so poll routines can check and avoid |
| 187 | access after disconnect. |
| 188 | */ |
Mauro Carvalho Chehab | e8e3039 | 2016-03-22 09:21:57 -0300 | [diff] [blame] | 189 | set_bit(DEV_DISCONNECTED, &dev->dev_state); |
Shuah Khan | eb336ea | 2014-11-21 21:17:08 -0300 | [diff] [blame] | 190 | |
Mauro Carvalho Chehab | 2fcfd31 | 2014-07-24 22:49:02 -0300 | [diff] [blame] | 191 | au0828_rc_unregister(dev); |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 192 | /* Digital TV */ |
| 193 | au0828_dvb_unregister(dev); |
| 194 | |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 195 | usb_set_intfdata(interface, NULL); |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 196 | mutex_lock(&dev->mutex); |
| 197 | dev->usbdev = NULL; |
| 198 | mutex_unlock(&dev->mutex); |
Mauro Carvalho Chehab | 7b606ff | 2016-02-09 15:53:39 -0200 | [diff] [blame] | 199 | if (au0828_analog_unregister(dev)) { |
Mauro Carvalho Chehab | 7e9a8ad | 2015-12-10 10:58:04 -0200 | [diff] [blame] | 200 | /* |
| 201 | * No need to call au0828_usb_release() if V4L2 is enabled, |
| 202 | * as this is already called via au0828_usb_v4l2_release() |
| 203 | */ |
Hans Verkuil | 823beb7 | 2013-03-11 10:16:45 -0300 | [diff] [blame] | 204 | return; |
| 205 | } |
Hans Verkuil | 823beb7 | 2013-03-11 10:16:45 -0300 | [diff] [blame] | 206 | au0828_usb_release(dev); |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 207 | } |
| 208 | |
Mauro Carvalho Chehab | 9f80679 | 2015-12-28 09:55:49 -0200 | [diff] [blame] | 209 | static int au0828_media_device_init(struct au0828_dev *dev, |
| 210 | struct usb_device *udev) |
Rafael Lourenço de Lima Chehab | bed6919 | 2015-06-08 22:20:46 -0300 | [diff] [blame] | 211 | { |
| 212 | #ifdef CONFIG_MEDIA_CONTROLLER |
| 213 | struct media_device *mdev; |
Rafael Lourenço de Lima Chehab | bed6919 | 2015-06-08 22:20:46 -0300 | [diff] [blame] | 214 | |
Mauro Carvalho Chehab | 405ddbf | 2016-03-31 10:54:05 -0300 | [diff] [blame] | 215 | mdev = kzalloc(sizeof(*mdev), GFP_KERNEL); |
Rafael Lourenço de Lima Chehab | bed6919 | 2015-06-08 22:20:46 -0300 | [diff] [blame] | 216 | if (!mdev) |
Mauro Carvalho Chehab | 9f80679 | 2015-12-28 09:55:49 -0200 | [diff] [blame] | 217 | return -ENOMEM; |
Rafael Lourenço de Lima Chehab | bed6919 | 2015-06-08 22:20:46 -0300 | [diff] [blame] | 218 | |
Shuah Khan | 7b12adf | 2016-02-11 21:41:31 -0200 | [diff] [blame] | 219 | /* check if media device is already initialized */ |
| 220 | if (!mdev->dev) |
| 221 | media_device_usb_init(mdev, udev, udev->product); |
Mauro Carvalho Chehab | 6cf5dad | 2016-02-22 12:10:49 -0300 | [diff] [blame] | 222 | |
Rafael Lourenço de Lima Chehab | bed6919 | 2015-06-08 22:20:46 -0300 | [diff] [blame] | 223 | dev->media_dev = mdev; |
| 224 | #endif |
Mauro Carvalho Chehab | 9f80679 | 2015-12-28 09:55:49 -0200 | [diff] [blame] | 225 | return 0; |
Rafael Lourenço de Lima Chehab | bed6919 | 2015-06-08 22:20:46 -0300 | [diff] [blame] | 226 | } |
| 227 | |
Arnd Bergmann | 0a82edd | 2016-03-04 21:06:43 -0300 | [diff] [blame] | 228 | #ifdef CONFIG_MEDIA_CONTROLLER |
Shuah Khan | f90c5d7 | 2016-02-11 21:41:34 -0200 | [diff] [blame] | 229 | static void au0828_media_graph_notify(struct media_entity *new, |
| 230 | void *notify_data) |
| 231 | { |
Shuah Khan | f90c5d7 | 2016-02-11 21:41:34 -0200 | [diff] [blame] | 232 | struct au0828_dev *dev = (struct au0828_dev *) notify_data; |
| 233 | int ret; |
Shuah Khan | 9096cae | 2016-03-03 00:38:19 -0300 | [diff] [blame] | 234 | struct media_entity *entity, *mixer = NULL, *decoder = NULL; |
Shuah Khan | f90c5d7 | 2016-02-11 21:41:34 -0200 | [diff] [blame] | 235 | |
Shuah Khan | 9096cae | 2016-03-03 00:38:19 -0300 | [diff] [blame] | 236 | if (!new) { |
| 237 | /* |
| 238 | * Called during au0828 probe time to connect |
| 239 | * entites that were created prior to registering |
| 240 | * the notify handler. Find mixer and decoder. |
| 241 | */ |
| 242 | media_device_for_each_entity(entity, dev->media_dev) { |
| 243 | if (entity->function == MEDIA_ENT_F_AUDIO_MIXER) |
| 244 | mixer = entity; |
| 245 | else if (entity->function == MEDIA_ENT_F_ATV_DECODER) |
| 246 | decoder = entity; |
| 247 | } |
| 248 | goto create_link; |
| 249 | } |
Shuah Khan | f90c5d7 | 2016-02-11 21:41:34 -0200 | [diff] [blame] | 250 | |
| 251 | switch (new->function) { |
| 252 | case MEDIA_ENT_F_AUDIO_MIXER: |
Shuah Khan | 9096cae | 2016-03-03 00:38:19 -0300 | [diff] [blame] | 253 | mixer = new; |
| 254 | if (dev->decoder) |
| 255 | decoder = dev->decoder; |
| 256 | break; |
| 257 | case MEDIA_ENT_F_ATV_DECODER: |
| 258 | /* In case, Mixer is added first, find mixer and create link */ |
| 259 | media_device_for_each_entity(entity, dev->media_dev) { |
| 260 | if (entity->function == MEDIA_ENT_F_AUDIO_MIXER) |
| 261 | mixer = entity; |
| 262 | } |
| 263 | decoder = new; |
Shuah Khan | f90c5d7 | 2016-02-11 21:41:34 -0200 | [diff] [blame] | 264 | break; |
| 265 | default: |
| 266 | break; |
| 267 | } |
Shuah Khan | 9096cae | 2016-03-03 00:38:19 -0300 | [diff] [blame] | 268 | |
| 269 | create_link: |
| 270 | if (decoder && mixer) { |
| 271 | ret = media_create_pad_link(decoder, |
| 272 | DEMOD_PAD_AUDIO_OUT, |
| 273 | mixer, 0, |
| 274 | MEDIA_LNK_FL_ENABLED); |
| 275 | if (ret) |
| 276 | dev_err(&dev->usbdev->dev, |
| 277 | "Mixer Pad Link Create Error: %d\n", ret); |
| 278 | } |
Shuah Khan | f90c5d7 | 2016-02-11 21:41:34 -0200 | [diff] [blame] | 279 | } |
| 280 | |
Shuah Khan | c94903f | 2016-02-11 21:41:35 -0200 | [diff] [blame] | 281 | static int au0828_enable_source(struct media_entity *entity, |
| 282 | struct media_pipeline *pipe) |
| 283 | { |
Shuah Khan | c94903f | 2016-02-11 21:41:35 -0200 | [diff] [blame] | 284 | struct media_entity *source, *find_source; |
| 285 | struct media_entity *sink; |
| 286 | struct media_link *link, *found_link = NULL; |
| 287 | int ret = 0; |
| 288 | struct media_device *mdev = entity->graph_obj.mdev; |
| 289 | struct au0828_dev *dev; |
| 290 | |
| 291 | if (!mdev) |
| 292 | return -ENODEV; |
| 293 | |
| 294 | mutex_lock(&mdev->graph_mutex); |
| 295 | |
| 296 | dev = mdev->source_priv; |
| 297 | |
| 298 | /* |
| 299 | * For Audio and V4L2 entity, find the link to which decoder |
| 300 | * is the sink. Look for an active link between decoder and |
| 301 | * source (tuner/s-video/Composite), if one exists, nothing |
| 302 | * to do. If not, look for any active links between source |
| 303 | * and any other entity. If one exists, source is busy. If |
| 304 | * source is free, setup link and start pipeline from source. |
| 305 | * For DVB FE entity, the source for the link is the tuner. |
| 306 | * Check if tuner is available and setup link and start |
| 307 | * pipeline. |
| 308 | */ |
| 309 | if (entity->function == MEDIA_ENT_F_DTV_DEMOD) { |
| 310 | sink = entity; |
| 311 | find_source = dev->tuner; |
| 312 | } else { |
| 313 | /* Analog isn't configured or register failed */ |
| 314 | if (!dev->decoder) { |
| 315 | ret = -ENODEV; |
| 316 | goto end; |
| 317 | } |
| 318 | |
| 319 | sink = dev->decoder; |
| 320 | |
| 321 | /* |
| 322 | * Default input is tuner and default input_type |
| 323 | * is AU0828_VMUX_TELEVISION. |
| 324 | * FIXME: |
| 325 | * There is a problem when s_input is called to |
| 326 | * change the default input. s_input will try to |
| 327 | * enable_source before attempting to change the |
| 328 | * input on the device, and will end up enabling |
| 329 | * default source which is tuner. |
| 330 | * |
| 331 | * Additional logic is necessary in au0828 |
| 332 | * to detect that the input has changed and |
| 333 | * enable the right source. |
| 334 | */ |
| 335 | |
| 336 | if (dev->input_type == AU0828_VMUX_TELEVISION) |
| 337 | find_source = dev->tuner; |
| 338 | else if (dev->input_type == AU0828_VMUX_SVIDEO || |
| 339 | dev->input_type == AU0828_VMUX_COMPOSITE) |
| 340 | find_source = &dev->input_ent[dev->input_type]; |
| 341 | else { |
| 342 | /* unknown input - let user select input */ |
| 343 | ret = 0; |
| 344 | goto end; |
| 345 | } |
| 346 | } |
| 347 | |
| 348 | /* Is an active link between sink and source */ |
| 349 | if (dev->active_link) { |
| 350 | /* |
| 351 | * If DVB is using the tuner and calling entity is |
| 352 | * audio/video, the following check will be false, |
| 353 | * since sink is different. Result is Busy. |
| 354 | */ |
| 355 | if (dev->active_link->sink->entity == sink && |
| 356 | dev->active_link->source->entity == find_source) { |
| 357 | /* |
| 358 | * Either ALSA or Video own tuner. sink is |
| 359 | * the same for both. Prevent Video stepping |
| 360 | * on ALSA when ALSA owns the source. |
| 361 | */ |
| 362 | if (dev->active_link_owner != entity && |
| 363 | dev->active_link_owner->function == |
| 364 | MEDIA_ENT_F_AUDIO_CAPTURE) { |
| 365 | pr_debug("ALSA has the tuner\n"); |
| 366 | ret = -EBUSY; |
| 367 | goto end; |
| 368 | } |
| 369 | ret = 0; |
| 370 | goto end; |
| 371 | } else { |
| 372 | ret = -EBUSY; |
| 373 | goto end; |
| 374 | } |
| 375 | } |
| 376 | |
| 377 | list_for_each_entry(link, &sink->links, list) { |
| 378 | /* Check sink, and source */ |
| 379 | if (link->sink->entity == sink && |
| 380 | link->source->entity == find_source) { |
| 381 | found_link = link; |
| 382 | break; |
| 383 | } |
| 384 | } |
| 385 | |
| 386 | if (!found_link) { |
| 387 | ret = -ENODEV; |
| 388 | goto end; |
| 389 | } |
| 390 | |
| 391 | /* activate link between source and sink and start pipeline */ |
| 392 | source = found_link->source->entity; |
| 393 | ret = __media_entity_setup_link(found_link, MEDIA_LNK_FL_ENABLED); |
| 394 | if (ret) { |
| 395 | pr_err("Activate tuner link %s->%s. Error %d\n", |
| 396 | source->name, sink->name, ret); |
| 397 | goto end; |
| 398 | } |
| 399 | |
| 400 | ret = __media_entity_pipeline_start(entity, pipe); |
| 401 | if (ret) { |
| 402 | pr_err("Start Pipeline: %s->%s Error %d\n", |
| 403 | source->name, entity->name, ret); |
| 404 | ret = __media_entity_setup_link(found_link, 0); |
| 405 | pr_err("Deactivate link Error %d\n", ret); |
| 406 | goto end; |
| 407 | } |
| 408 | /* |
| 409 | * save active link and active link owner to avoid audio |
| 410 | * deactivating video owned link from disable_source and |
| 411 | * vice versa |
| 412 | */ |
| 413 | dev->active_link = found_link; |
| 414 | dev->active_link_owner = entity; |
| 415 | dev->active_source = source; |
| 416 | dev->active_sink = sink; |
| 417 | |
| 418 | pr_debug("Enabled Source: %s->%s->%s Ret %d\n", |
| 419 | dev->active_source->name, dev->active_sink->name, |
| 420 | dev->active_link_owner->name, ret); |
| 421 | end: |
| 422 | mutex_unlock(&mdev->graph_mutex); |
| 423 | pr_debug("au0828_enable_source() end %s %d %d\n", |
| 424 | entity->name, entity->function, ret); |
| 425 | return ret; |
Shuah Khan | c94903f | 2016-02-11 21:41:35 -0200 | [diff] [blame] | 426 | } |
| 427 | |
| 428 | static void au0828_disable_source(struct media_entity *entity) |
| 429 | { |
Shuah Khan | c94903f | 2016-02-11 21:41:35 -0200 | [diff] [blame] | 430 | int ret = 0; |
| 431 | struct media_device *mdev = entity->graph_obj.mdev; |
| 432 | struct au0828_dev *dev; |
| 433 | |
| 434 | if (!mdev) |
| 435 | return; |
| 436 | |
| 437 | mutex_lock(&mdev->graph_mutex); |
| 438 | dev = mdev->source_priv; |
| 439 | |
| 440 | if (!dev->active_link) { |
| 441 | ret = -ENODEV; |
| 442 | goto end; |
| 443 | } |
| 444 | |
| 445 | /* link is active - stop pipeline from source (tuner) */ |
| 446 | if (dev->active_link->sink->entity == dev->active_sink && |
| 447 | dev->active_link->source->entity == dev->active_source) { |
| 448 | /* |
| 449 | * prevent video from deactivating link when audio |
| 450 | * has active pipeline |
| 451 | */ |
| 452 | if (dev->active_link_owner != entity) |
| 453 | goto end; |
| 454 | __media_entity_pipeline_stop(entity); |
| 455 | ret = __media_entity_setup_link(dev->active_link, 0); |
| 456 | if (ret) |
| 457 | pr_err("Deactivate link Error %d\n", ret); |
| 458 | |
| 459 | pr_debug("Disabled Source: %s->%s->%s Ret %d\n", |
| 460 | dev->active_source->name, dev->active_sink->name, |
| 461 | dev->active_link_owner->name, ret); |
| 462 | |
| 463 | dev->active_link = NULL; |
| 464 | dev->active_link_owner = NULL; |
| 465 | dev->active_source = NULL; |
| 466 | dev->active_sink = NULL; |
| 467 | } |
| 468 | |
| 469 | end: |
| 470 | mutex_unlock(&mdev->graph_mutex); |
Shuah Khan | c94903f | 2016-02-11 21:41:35 -0200 | [diff] [blame] | 471 | } |
Arnd Bergmann | 0a82edd | 2016-03-04 21:06:43 -0300 | [diff] [blame] | 472 | #endif |
Shuah Khan | c94903f | 2016-02-11 21:41:35 -0200 | [diff] [blame] | 473 | |
Shuah Khan | 7b12adf | 2016-02-11 21:41:31 -0200 | [diff] [blame] | 474 | static int au0828_media_device_register(struct au0828_dev *dev, |
| 475 | struct usb_device *udev) |
| 476 | { |
| 477 | #ifdef CONFIG_MEDIA_CONTROLLER |
| 478 | int ret; |
Mauro Carvalho Chehab | 2e208c6 | 2016-03-11 16:02:14 -0300 | [diff] [blame] | 479 | struct media_entity *entity, *demod = NULL; |
| 480 | struct media_link *link; |
Shuah Khan | 7b12adf | 2016-02-11 21:41:31 -0200 | [diff] [blame] | 481 | |
Shuah Khan | f90c5d7 | 2016-02-11 21:41:34 -0200 | [diff] [blame] | 482 | if (!dev->media_dev) |
| 483 | return 0; |
| 484 | |
Mauro Carvalho Chehab | a087ce7 | 2016-04-27 19:28:26 -0300 | [diff] [blame] | 485 | if (!media_devnode_is_registered(dev->media_dev->devnode)) { |
Shuah Khan | 7b12adf | 2016-02-11 21:41:31 -0200 | [diff] [blame] | 486 | |
| 487 | /* register media device */ |
| 488 | ret = media_device_register(dev->media_dev); |
| 489 | if (ret) { |
| 490 | dev_err(&udev->dev, |
| 491 | "Media Device Register Error: %d\n", ret); |
| 492 | return ret; |
| 493 | } |
Shuah Khan | 9096cae | 2016-03-03 00:38:19 -0300 | [diff] [blame] | 494 | } else { |
| 495 | /* |
| 496 | * Call au0828_media_graph_notify() to connect |
| 497 | * audio graph to our graph. In this case, audio |
| 498 | * driver registered the device and there is no |
| 499 | * entity_notify to be called when new entities |
| 500 | * are added. Invoke it now. |
| 501 | */ |
| 502 | au0828_media_graph_notify(NULL, (void *) dev); |
Shuah Khan | 7b12adf | 2016-02-11 21:41:31 -0200 | [diff] [blame] | 503 | } |
Shuah Khan | 840f5b0 | 2016-03-09 19:15:38 -0700 | [diff] [blame] | 504 | |
| 505 | /* |
Mauro Carvalho Chehab | 2e208c6 | 2016-03-11 16:02:14 -0300 | [diff] [blame] | 506 | * Find tuner, decoder and demod. |
| 507 | * |
| 508 | * The tuner and decoder should be cached, as they'll be used by |
| 509 | * au0828_enable_source. |
| 510 | * |
| 511 | * It also needs to disable the link between tuner and |
| 512 | * decoder/demod, to avoid disable step when tuner is requested |
| 513 | * by video or audio. Note that this step can't be done until dvb |
| 514 | * graph is created during dvb register. |
Shuah Khan | 840f5b0 | 2016-03-09 19:15:38 -0700 | [diff] [blame] | 515 | */ |
| 516 | media_device_for_each_entity(entity, dev->media_dev) { |
Mauro Carvalho Chehab | 2e208c6 | 2016-03-11 16:02:14 -0300 | [diff] [blame] | 517 | switch (entity->function) { |
| 518 | case MEDIA_ENT_F_TUNER: |
| 519 | dev->tuner = entity; |
| 520 | break; |
| 521 | case MEDIA_ENT_F_ATV_DECODER: |
| 522 | dev->decoder = entity; |
| 523 | break; |
| 524 | case MEDIA_ENT_F_DTV_DEMOD: |
Shuah Khan | 840f5b0 | 2016-03-09 19:15:38 -0700 | [diff] [blame] | 525 | demod = entity; |
Mauro Carvalho Chehab | 2e208c6 | 2016-03-11 16:02:14 -0300 | [diff] [blame] | 526 | break; |
| 527 | } |
Shuah Khan | 840f5b0 | 2016-03-09 19:15:38 -0700 | [diff] [blame] | 528 | } |
Shuah Khan | 840f5b0 | 2016-03-09 19:15:38 -0700 | [diff] [blame] | 529 | |
Mauro Carvalho Chehab | 2e208c6 | 2016-03-11 16:02:14 -0300 | [diff] [blame] | 530 | /* Disable link between tuner->demod and/or tuner->decoder */ |
| 531 | if (dev->tuner) { |
| 532 | list_for_each_entry(link, &dev->tuner->links, list) { |
| 533 | if (demod && link->sink->entity == demod) |
Shuah Khan | 840f5b0 | 2016-03-09 19:15:38 -0700 | [diff] [blame] | 534 | media_entity_setup_link(link, 0); |
Mauro Carvalho Chehab | 2e208c6 | 2016-03-11 16:02:14 -0300 | [diff] [blame] | 535 | if (dev->decoder && link->sink->entity == dev->decoder) |
| 536 | media_entity_setup_link(link, 0); |
Shuah Khan | 840f5b0 | 2016-03-09 19:15:38 -0700 | [diff] [blame] | 537 | } |
| 538 | } |
| 539 | |
Shuah Khan | f90c5d7 | 2016-02-11 21:41:34 -0200 | [diff] [blame] | 540 | /* register entity_notify callback */ |
| 541 | dev->entity_notify.notify_data = (void *) dev; |
| 542 | dev->entity_notify.notify = (void *) au0828_media_graph_notify; |
| 543 | ret = media_device_register_entity_notify(dev->media_dev, |
| 544 | &dev->entity_notify); |
| 545 | if (ret) { |
| 546 | dev_err(&udev->dev, |
| 547 | "Media Device register entity_notify Error: %d\n", |
| 548 | ret); |
| 549 | return ret; |
| 550 | } |
Shuah Khan | c94903f | 2016-02-11 21:41:35 -0200 | [diff] [blame] | 551 | /* set enable_source */ |
| 552 | dev->media_dev->source_priv = (void *) dev; |
| 553 | dev->media_dev->enable_source = au0828_enable_source; |
| 554 | dev->media_dev->disable_source = au0828_disable_source; |
Shuah Khan | 7b12adf | 2016-02-11 21:41:31 -0200 | [diff] [blame] | 555 | #endif |
| 556 | return 0; |
| 557 | } |
Rafael Lourenço de Lima Chehab | bed6919 | 2015-06-08 22:20:46 -0300 | [diff] [blame] | 558 | |
Mauro Carvalho Chehab | 18d73c5 | 2008-04-18 22:12:52 -0300 | [diff] [blame] | 559 | static int au0828_usb_probe(struct usb_interface *interface, |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 560 | const struct usb_device_id *id) |
| 561 | { |
Michael Krufky | 8a4e786 | 2012-12-04 11:30:00 -0300 | [diff] [blame] | 562 | int ifnum; |
Tim Mester | f251b3e | 2014-01-07 01:29:25 -0300 | [diff] [blame] | 563 | int retval = 0; |
| 564 | |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 565 | struct au0828_dev *dev; |
| 566 | struct usb_device *usbdev = interface_to_usbdev(interface); |
| 567 | |
| 568 | ifnum = interface->altsetting->desc.bInterfaceNumber; |
| 569 | |
| 570 | if (ifnum != 0) |
| 571 | return -ENODEV; |
| 572 | |
Steven Toth | a9c36aa | 2008-04-17 21:41:28 -0300 | [diff] [blame] | 573 | dprintk(1, "%s() vendor id 0x%x device id 0x%x ifnum:%d\n", __func__, |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 574 | le16_to_cpu(usbdev->descriptor.idVendor), |
| 575 | le16_to_cpu(usbdev->descriptor.idProduct), |
| 576 | ifnum); |
| 577 | |
Devin Heitmueller | ee3436b | 2009-05-27 23:25:36 -0300 | [diff] [blame] | 578 | /* |
| 579 | * Make sure we have 480 Mbps of bandwidth, otherwise things like |
| 580 | * video stream wouldn't likely work, since 12 Mbps is generally |
| 581 | * not enough even for most Digital TV streams. |
| 582 | */ |
Devin Heitmueller | d6a9a43 | 2009-05-27 23:46:17 -0300 | [diff] [blame] | 583 | if (usbdev->speed != USB_SPEED_HIGH && disable_usb_speed_check == 0) { |
Mauro Carvalho Chehab | 83afb32 | 2014-08-09 21:47:17 -0300 | [diff] [blame] | 584 | pr_err("au0828: Device initialization failed.\n"); |
| 585 | pr_err("au0828: Device must be connected to a high-speed USB 2.0 port.\n"); |
Devin Heitmueller | ee3436b | 2009-05-27 23:25:36 -0300 | [diff] [blame] | 586 | return -ENODEV; |
| 587 | } |
| 588 | |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 589 | dev = kzalloc(sizeof(*dev), GFP_KERNEL); |
| 590 | if (dev == NULL) { |
Mauro Carvalho Chehab | 83afb32 | 2014-08-09 21:47:17 -0300 | [diff] [blame] | 591 | pr_err("%s() Unable to allocate memory\n", __func__); |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 592 | return -ENOMEM; |
| 593 | } |
| 594 | |
Devin Heitmueller | 549ee4d | 2012-08-06 22:46:58 -0300 | [diff] [blame] | 595 | mutex_init(&dev->lock); |
| 596 | mutex_lock(&dev->lock); |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 597 | mutex_init(&dev->mutex); |
| 598 | mutex_init(&dev->dvb.lock); |
| 599 | dev->usbdev = usbdev; |
Devin Heitmueller | f1add5b | 2009-03-11 03:00:47 -0300 | [diff] [blame] | 600 | dev->boardnr = id->driver_info; |
Rafael Lourenço de Lima Chehab | e42c8c6 | 2015-06-08 22:20:45 -0300 | [diff] [blame] | 601 | dev->board = au0828_boards[dev->boardnr]; |
| 602 | |
Javier Martinez Canillas | 9832e15 | 2015-12-11 20:57:08 -0200 | [diff] [blame] | 603 | /* Initialize the media controller */ |
Mauro Carvalho Chehab | 9f80679 | 2015-12-28 09:55:49 -0200 | [diff] [blame] | 604 | retval = au0828_media_device_init(dev, usbdev); |
| 605 | if (retval) { |
| 606 | pr_err("%s() au0828_media_device_init failed\n", |
| 607 | __func__); |
| 608 | mutex_unlock(&dev->lock); |
| 609 | kfree(dev); |
| 610 | return retval; |
| 611 | } |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 612 | |
Mauro Carvalho Chehab | 7b606ff | 2016-02-09 15:53:39 -0200 | [diff] [blame] | 613 | retval = au0828_v4l2_device_register(interface, dev); |
Devin Heitmueller | b14667f | 2009-03-11 03:01:04 -0300 | [diff] [blame] | 614 | if (retval) { |
Mauro Carvalho Chehab | 7b606ff | 2016-02-09 15:53:39 -0200 | [diff] [blame] | 615 | au0828_usb_v4l2_media_release(dev); |
Devin Heitmueller | 549ee4d | 2012-08-06 22:46:58 -0300 | [diff] [blame] | 616 | mutex_unlock(&dev->lock); |
Devin Heitmueller | b14667f | 2009-03-11 03:01:04 -0300 | [diff] [blame] | 617 | kfree(dev); |
Hans Verkuil | e8c26f4 | 2013-02-15 08:55:41 -0300 | [diff] [blame] | 618 | return retval; |
Devin Heitmueller | b14667f | 2009-03-11 03:01:04 -0300 | [diff] [blame] | 619 | } |
| 620 | |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 621 | /* Power Up the bridge */ |
| 622 | au0828_write(dev, REG_600, 1 << 4); |
| 623 | |
| 624 | /* Bring up the GPIO's and supporting devices */ |
| 625 | au0828_gpio_setup(dev); |
| 626 | |
| 627 | /* I2C */ |
| 628 | au0828_i2c_register(dev); |
| 629 | |
Steven Toth | 28930fa | 2008-03-29 19:53:07 -0300 | [diff] [blame] | 630 | /* Setup */ |
| 631 | au0828_card_setup(dev); |
| 632 | |
Sean Young | f7d3edb0 | 2019-05-19 15:28:22 -0400 | [diff] [blame] | 633 | /* |
| 634 | * Store the pointer to the au0828_dev so it can be accessed in |
| 635 | * au0828_usb_disconnect |
| 636 | */ |
| 637 | usb_set_intfdata(interface, dev); |
| 638 | |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 639 | /* Analog TV */ |
Mauro Carvalho Chehab | 7b606ff | 2016-02-09 15:53:39 -0200 | [diff] [blame] | 640 | retval = au0828_analog_register(dev, interface); |
| 641 | if (retval) { |
Brad Love | c6b1c9d | 2018-09-06 17:07:49 -0400 | [diff] [blame] | 642 | pr_err("%s() au0828_analog_register failed to register on V4L2\n", |
Mauro Carvalho Chehab | 7b606ff | 2016-02-09 15:53:39 -0200 | [diff] [blame] | 643 | __func__); |
| 644 | goto done; |
Mauro Carvalho Chehab | 82e92f4 | 2016-02-09 13:46:05 -0200 | [diff] [blame] | 645 | } |
Devin Heitmueller | 8b2f079 | 2009-03-11 03:00:40 -0300 | [diff] [blame] | 646 | |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 647 | /* Digital TV */ |
Tim Mester | f251b3e | 2014-01-07 01:29:25 -0300 | [diff] [blame] | 648 | retval = au0828_dvb_register(dev); |
| 649 | if (retval) |
Brad Love | c6b1c9d | 2018-09-06 17:07:49 -0400 | [diff] [blame] | 650 | pr_err("%s() au0828_dvb_register failed\n", |
Tim Mester | f251b3e | 2014-01-07 01:29:25 -0300 | [diff] [blame] | 651 | __func__); |
| 652 | |
Mauro Carvalho Chehab | 2fcfd31 | 2014-07-24 22:49:02 -0300 | [diff] [blame] | 653 | /* Remote controller */ |
| 654 | au0828_rc_register(dev); |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 655 | |
Mauro Carvalho Chehab | 83afb32 | 2014-08-09 21:47:17 -0300 | [diff] [blame] | 656 | pr_info("Registered device AU0828 [%s]\n", |
Devin Heitmueller | f1add5b | 2009-03-11 03:00:47 -0300 | [diff] [blame] | 657 | dev->board.name == NULL ? "Unset" : dev->board.name); |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 658 | |
Devin Heitmueller | 549ee4d | 2012-08-06 22:46:58 -0300 | [diff] [blame] | 659 | mutex_unlock(&dev->lock); |
| 660 | |
Shuah Khan | 7b12adf | 2016-02-11 21:41:31 -0200 | [diff] [blame] | 661 | retval = au0828_media_device_register(dev, usbdev); |
Javier Martinez Canillas | 9832e15 | 2015-12-11 20:57:08 -0200 | [diff] [blame] | 662 | |
| 663 | done: |
| 664 | if (retval < 0) |
| 665 | au0828_usb_disconnect(interface); |
| 666 | |
Tim Mester | f251b3e | 2014-01-07 01:29:25 -0300 | [diff] [blame] | 667 | return retval; |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 668 | } |
| 669 | |
Mauro Carvalho Chehab | aaeac19 | 2014-08-09 21:47:11 -0300 | [diff] [blame] | 670 | static int au0828_suspend(struct usb_interface *interface, |
| 671 | pm_message_t message) |
| 672 | { |
| 673 | struct au0828_dev *dev = usb_get_intfdata(interface); |
| 674 | |
| 675 | if (!dev) |
| 676 | return 0; |
| 677 | |
Mauro Carvalho Chehab | 8118724 | 2014-08-09 21:47:18 -0300 | [diff] [blame] | 678 | pr_info("Suspend\n"); |
| 679 | |
Mauro Carvalho Chehab | aaeac19 | 2014-08-09 21:47:11 -0300 | [diff] [blame] | 680 | au0828_rc_suspend(dev); |
Mauro Carvalho Chehab | 1a1ba95 | 2014-08-09 21:47:15 -0300 | [diff] [blame] | 681 | au0828_v4l2_suspend(dev); |
Mauro Carvalho Chehab | b799de7 | 2014-08-09 21:47:13 -0300 | [diff] [blame] | 682 | au0828_dvb_suspend(dev); |
Mauro Carvalho Chehab | aaeac19 | 2014-08-09 21:47:11 -0300 | [diff] [blame] | 683 | |
| 684 | /* FIXME: should suspend also ATV/DTV */ |
| 685 | |
| 686 | return 0; |
| 687 | } |
| 688 | |
| 689 | static int au0828_resume(struct usb_interface *interface) |
| 690 | { |
| 691 | struct au0828_dev *dev = usb_get_intfdata(interface); |
| 692 | if (!dev) |
| 693 | return 0; |
| 694 | |
Mauro Carvalho Chehab | 8118724 | 2014-08-09 21:47:18 -0300 | [diff] [blame] | 695 | pr_info("Resume\n"); |
| 696 | |
Mauro Carvalho Chehab | fa50046 | 2014-08-09 21:47:12 -0300 | [diff] [blame] | 697 | /* Power Up the bridge */ |
| 698 | au0828_write(dev, REG_600, 1 << 4); |
| 699 | |
| 700 | /* Bring up the GPIO's and supporting devices */ |
| 701 | au0828_gpio_setup(dev); |
| 702 | |
Mauro Carvalho Chehab | aaeac19 | 2014-08-09 21:47:11 -0300 | [diff] [blame] | 703 | au0828_rc_resume(dev); |
Mauro Carvalho Chehab | 1a1ba95 | 2014-08-09 21:47:15 -0300 | [diff] [blame] | 704 | au0828_v4l2_resume(dev); |
Mauro Carvalho Chehab | b799de7 | 2014-08-09 21:47:13 -0300 | [diff] [blame] | 705 | au0828_dvb_resume(dev); |
Mauro Carvalho Chehab | aaeac19 | 2014-08-09 21:47:11 -0300 | [diff] [blame] | 706 | |
| 707 | /* FIXME: should resume also ATV/DTV */ |
| 708 | |
| 709 | return 0; |
| 710 | } |
| 711 | |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 712 | static struct usb_driver au0828_usb_driver = { |
Mauro Carvalho Chehab | 83afb32 | 2014-08-09 21:47:17 -0300 | [diff] [blame] | 713 | .name = KBUILD_MODNAME, |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 714 | .probe = au0828_usb_probe, |
| 715 | .disconnect = au0828_usb_disconnect, |
| 716 | .id_table = au0828_usb_id_table, |
Mauro Carvalho Chehab | aaeac19 | 2014-08-09 21:47:11 -0300 | [diff] [blame] | 717 | .suspend = au0828_suspend, |
| 718 | .resume = au0828_resume, |
| 719 | .reset_resume = au0828_resume, |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 720 | }; |
| 721 | |
| 722 | static int __init au0828_init(void) |
| 723 | { |
| 724 | int ret; |
| 725 | |
Adrian Bunk | b33d24c | 2008-04-25 19:06:03 -0300 | [diff] [blame] | 726 | if (au0828_debug & 1) |
Mauro Carvalho Chehab | 83afb32 | 2014-08-09 21:47:17 -0300 | [diff] [blame] | 727 | pr_info("%s() Debugging is enabled\n", __func__); |
Steven Toth | bc3c613 | 2008-04-18 21:39:11 -0300 | [diff] [blame] | 728 | |
Adrian Bunk | b33d24c | 2008-04-25 19:06:03 -0300 | [diff] [blame] | 729 | if (au0828_debug & 2) |
Mauro Carvalho Chehab | 83afb32 | 2014-08-09 21:47:17 -0300 | [diff] [blame] | 730 | pr_info("%s() USB Debugging is enabled\n", __func__); |
Steven Toth | bc3c613 | 2008-04-18 21:39:11 -0300 | [diff] [blame] | 731 | |
Adrian Bunk | b33d24c | 2008-04-25 19:06:03 -0300 | [diff] [blame] | 732 | if (au0828_debug & 4) |
Mauro Carvalho Chehab | 83afb32 | 2014-08-09 21:47:17 -0300 | [diff] [blame] | 733 | pr_info("%s() I2C Debugging is enabled\n", __func__); |
Steven Toth | bc3c613 | 2008-04-18 21:39:11 -0300 | [diff] [blame] | 734 | |
Adrian Bunk | b33d24c | 2008-04-25 19:06:03 -0300 | [diff] [blame] | 735 | if (au0828_debug & 8) |
Mauro Carvalho Chehab | 83afb32 | 2014-08-09 21:47:17 -0300 | [diff] [blame] | 736 | pr_info("%s() Bridge Debugging is enabled\n", |
Michael Krufky | f07e8e4 | 2008-04-18 21:42:30 -0300 | [diff] [blame] | 737 | __func__); |
Steven Toth | bc3c613 | 2008-04-18 21:39:11 -0300 | [diff] [blame] | 738 | |
Mauro Carvalho Chehab | 2fcfd31 | 2014-07-24 22:49:02 -0300 | [diff] [blame] | 739 | if (au0828_debug & 16) |
Mauro Carvalho Chehab | 83afb32 | 2014-08-09 21:47:17 -0300 | [diff] [blame] | 740 | pr_info("%s() IR Debugging is enabled\n", |
Mauro Carvalho Chehab | 2fcfd31 | 2014-07-24 22:49:02 -0300 | [diff] [blame] | 741 | __func__); |
| 742 | |
Mauro Carvalho Chehab | 83afb32 | 2014-08-09 21:47:17 -0300 | [diff] [blame] | 743 | pr_info("au0828 driver loaded\n"); |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 744 | |
| 745 | ret = usb_register(&au0828_usb_driver); |
| 746 | if (ret) |
Mauro Carvalho Chehab | 83afb32 | 2014-08-09 21:47:17 -0300 | [diff] [blame] | 747 | pr_err("usb_register failed, error = %d\n", ret); |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 748 | |
| 749 | return ret; |
| 750 | } |
| 751 | |
| 752 | static void __exit au0828_exit(void) |
| 753 | { |
| 754 | usb_deregister(&au0828_usb_driver); |
| 755 | } |
| 756 | |
| 757 | module_init(au0828_init); |
| 758 | module_exit(au0828_exit); |
| 759 | |
| 760 | MODULE_DESCRIPTION("Driver for Auvitek AU0828 based products"); |
Steven Toth | 6d89761 | 2008-09-03 17:12:12 -0300 | [diff] [blame] | 761 | MODULE_AUTHOR("Steven Toth <stoth@linuxtv.org>"); |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 762 | MODULE_LICENSE("GPL"); |
Mauro Carvalho Chehab | 2fcfd31 | 2014-07-24 22:49:02 -0300 | [diff] [blame] | 763 | MODULE_VERSION("0.0.3"); |