+/* Device specific operations */
+
+static int default_set_power_mode(am7xxx_device *dev, am7xxx_power_mode power)
+{
+ int ret;
+ struct am7xxx_header h = {
+ .packet_type = AM7XXX_PACKET_TYPE_POWER,
+ .direction = AM7XXX_DIRECTION_OUT,
+ .header_data_len = sizeof(struct am7xxx_power_header),
+ .unknown2 = 0x3e,
+ .unknown3 = 0x10,
+ };
+
+ switch(power) {
+ case AM7XXX_POWER_OFF:
+ h.header_data.power.bit2 = 0;
+ h.header_data.power.bit1 = 0;
+ h.header_data.power.bit0 = 0;
+ break;
+
+ case AM7XXX_POWER_LOW:
+ h.header_data.power.bit2 = 0;
+ h.header_data.power.bit1 = 0;
+ h.header_data.power.bit0 = 1;
+ break;
+
+ case AM7XXX_POWER_MIDDLE:
+ h.header_data.power.bit2 = 0;
+ h.header_data.power.bit1 = 1;
+ h.header_data.power.bit0 = 0;
+ break;
+
+ case AM7XXX_POWER_HIGH:
+ h.header_data.power.bit2 = 0;
+ h.header_data.power.bit1 = 1;
+ h.header_data.power.bit0 = 1;
+ break;
+
+ case AM7XXX_POWER_TURBO:
+ h.header_data.power.bit2 = 1;
+ h.header_data.power.bit1 = 0;
+ h.header_data.power.bit0 = 0;
+ break;
+
+ default:
+ error(dev->ctx, "Unsupported power mode.\n");
+ return -EINVAL;
+ };
+
+ ret = send_header(dev, &h);
+ if (ret < 0)
+ return ret;
+
+ return 0;
+}
+
+static int picopix_set_power_mode(am7xxx_device *dev, am7xxx_power_mode power)
+{
+ switch(power) {
+ case AM7XXX_POWER_LOW:
+ return send_command(dev, AM7XXX_PACKET_TYPE_PICOPIX_POWER_LOW);
+
+ case AM7XXX_POWER_MIDDLE:
+ return send_command(dev, AM7XXX_PACKET_TYPE_PICOPIX_POWER_MEDIUM);
+
+ case AM7XXX_POWER_HIGH:
+ return send_command(dev, AM7XXX_PACKET_TYPE_PICOPIX_POWER_HIGH);
+
+ case AM7XXX_POWER_OFF:
+ case AM7XXX_POWER_TURBO:
+ default:
+ error(dev->ctx, "Unsupported power mode.\n");
+ return -EINVAL;
+ };
+}
+
+static int default_set_zoom_mode(am7xxx_device *dev, am7xxx_zoom_mode zoom)
+{
+ int ret;
+ struct am7xxx_header h = {
+ .packet_type = AM7XXX_PACKET_TYPE_ZOOM,
+ .direction = AM7XXX_DIRECTION_OUT,
+ .header_data_len = sizeof(struct am7xxx_zoom_header),
+ .unknown2 = 0x3e,
+ .unknown3 = 0x10,
+ };
+
+ switch(zoom) {
+ case AM7XXX_ZOOM_ORIGINAL:
+ h.header_data.zoom.bit1 = 0;
+ h.header_data.zoom.bit0 = 0;
+ break;
+
+ case AM7XXX_ZOOM_H:
+ h.header_data.zoom.bit1 = 0;
+ h.header_data.zoom.bit0 = 1;
+ break;
+
+ case AM7XXX_ZOOM_H_V:
+ h.header_data.zoom.bit1 = 1;
+ h.header_data.zoom.bit0 = 0;
+ break;
+
+ case AM7XXX_ZOOM_TEST:
+ h.header_data.zoom.bit1 = 1;
+ h.header_data.zoom.bit0 = 1;
+ break;
+
+ case AM7XXX_ZOOM_TELE:
+ default:
+ error(dev->ctx, "Unsupported zoom mode.\n");
+ return -EINVAL;
+ };
+
+ ret = send_header(dev, &h);
+ if (ret < 0)
+ return ret;
+
+ return 0;
+}
+
+static int picopix_set_zoom_mode(am7xxx_device *dev, am7xxx_zoom_mode zoom)
+{
+ int ret;
+ am7xxx_packet_type packet_type;
+
+ switch(zoom) {
+ case AM7XXX_ZOOM_ORIGINAL:
+ packet_type = AM7XXX_PACKET_TYPE_PICOPIX_DISABLE_TI;
+ break;
+
+ case AM7XXX_ZOOM_TELE:
+ packet_type = AM7XXX_PACKET_TYPE_PICOPIX_ENABLE_TI;
+ break;
+
+ case AM7XXX_ZOOM_H:
+ case AM7XXX_ZOOM_H_V:
+ case AM7XXX_ZOOM_TEST:
+ default:
+ error(dev->ctx, "Unsupported zoom mode.\n");
+ return -EINVAL;
+ };
+
+ ret = send_command(dev, packet_type);
+ if (ret < 0)
+ return ret;
+
+ /* The Windows drivers wait for 100ms and send the same command again,
+ * probably to overcome a firmware deficiency */
+ ret = msleep(100);
+ if (ret < 0)
+ return ret;
+
+ return send_command(dev, packet_type);
+}
+