mirror of
https://github.com/AetherDroid/android_kernel_samsung_on5xelte.git
synced 2025-09-08 01:08:03 -04:00
Fixed MTP to work with TWRP
This commit is contained in:
commit
f6dfaef42e
50820 changed files with 20846062 additions and 0 deletions
7
drivers/ps3/Makefile
Normal file
7
drivers/ps3/Makefile
Normal file
|
@ -0,0 +1,7 @@
|
|||
obj-$(CONFIG_PS3_VUART) += ps3-vuart.o
|
||||
obj-$(CONFIG_PS3_PS3AV) += ps3av_mod.o
|
||||
ps3av_mod-y := ps3av.o ps3av_cmd.o
|
||||
obj-$(CONFIG_PPC_PS3) += sys-manager-core.o
|
||||
obj-$(CONFIG_PS3_SYS_MANAGER) += ps3-sys-manager.o
|
||||
obj-$(CONFIG_PS3_STORAGE) += ps3stor_lib.o
|
||||
obj-$(CONFIG_PS3_LPM) += ps3-lpm.o
|
1253
drivers/ps3/ps3-lpm.c
Normal file
1253
drivers/ps3/ps3-lpm.c
Normal file
File diff suppressed because it is too large
Load diff
767
drivers/ps3/ps3-sys-manager.c
Normal file
767
drivers/ps3/ps3-sys-manager.c
Normal file
|
@ -0,0 +1,767 @@
|
|||
/*
|
||||
* PS3 System Manager.
|
||||
*
|
||||
* Copyright (C) 2007 Sony Computer Entertainment Inc.
|
||||
* Copyright 2007 Sony Corp.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; version 2 of the License.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#include <linux/kernel.h>
|
||||
#include <linux/module.h>
|
||||
#include <linux/workqueue.h>
|
||||
#include <linux/reboot.h>
|
||||
|
||||
#include <asm/firmware.h>
|
||||
#include <asm/lv1call.h>
|
||||
#include <asm/ps3.h>
|
||||
|
||||
#include "vuart.h"
|
||||
|
||||
/**
|
||||
* ps3_sys_manager - PS3 system manager driver.
|
||||
*
|
||||
* The system manager provides an asynchronous system event notification
|
||||
* mechanism for reporting events like thermal alert and button presses to
|
||||
* guests. It also provides support to control system shutdown and startup.
|
||||
*
|
||||
* The actual system manager is implemented as an application running in the
|
||||
* system policy module in lpar_1. Guests communicate with the system manager
|
||||
* through port 2 of the vuart using a simple packet message protocol.
|
||||
* Messages are comprised of a fixed field header followed by a message
|
||||
* specific payload.
|
||||
*/
|
||||
|
||||
/**
|
||||
* struct ps3_sys_manager_header - System manager message header.
|
||||
* @version: Header version, currently 1.
|
||||
* @size: Header size in bytes, currently 16.
|
||||
* @payload_size: Message payload size in bytes.
|
||||
* @service_id: Message type, one of enum ps3_sys_manager_service_id.
|
||||
* @request_tag: Unique number to identify reply.
|
||||
*/
|
||||
|
||||
struct ps3_sys_manager_header {
|
||||
/* version 1 */
|
||||
u8 version;
|
||||
u8 size;
|
||||
u16 reserved_1;
|
||||
u32 payload_size;
|
||||
u16 service_id;
|
||||
u16 reserved_2;
|
||||
u32 request_tag;
|
||||
};
|
||||
|
||||
#define dump_sm_header(_h) _dump_sm_header(_h, __func__, __LINE__)
|
||||
static void __maybe_unused _dump_sm_header(
|
||||
const struct ps3_sys_manager_header *h, const char *func, int line)
|
||||
{
|
||||
pr_debug("%s:%d: version: %xh\n", func, line, h->version);
|
||||
pr_debug("%s:%d: size: %xh\n", func, line, h->size);
|
||||
pr_debug("%s:%d: payload_size: %xh\n", func, line, h->payload_size);
|
||||
pr_debug("%s:%d: service_id: %xh\n", func, line, h->service_id);
|
||||
pr_debug("%s:%d: request_tag: %xh\n", func, line, h->request_tag);
|
||||
}
|
||||
|
||||
/**
|
||||
* @PS3_SM_RX_MSG_LEN_MIN - Shortest received message length.
|
||||
* @PS3_SM_RX_MSG_LEN_MAX - Longest received message length.
|
||||
*
|
||||
* Currently all messages received from the system manager are either
|
||||
* (16 bytes header + 8 bytes payload = 24 bytes) or (16 bytes header
|
||||
* + 16 bytes payload = 32 bytes). This knowledge is used to simplify
|
||||
* the logic.
|
||||
*/
|
||||
|
||||
enum {
|
||||
PS3_SM_RX_MSG_LEN_MIN = 24,
|
||||
PS3_SM_RX_MSG_LEN_MAX = 32,
|
||||
};
|
||||
|
||||
/**
|
||||
* enum ps3_sys_manager_service_id - Message header service_id.
|
||||
* @PS3_SM_SERVICE_ID_REQUEST: guest --> sys_manager.
|
||||
* @PS3_SM_SERVICE_ID_REQUEST_ERROR: guest <-- sys_manager.
|
||||
* @PS3_SM_SERVICE_ID_COMMAND: guest <-- sys_manager.
|
||||
* @PS3_SM_SERVICE_ID_RESPONSE: guest --> sys_manager.
|
||||
* @PS3_SM_SERVICE_ID_SET_ATTR: guest --> sys_manager.
|
||||
* @PS3_SM_SERVICE_ID_EXTERN_EVENT: guest <-- sys_manager.
|
||||
* @PS3_SM_SERVICE_ID_SET_NEXT_OP: guest --> sys_manager.
|
||||
*
|
||||
* PS3_SM_SERVICE_ID_REQUEST_ERROR is returned for invalid data values in a
|
||||
* a PS3_SM_SERVICE_ID_REQUEST message. It also seems to be returned when
|
||||
* a REQUEST message is sent at the wrong time.
|
||||
*/
|
||||
|
||||
enum ps3_sys_manager_service_id {
|
||||
/* version 1 */
|
||||
PS3_SM_SERVICE_ID_REQUEST = 1,
|
||||
PS3_SM_SERVICE_ID_RESPONSE = 2,
|
||||
PS3_SM_SERVICE_ID_COMMAND = 3,
|
||||
PS3_SM_SERVICE_ID_EXTERN_EVENT = 4,
|
||||
PS3_SM_SERVICE_ID_SET_NEXT_OP = 5,
|
||||
PS3_SM_SERVICE_ID_REQUEST_ERROR = 6,
|
||||
PS3_SM_SERVICE_ID_SET_ATTR = 8,
|
||||
};
|
||||
|
||||
/**
|
||||
* enum ps3_sys_manager_attr - Notification attribute (bit position mask).
|
||||
* @PS3_SM_ATTR_POWER: Power button.
|
||||
* @PS3_SM_ATTR_RESET: Reset button, not available on retail console.
|
||||
* @PS3_SM_ATTR_THERMAL: System thermal alert.
|
||||
* @PS3_SM_ATTR_CONTROLLER: Remote controller event.
|
||||
* @PS3_SM_ATTR_ALL: Logical OR of all.
|
||||
*
|
||||
* The guest tells the system manager which events it is interested in receiving
|
||||
* notice of by sending the system manager a logical OR of notification
|
||||
* attributes via the ps3_sys_manager_send_attr() routine.
|
||||
*/
|
||||
|
||||
enum ps3_sys_manager_attr {
|
||||
/* version 1 */
|
||||
PS3_SM_ATTR_POWER = 1,
|
||||
PS3_SM_ATTR_RESET = 2,
|
||||
PS3_SM_ATTR_THERMAL = 4,
|
||||
PS3_SM_ATTR_CONTROLLER = 8, /* bogus? */
|
||||
PS3_SM_ATTR_ALL = 0x0f,
|
||||
};
|
||||
|
||||
/**
|
||||
* enum ps3_sys_manager_event - External event type, reported by system manager.
|
||||
* @PS3_SM_EVENT_POWER_PRESSED: payload.value =
|
||||
* enum ps3_sys_manager_button_event.
|
||||
* @PS3_SM_EVENT_POWER_RELEASED: payload.value = time pressed in millisec.
|
||||
* @PS3_SM_EVENT_RESET_PRESSED: payload.value =
|
||||
* enum ps3_sys_manager_button_event.
|
||||
* @PS3_SM_EVENT_RESET_RELEASED: payload.value = time pressed in millisec.
|
||||
* @PS3_SM_EVENT_THERMAL_ALERT: payload.value = thermal zone id.
|
||||
* @PS3_SM_EVENT_THERMAL_CLEARED: payload.value = thermal zone id.
|
||||
*/
|
||||
|
||||
enum ps3_sys_manager_event {
|
||||
/* version 1 */
|
||||
PS3_SM_EVENT_POWER_PRESSED = 3,
|
||||
PS3_SM_EVENT_POWER_RELEASED = 4,
|
||||
PS3_SM_EVENT_RESET_PRESSED = 5,
|
||||
PS3_SM_EVENT_RESET_RELEASED = 6,
|
||||
PS3_SM_EVENT_THERMAL_ALERT = 7,
|
||||
PS3_SM_EVENT_THERMAL_CLEARED = 8,
|
||||
/* no info on controller events */
|
||||
};
|
||||
|
||||
/**
|
||||
* enum ps3_sys_manager_button_event - Button event payload values.
|
||||
* @PS3_SM_BUTTON_EVENT_HARD: Hardware generated event.
|
||||
* @PS3_SM_BUTTON_EVENT_SOFT: Software generated event.
|
||||
*/
|
||||
|
||||
enum ps3_sys_manager_button_event {
|
||||
PS3_SM_BUTTON_EVENT_HARD = 0,
|
||||
PS3_SM_BUTTON_EVENT_SOFT = 1,
|
||||
};
|
||||
|
||||
/**
|
||||
* enum ps3_sys_manager_next_op - Operation to perform after lpar is destroyed.
|
||||
*/
|
||||
|
||||
enum ps3_sys_manager_next_op {
|
||||
/* version 3 */
|
||||
PS3_SM_NEXT_OP_SYS_SHUTDOWN = 1,
|
||||
PS3_SM_NEXT_OP_SYS_REBOOT = 2,
|
||||
PS3_SM_NEXT_OP_LPAR_REBOOT = 0x82,
|
||||
};
|
||||
|
||||
/**
|
||||
* enum ps3_sys_manager_wake_source - Next-op wakeup source (bit position mask).
|
||||
* @PS3_SM_WAKE_DEFAULT: Disk insert, power button, eject button.
|
||||
* @PS3_SM_WAKE_W_O_L: Ether or wireless LAN.
|
||||
* @PS3_SM_WAKE_P_O_R: Power on reset.
|
||||
*
|
||||
* Additional wakeup sources when specifying PS3_SM_NEXT_OP_SYS_SHUTDOWN.
|
||||
* The system will always wake from the PS3_SM_WAKE_DEFAULT sources.
|
||||
* Sources listed here are the only ones available to guests in the
|
||||
* other-os lpar.
|
||||
*/
|
||||
|
||||
enum ps3_sys_manager_wake_source {
|
||||
/* version 3 */
|
||||
PS3_SM_WAKE_DEFAULT = 0,
|
||||
PS3_SM_WAKE_W_O_L = 0x00000400,
|
||||
PS3_SM_WAKE_P_O_R = 0x80000000,
|
||||
};
|
||||
|
||||
/**
|
||||
* user_wake_sources - User specified wakeup sources.
|
||||
*
|
||||
* Logical OR of enum ps3_sys_manager_wake_source types.
|
||||
*/
|
||||
|
||||
static u32 user_wake_sources = PS3_SM_WAKE_DEFAULT;
|
||||
|
||||
/**
|
||||
* enum ps3_sys_manager_cmd - Command from system manager to guest.
|
||||
*
|
||||
* The guest completes the actions needed, then acks or naks the command via
|
||||
* ps3_sys_manager_send_response(). In the case of @PS3_SM_CMD_SHUTDOWN,
|
||||
* the guest must be fully prepared for a system poweroff prior to acking the
|
||||
* command.
|
||||
*/
|
||||
|
||||
enum ps3_sys_manager_cmd {
|
||||
/* version 1 */
|
||||
PS3_SM_CMD_SHUTDOWN = 1, /* shutdown guest OS */
|
||||
};
|
||||
|
||||
/**
|
||||
* ps3_sm_force_power_off - Poweroff helper.
|
||||
*
|
||||
* A global variable used to force a poweroff when the power button has
|
||||
* been pressed irrespective of how init handles the ctrl_alt_del signal.
|
||||
*
|
||||
*/
|
||||
|
||||
static unsigned int ps3_sm_force_power_off;
|
||||
|
||||
/**
|
||||
* ps3_sys_manager_write - Helper to write a two part message to the vuart.
|
||||
*
|
||||
*/
|
||||
|
||||
static int ps3_sys_manager_write(struct ps3_system_bus_device *dev,
|
||||
const struct ps3_sys_manager_header *header, const void *payload)
|
||||
{
|
||||
int result;
|
||||
|
||||
BUG_ON(header->version != 1);
|
||||
BUG_ON(header->size != 16);
|
||||
BUG_ON(header->payload_size != 8 && header->payload_size != 16);
|
||||
BUG_ON(header->service_id > 8);
|
||||
|
||||
result = ps3_vuart_write(dev, header,
|
||||
sizeof(struct ps3_sys_manager_header));
|
||||
|
||||
if (!result)
|
||||
result = ps3_vuart_write(dev, payload, header->payload_size);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* ps3_sys_manager_send_attr - Send a 'set attribute' to the system manager.
|
||||
*
|
||||
*/
|
||||
|
||||
static int ps3_sys_manager_send_attr(struct ps3_system_bus_device *dev,
|
||||
enum ps3_sys_manager_attr attr)
|
||||
{
|
||||
struct ps3_sys_manager_header header;
|
||||
struct {
|
||||
u8 version;
|
||||
u8 reserved_1[3];
|
||||
u32 attribute;
|
||||
} payload;
|
||||
|
||||
BUILD_BUG_ON(sizeof(payload) != 8);
|
||||
|
||||
dev_dbg(&dev->core, "%s:%d: %xh\n", __func__, __LINE__, attr);
|
||||
|
||||
memset(&header, 0, sizeof(header));
|
||||
header.version = 1;
|
||||
header.size = 16;
|
||||
header.payload_size = 16;
|
||||
header.service_id = PS3_SM_SERVICE_ID_SET_ATTR;
|
||||
|
||||
memset(&payload, 0, sizeof(payload));
|
||||
payload.version = 1;
|
||||
payload.attribute = attr;
|
||||
|
||||
return ps3_sys_manager_write(dev, &header, &payload);
|
||||
}
|
||||
|
||||
/**
|
||||
* ps3_sys_manager_send_next_op - Send a 'set next op' to the system manager.
|
||||
*
|
||||
* Tell the system manager what to do after this lpar is destroyed.
|
||||
*/
|
||||
|
||||
static int ps3_sys_manager_send_next_op(struct ps3_system_bus_device *dev,
|
||||
enum ps3_sys_manager_next_op op,
|
||||
enum ps3_sys_manager_wake_source wake_source)
|
||||
{
|
||||
struct ps3_sys_manager_header header;
|
||||
struct {
|
||||
u8 version;
|
||||
u8 type;
|
||||
u8 gos_id;
|
||||
u8 reserved_1;
|
||||
u32 wake_source;
|
||||
u8 reserved_2[8];
|
||||
} payload;
|
||||
|
||||
BUILD_BUG_ON(sizeof(payload) != 16);
|
||||
|
||||
dev_dbg(&dev->core, "%s:%d: (%xh)\n", __func__, __LINE__, op);
|
||||
|
||||
memset(&header, 0, sizeof(header));
|
||||
header.version = 1;
|
||||
header.size = 16;
|
||||
header.payload_size = 16;
|
||||
header.service_id = PS3_SM_SERVICE_ID_SET_NEXT_OP;
|
||||
|
||||
memset(&payload, 0, sizeof(payload));
|
||||
payload.version = 3;
|
||||
payload.type = op;
|
||||
payload.gos_id = 3; /* other os */
|
||||
payload.wake_source = wake_source;
|
||||
|
||||
return ps3_sys_manager_write(dev, &header, &payload);
|
||||
}
|
||||
|
||||
/**
|
||||
* ps3_sys_manager_send_request_shutdown - Send 'request' to the system manager.
|
||||
*
|
||||
* The guest sends this message to request an operation or action of the system
|
||||
* manager. The reply is a command message from the system manager. In the
|
||||
* command handler the guest performs the requested operation. The result of
|
||||
* the command is then communicated back to the system manager with a response
|
||||
* message.
|
||||
*
|
||||
* Currently, the only supported request is the 'shutdown self' request.
|
||||
*/
|
||||
|
||||
static int ps3_sys_manager_send_request_shutdown(
|
||||
struct ps3_system_bus_device *dev)
|
||||
{
|
||||
struct ps3_sys_manager_header header;
|
||||
struct {
|
||||
u8 version;
|
||||
u8 type;
|
||||
u8 gos_id;
|
||||
u8 reserved_1[13];
|
||||
} payload;
|
||||
|
||||
BUILD_BUG_ON(sizeof(payload) != 16);
|
||||
|
||||
dev_dbg(&dev->core, "%s:%d\n", __func__, __LINE__);
|
||||
|
||||
memset(&header, 0, sizeof(header));
|
||||
header.version = 1;
|
||||
header.size = 16;
|
||||
header.payload_size = 16;
|
||||
header.service_id = PS3_SM_SERVICE_ID_REQUEST;
|
||||
|
||||
memset(&payload, 0, sizeof(payload));
|
||||
payload.version = 1;
|
||||
payload.type = 1; /* shutdown */
|
||||
payload.gos_id = 0; /* self */
|
||||
|
||||
return ps3_sys_manager_write(dev, &header, &payload);
|
||||
}
|
||||
|
||||
/**
|
||||
* ps3_sys_manager_send_response - Send a 'response' to the system manager.
|
||||
* @status: zero = success, others fail.
|
||||
*
|
||||
* The guest sends this message to the system manager to acnowledge success or
|
||||
* failure of a command sent by the system manager.
|
||||
*/
|
||||
|
||||
static int ps3_sys_manager_send_response(struct ps3_system_bus_device *dev,
|
||||
u64 status)
|
||||
{
|
||||
struct ps3_sys_manager_header header;
|
||||
struct {
|
||||
u8 version;
|
||||
u8 reserved_1[3];
|
||||
u8 status;
|
||||
u8 reserved_2[11];
|
||||
} payload;
|
||||
|
||||
BUILD_BUG_ON(sizeof(payload) != 16);
|
||||
|
||||
dev_dbg(&dev->core, "%s:%d: (%s)\n", __func__, __LINE__,
|
||||
(status ? "nak" : "ack"));
|
||||
|
||||
memset(&header, 0, sizeof(header));
|
||||
header.version = 1;
|
||||
header.size = 16;
|
||||
header.payload_size = 16;
|
||||
header.service_id = PS3_SM_SERVICE_ID_RESPONSE;
|
||||
|
||||
memset(&payload, 0, sizeof(payload));
|
||||
payload.version = 1;
|
||||
payload.status = status;
|
||||
|
||||
return ps3_sys_manager_write(dev, &header, &payload);
|
||||
}
|
||||
|
||||
/**
|
||||
* ps3_sys_manager_handle_event - Second stage event msg handler.
|
||||
*
|
||||
*/
|
||||
|
||||
static int ps3_sys_manager_handle_event(struct ps3_system_bus_device *dev)
|
||||
{
|
||||
int result;
|
||||
struct {
|
||||
u8 version;
|
||||
u8 type;
|
||||
u8 reserved_1[2];
|
||||
u32 value;
|
||||
u8 reserved_2[8];
|
||||
} event;
|
||||
|
||||
BUILD_BUG_ON(sizeof(event) != 16);
|
||||
|
||||
result = ps3_vuart_read(dev, &event, sizeof(event));
|
||||
BUG_ON(result && "need to retry here");
|
||||
|
||||
if (event.version != 1) {
|
||||
dev_dbg(&dev->core, "%s:%d: unsupported event version (%u)\n",
|
||||
__func__, __LINE__, event.version);
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
switch (event.type) {
|
||||
case PS3_SM_EVENT_POWER_PRESSED:
|
||||
dev_dbg(&dev->core, "%s:%d: POWER_PRESSED (%s)\n",
|
||||
__func__, __LINE__,
|
||||
(event.value == PS3_SM_BUTTON_EVENT_SOFT ? "soft"
|
||||
: "hard"));
|
||||
ps3_sm_force_power_off = 1;
|
||||
/*
|
||||
* A memory barrier is use here to sync memory since
|
||||
* ps3_sys_manager_final_restart() could be called on
|
||||
* another cpu.
|
||||
*/
|
||||
wmb();
|
||||
kill_cad_pid(SIGINT, 1); /* ctrl_alt_del */
|
||||
break;
|
||||
case PS3_SM_EVENT_POWER_RELEASED:
|
||||
dev_dbg(&dev->core, "%s:%d: POWER_RELEASED (%u ms)\n",
|
||||
__func__, __LINE__, event.value);
|
||||
break;
|
||||
case PS3_SM_EVENT_RESET_PRESSED:
|
||||
dev_dbg(&dev->core, "%s:%d: RESET_PRESSED (%s)\n",
|
||||
__func__, __LINE__,
|
||||
(event.value == PS3_SM_BUTTON_EVENT_SOFT ? "soft"
|
||||
: "hard"));
|
||||
ps3_sm_force_power_off = 0;
|
||||
/*
|
||||
* A memory barrier is use here to sync memory since
|
||||
* ps3_sys_manager_final_restart() could be called on
|
||||
* another cpu.
|
||||
*/
|
||||
wmb();
|
||||
kill_cad_pid(SIGINT, 1); /* ctrl_alt_del */
|
||||
break;
|
||||
case PS3_SM_EVENT_RESET_RELEASED:
|
||||
dev_dbg(&dev->core, "%s:%d: RESET_RELEASED (%u ms)\n",
|
||||
__func__, __LINE__, event.value);
|
||||
break;
|
||||
case PS3_SM_EVENT_THERMAL_ALERT:
|
||||
dev_dbg(&dev->core, "%s:%d: THERMAL_ALERT (zone %u)\n",
|
||||
__func__, __LINE__, event.value);
|
||||
pr_info("PS3 Thermal Alert Zone %u\n", event.value);
|
||||
break;
|
||||
case PS3_SM_EVENT_THERMAL_CLEARED:
|
||||
dev_dbg(&dev->core, "%s:%d: THERMAL_CLEARED (zone %u)\n",
|
||||
__func__, __LINE__, event.value);
|
||||
break;
|
||||
default:
|
||||
dev_dbg(&dev->core, "%s:%d: unknown event (%u)\n",
|
||||
__func__, __LINE__, event.type);
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
/**
|
||||
* ps3_sys_manager_handle_cmd - Second stage command msg handler.
|
||||
*
|
||||
* The system manager sends this in reply to a 'request' message from the guest.
|
||||
*/
|
||||
|
||||
static int ps3_sys_manager_handle_cmd(struct ps3_system_bus_device *dev)
|
||||
{
|
||||
int result;
|
||||
struct {
|
||||
u8 version;
|
||||
u8 type;
|
||||
u8 reserved_1[14];
|
||||
} cmd;
|
||||
|
||||
BUILD_BUG_ON(sizeof(cmd) != 16);
|
||||
|
||||
dev_dbg(&dev->core, "%s:%d\n", __func__, __LINE__);
|
||||
|
||||
result = ps3_vuart_read(dev, &cmd, sizeof(cmd));
|
||||
BUG_ON(result && "need to retry here");
|
||||
|
||||
if (result)
|
||||
return result;
|
||||
|
||||
if (cmd.version != 1) {
|
||||
dev_dbg(&dev->core, "%s:%d: unsupported cmd version (%u)\n",
|
||||
__func__, __LINE__, cmd.version);
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
if (cmd.type != PS3_SM_CMD_SHUTDOWN) {
|
||||
dev_dbg(&dev->core, "%s:%d: unknown cmd (%u)\n",
|
||||
__func__, __LINE__, cmd.type);
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
ps3_sys_manager_send_response(dev, 0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* ps3_sys_manager_handle_msg - First stage msg handler.
|
||||
*
|
||||
* Can be called directly to manually poll vuart and pump message handler.
|
||||
*/
|
||||
|
||||
static int ps3_sys_manager_handle_msg(struct ps3_system_bus_device *dev)
|
||||
{
|
||||
int result;
|
||||
struct ps3_sys_manager_header header;
|
||||
|
||||
result = ps3_vuart_read(dev, &header,
|
||||
sizeof(struct ps3_sys_manager_header));
|
||||
|
||||
if (result)
|
||||
return result;
|
||||
|
||||
if (header.version != 1) {
|
||||
dev_dbg(&dev->core, "%s:%d: unsupported header version (%u)\n",
|
||||
__func__, __LINE__, header.version);
|
||||
dump_sm_header(&header);
|
||||
goto fail_header;
|
||||
}
|
||||
|
||||
BUILD_BUG_ON(sizeof(header) != 16);
|
||||
|
||||
if (header.size != 16 || (header.payload_size != 8
|
||||
&& header.payload_size != 16)) {
|
||||
dump_sm_header(&header);
|
||||
BUG();
|
||||
}
|
||||
|
||||
switch (header.service_id) {
|
||||
case PS3_SM_SERVICE_ID_EXTERN_EVENT:
|
||||
dev_dbg(&dev->core, "%s:%d: EVENT\n", __func__, __LINE__);
|
||||
return ps3_sys_manager_handle_event(dev);
|
||||
case PS3_SM_SERVICE_ID_COMMAND:
|
||||
dev_dbg(&dev->core, "%s:%d: COMMAND\n", __func__, __LINE__);
|
||||
return ps3_sys_manager_handle_cmd(dev);
|
||||
case PS3_SM_SERVICE_ID_REQUEST_ERROR:
|
||||
dev_dbg(&dev->core, "%s:%d: REQUEST_ERROR\n", __func__,
|
||||
__LINE__);
|
||||
dump_sm_header(&header);
|
||||
break;
|
||||
default:
|
||||
dev_dbg(&dev->core, "%s:%d: unknown service_id (%u)\n",
|
||||
__func__, __LINE__, header.service_id);
|
||||
break;
|
||||
}
|
||||
goto fail_id;
|
||||
|
||||
fail_header:
|
||||
ps3_vuart_clear_rx_bytes(dev, 0);
|
||||
return -EIO;
|
||||
fail_id:
|
||||
ps3_vuart_clear_rx_bytes(dev, header.payload_size);
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
static void ps3_sys_manager_fin(struct ps3_system_bus_device *dev)
|
||||
{
|
||||
ps3_sys_manager_send_request_shutdown(dev);
|
||||
|
||||
pr_emerg("System Halted, OK to turn off power\n");
|
||||
|
||||
while (ps3_sys_manager_handle_msg(dev)) {
|
||||
/* pause until next DEC interrupt */
|
||||
lv1_pause(0);
|
||||
}
|
||||
|
||||
while (1) {
|
||||
/* pause, ignoring DEC interrupt */
|
||||
lv1_pause(1);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* ps3_sys_manager_final_power_off - The final platform machine_power_off routine.
|
||||
*
|
||||
* This routine never returns. The routine disables asynchronous vuart reads
|
||||
* then spins calling ps3_sys_manager_handle_msg() to receive and acknowledge
|
||||
* the shutdown command sent from the system manager. Soon after the
|
||||
* acknowledgement is sent the lpar is destroyed by the HV. This routine
|
||||
* should only be called from ps3_power_off() through
|
||||
* ps3_sys_manager_ops.power_off.
|
||||
*/
|
||||
|
||||
static void ps3_sys_manager_final_power_off(struct ps3_system_bus_device *dev)
|
||||
{
|
||||
BUG_ON(!dev);
|
||||
|
||||
dev_dbg(&dev->core, "%s:%d\n", __func__, __LINE__);
|
||||
|
||||
ps3_vuart_cancel_async(dev);
|
||||
|
||||
ps3_sys_manager_send_next_op(dev, PS3_SM_NEXT_OP_SYS_SHUTDOWN,
|
||||
user_wake_sources);
|
||||
|
||||
ps3_sys_manager_fin(dev);
|
||||
}
|
||||
|
||||
/**
|
||||
* ps3_sys_manager_final_restart - The final platform machine_restart routine.
|
||||
*
|
||||
* This routine never returns. The routine disables asynchronous vuart reads
|
||||
* then spins calling ps3_sys_manager_handle_msg() to receive and acknowledge
|
||||
* the shutdown command sent from the system manager. Soon after the
|
||||
* acknowledgement is sent the lpar is destroyed by the HV. This routine
|
||||
* should only be called from ps3_restart() through ps3_sys_manager_ops.restart.
|
||||
*/
|
||||
|
||||
static void ps3_sys_manager_final_restart(struct ps3_system_bus_device *dev)
|
||||
{
|
||||
BUG_ON(!dev);
|
||||
|
||||
dev_dbg(&dev->core, "%s:%d\n", __func__, __LINE__);
|
||||
|
||||
/* Check if we got here via a power button event. */
|
||||
|
||||
if (ps3_sm_force_power_off) {
|
||||
dev_dbg(&dev->core, "%s:%d: forcing poweroff\n",
|
||||
__func__, __LINE__);
|
||||
ps3_sys_manager_final_power_off(dev);
|
||||
}
|
||||
|
||||
ps3_vuart_cancel_async(dev);
|
||||
|
||||
ps3_sys_manager_send_attr(dev, 0);
|
||||
ps3_sys_manager_send_next_op(dev, PS3_SM_NEXT_OP_SYS_REBOOT,
|
||||
user_wake_sources);
|
||||
|
||||
ps3_sys_manager_fin(dev);
|
||||
}
|
||||
|
||||
/**
|
||||
* ps3_sys_manager_get_wol - Get wake-on-lan setting.
|
||||
*/
|
||||
|
||||
int ps3_sys_manager_get_wol(void)
|
||||
{
|
||||
pr_debug("%s:%d\n", __func__, __LINE__);
|
||||
|
||||
return (user_wake_sources & PS3_SM_WAKE_W_O_L) != 0;
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(ps3_sys_manager_get_wol);
|
||||
|
||||
/**
|
||||
* ps3_sys_manager_set_wol - Set wake-on-lan setting.
|
||||
*/
|
||||
|
||||
void ps3_sys_manager_set_wol(int state)
|
||||
{
|
||||
static DEFINE_MUTEX(mutex);
|
||||
|
||||
mutex_lock(&mutex);
|
||||
|
||||
pr_debug("%s:%d: %d\n", __func__, __LINE__, state);
|
||||
|
||||
if (state)
|
||||
user_wake_sources |= PS3_SM_WAKE_W_O_L;
|
||||
else
|
||||
user_wake_sources &= ~PS3_SM_WAKE_W_O_L;
|
||||
mutex_unlock(&mutex);
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(ps3_sys_manager_set_wol);
|
||||
|
||||
/**
|
||||
* ps3_sys_manager_work - Asynchronous read handler.
|
||||
*
|
||||
* Signaled when PS3_SM_RX_MSG_LEN_MIN bytes arrive at the vuart port.
|
||||
*/
|
||||
|
||||
static void ps3_sys_manager_work(struct ps3_system_bus_device *dev)
|
||||
{
|
||||
ps3_sys_manager_handle_msg(dev);
|
||||
ps3_vuart_read_async(dev, PS3_SM_RX_MSG_LEN_MIN);
|
||||
}
|
||||
|
||||
static int ps3_sys_manager_probe(struct ps3_system_bus_device *dev)
|
||||
{
|
||||
int result;
|
||||
struct ps3_sys_manager_ops ops;
|
||||
|
||||
dev_dbg(&dev->core, "%s:%d\n", __func__, __LINE__);
|
||||
|
||||
ops.power_off = ps3_sys_manager_final_power_off;
|
||||
ops.restart = ps3_sys_manager_final_restart;
|
||||
ops.dev = dev;
|
||||
|
||||
/* ps3_sys_manager_register_ops copies ops. */
|
||||
|
||||
ps3_sys_manager_register_ops(&ops);
|
||||
|
||||
result = ps3_sys_manager_send_attr(dev, PS3_SM_ATTR_ALL);
|
||||
BUG_ON(result);
|
||||
|
||||
result = ps3_vuart_read_async(dev, PS3_SM_RX_MSG_LEN_MIN);
|
||||
BUG_ON(result);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static int ps3_sys_manager_remove(struct ps3_system_bus_device *dev)
|
||||
{
|
||||
dev_dbg(&dev->core, "%s:%d\n", __func__, __LINE__);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void ps3_sys_manager_shutdown(struct ps3_system_bus_device *dev)
|
||||
{
|
||||
dev_dbg(&dev->core, "%s:%d\n", __func__, __LINE__);
|
||||
}
|
||||
|
||||
static struct ps3_vuart_port_driver ps3_sys_manager = {
|
||||
.core.match_id = PS3_MATCH_ID_SYSTEM_MANAGER,
|
||||
.core.core.name = "ps3_sys_manager",
|
||||
.probe = ps3_sys_manager_probe,
|
||||
.remove = ps3_sys_manager_remove,
|
||||
.shutdown = ps3_sys_manager_shutdown,
|
||||
.work = ps3_sys_manager_work,
|
||||
};
|
||||
|
||||
static int __init ps3_sys_manager_init(void)
|
||||
{
|
||||
if (!firmware_has_feature(FW_FEATURE_PS3_LV1))
|
||||
return -ENODEV;
|
||||
|
||||
return ps3_vuart_port_driver_register(&ps3_sys_manager);
|
||||
}
|
||||
|
||||
module_init(ps3_sys_manager_init);
|
||||
/* Module remove not supported. */
|
||||
|
||||
MODULE_AUTHOR("Sony Corporation");
|
||||
MODULE_LICENSE("GPL v2");
|
||||
MODULE_DESCRIPTION("PS3 System Manager");
|
||||
MODULE_ALIAS(PS3_MODULE_ALIAS_SYSTEM_MANAGER);
|
1269
drivers/ps3/ps3-vuart.c
Normal file
1269
drivers/ps3/ps3-vuart.c
Normal file
File diff suppressed because it is too large
Load diff
1080
drivers/ps3/ps3av.c
Normal file
1080
drivers/ps3/ps3av.c
Normal file
File diff suppressed because it is too large
Load diff
936
drivers/ps3/ps3av_cmd.c
Normal file
936
drivers/ps3/ps3av_cmd.c
Normal file
|
@ -0,0 +1,936 @@
|
|||
/*
|
||||
* Copyright (C) 2006 Sony Computer Entertainment Inc.
|
||||
* Copyright 2006, 2007 Sony Corporation
|
||||
*
|
||||
* AV backend support for PS3
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published
|
||||
* by the Free Software Foundation; version 2 of the License.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
#include <linux/module.h>
|
||||
#include <linux/kernel.h>
|
||||
#include <linux/delay.h>
|
||||
|
||||
#include <asm/ps3av.h>
|
||||
#include <asm/ps3.h>
|
||||
#include <asm/ps3gpu.h>
|
||||
|
||||
#include "vuart.h"
|
||||
|
||||
static const struct video_fmt {
|
||||
u32 format;
|
||||
u32 order;
|
||||
} ps3av_video_fmt_table[] = {
|
||||
{ PS3AV_CMD_VIDEO_FORMAT_ARGB_8BIT, PS3AV_CMD_VIDEO_ORDER_RGB },
|
||||
{ PS3AV_CMD_VIDEO_FORMAT_ARGB_8BIT, PS3AV_CMD_VIDEO_ORDER_BGR },
|
||||
};
|
||||
|
||||
static const struct {
|
||||
int cs;
|
||||
u32 av;
|
||||
u32 bl;
|
||||
} ps3av_cs_video2av_table[] = {
|
||||
{
|
||||
.cs = PS3AV_CMD_VIDEO_CS_RGB_8,
|
||||
.av = PS3AV_CMD_AV_CS_RGB_8,
|
||||
.bl = PS3AV_CMD_AV_CS_8
|
||||
}, {
|
||||
.cs = PS3AV_CMD_VIDEO_CS_RGB_10,
|
||||
.av = PS3AV_CMD_AV_CS_RGB_8,
|
||||
.bl = PS3AV_CMD_AV_CS_8
|
||||
}, {
|
||||
.cs = PS3AV_CMD_VIDEO_CS_RGB_12,
|
||||
.av = PS3AV_CMD_AV_CS_RGB_8,
|
||||
.bl = PS3AV_CMD_AV_CS_8
|
||||
}, {
|
||||
.cs = PS3AV_CMD_VIDEO_CS_YUV444_8,
|
||||
.av = PS3AV_CMD_AV_CS_YUV444_8,
|
||||
.bl = PS3AV_CMD_AV_CS_8
|
||||
}, {
|
||||
.cs = PS3AV_CMD_VIDEO_CS_YUV444_10,
|
||||
.av = PS3AV_CMD_AV_CS_YUV444_8,
|
||||
.bl = PS3AV_CMD_AV_CS_10
|
||||
}, {
|
||||
.cs = PS3AV_CMD_VIDEO_CS_YUV444_12,
|
||||
.av = PS3AV_CMD_AV_CS_YUV444_8,
|
||||
.bl = PS3AV_CMD_AV_CS_10
|
||||
}, {
|
||||
.cs = PS3AV_CMD_VIDEO_CS_YUV422_8,
|
||||
.av = PS3AV_CMD_AV_CS_YUV422_8,
|
||||
.bl = PS3AV_CMD_AV_CS_10
|
||||
}, {
|
||||
.cs = PS3AV_CMD_VIDEO_CS_YUV422_10,
|
||||
.av = PS3AV_CMD_AV_CS_YUV422_8,
|
||||
.bl = PS3AV_CMD_AV_CS_10
|
||||
}, {
|
||||
.cs = PS3AV_CMD_VIDEO_CS_YUV422_12,
|
||||
.av = PS3AV_CMD_AV_CS_YUV422_8,
|
||||
.bl = PS3AV_CMD_AV_CS_12
|
||||
}, {
|
||||
.cs = PS3AV_CMD_VIDEO_CS_XVYCC_8,
|
||||
.av = PS3AV_CMD_AV_CS_XVYCC_8,
|
||||
.bl = PS3AV_CMD_AV_CS_12
|
||||
}, {
|
||||
.cs = PS3AV_CMD_VIDEO_CS_XVYCC_10,
|
||||
.av = PS3AV_CMD_AV_CS_XVYCC_8,
|
||||
.bl = PS3AV_CMD_AV_CS_12
|
||||
}, {
|
||||
.cs = PS3AV_CMD_VIDEO_CS_XVYCC_12,
|
||||
.av = PS3AV_CMD_AV_CS_XVYCC_8,
|
||||
.bl = PS3AV_CMD_AV_CS_12
|
||||
}
|
||||
};
|
||||
|
||||
static u32 ps3av_cs_video2av(int cs)
|
||||
{
|
||||
unsigned int i;
|
||||
|
||||
for (i = 0; i < ARRAY_SIZE(ps3av_cs_video2av_table); i++)
|
||||
if (ps3av_cs_video2av_table[i].cs == cs)
|
||||
return ps3av_cs_video2av_table[i].av;
|
||||
|
||||
return PS3AV_CMD_AV_CS_RGB_8;
|
||||
}
|
||||
|
||||
static u32 ps3av_cs_video2av_bitlen(int cs)
|
||||
{
|
||||
unsigned int i;
|
||||
|
||||
for (i = 0; i < ARRAY_SIZE(ps3av_cs_video2av_table); i++)
|
||||
if (ps3av_cs_video2av_table[i].cs == cs)
|
||||
return ps3av_cs_video2av_table[i].bl;
|
||||
|
||||
return PS3AV_CMD_AV_CS_8;
|
||||
}
|
||||
|
||||
static const struct {
|
||||
int vid;
|
||||
u32 av;
|
||||
} ps3av_vid_video2av_table[] = {
|
||||
{ PS3AV_CMD_VIDEO_VID_480I, PS3AV_CMD_AV_VID_480I },
|
||||
{ PS3AV_CMD_VIDEO_VID_480P, PS3AV_CMD_AV_VID_480P },
|
||||
{ PS3AV_CMD_VIDEO_VID_576I, PS3AV_CMD_AV_VID_576I },
|
||||
{ PS3AV_CMD_VIDEO_VID_576P, PS3AV_CMD_AV_VID_576P },
|
||||
{ PS3AV_CMD_VIDEO_VID_1080I_60HZ, PS3AV_CMD_AV_VID_1080I_60HZ },
|
||||
{ PS3AV_CMD_VIDEO_VID_720P_60HZ, PS3AV_CMD_AV_VID_720P_60HZ },
|
||||
{ PS3AV_CMD_VIDEO_VID_1080P_60HZ, PS3AV_CMD_AV_VID_1080P_60HZ },
|
||||
{ PS3AV_CMD_VIDEO_VID_1080I_50HZ, PS3AV_CMD_AV_VID_1080I_50HZ },
|
||||
{ PS3AV_CMD_VIDEO_VID_720P_50HZ, PS3AV_CMD_AV_VID_720P_50HZ },
|
||||
{ PS3AV_CMD_VIDEO_VID_1080P_50HZ, PS3AV_CMD_AV_VID_1080P_50HZ },
|
||||
{ PS3AV_CMD_VIDEO_VID_WXGA, PS3AV_CMD_AV_VID_WXGA },
|
||||
{ PS3AV_CMD_VIDEO_VID_SXGA, PS3AV_CMD_AV_VID_SXGA },
|
||||
{ PS3AV_CMD_VIDEO_VID_WUXGA, PS3AV_CMD_AV_VID_WUXGA }
|
||||
};
|
||||
|
||||
static u32 ps3av_vid_video2av(int vid)
|
||||
{
|
||||
unsigned int i;
|
||||
|
||||
for (i = 0; i < ARRAY_SIZE(ps3av_vid_video2av_table); i++)
|
||||
if (ps3av_vid_video2av_table[i].vid == vid)
|
||||
return ps3av_vid_video2av_table[i].av;
|
||||
|
||||
return PS3AV_CMD_AV_VID_480P;
|
||||
}
|
||||
|
||||
static int ps3av_hdmi_range(void)
|
||||
{
|
||||
if (ps3_compare_firmware_version(1, 8, 0) < 0)
|
||||
return 0;
|
||||
else
|
||||
return 1; /* supported */
|
||||
}
|
||||
|
||||
int ps3av_cmd_init(void)
|
||||
{
|
||||
int res;
|
||||
struct ps3av_pkt_av_init av_init;
|
||||
struct ps3av_pkt_video_init video_init;
|
||||
struct ps3av_pkt_audio_init audio_init;
|
||||
|
||||
/* video init */
|
||||
memset(&video_init, 0, sizeof(video_init));
|
||||
|
||||
res = ps3av_do_pkt(PS3AV_CID_VIDEO_INIT, sizeof(video_init.send_hdr),
|
||||
sizeof(video_init), &video_init.send_hdr);
|
||||
if (res < 0)
|
||||
return res;
|
||||
|
||||
res = get_status(&video_init);
|
||||
if (res) {
|
||||
printk(KERN_ERR "PS3AV_CID_VIDEO_INIT: failed %x\n", res);
|
||||
return res;
|
||||
}
|
||||
|
||||
/* audio init */
|
||||
memset(&audio_init, 0, sizeof(audio_init));
|
||||
|
||||
res = ps3av_do_pkt(PS3AV_CID_AUDIO_INIT, sizeof(audio_init.send_hdr),
|
||||
sizeof(audio_init), &audio_init.send_hdr);
|
||||
if (res < 0)
|
||||
return res;
|
||||
|
||||
res = get_status(&audio_init);
|
||||
if (res) {
|
||||
printk(KERN_ERR "PS3AV_CID_AUDIO_INIT: failed %x\n", res);
|
||||
return res;
|
||||
}
|
||||
|
||||
/* av init */
|
||||
memset(&av_init, 0, sizeof(av_init));
|
||||
av_init.event_bit = 0;
|
||||
|
||||
res = ps3av_do_pkt(PS3AV_CID_AV_INIT, sizeof(av_init), sizeof(av_init),
|
||||
&av_init.send_hdr);
|
||||
if (res < 0)
|
||||
return res;
|
||||
|
||||
res = get_status(&av_init);
|
||||
if (res)
|
||||
printk(KERN_ERR "PS3AV_CID_AV_INIT: failed %x\n", res);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
int ps3av_cmd_fin(void)
|
||||
{
|
||||
int res;
|
||||
struct ps3av_pkt_av_fin av_fin;
|
||||
|
||||
memset(&av_fin, 0, sizeof(av_fin));
|
||||
|
||||
res = ps3av_do_pkt(PS3AV_CID_AV_FIN, sizeof(av_fin.send_hdr),
|
||||
sizeof(av_fin), &av_fin.send_hdr);
|
||||
if (res < 0)
|
||||
return res;
|
||||
|
||||
res = get_status(&av_fin);
|
||||
if (res)
|
||||
printk(KERN_ERR "PS3AV_CID_AV_FIN: failed %x\n", res);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
int ps3av_cmd_av_video_mute(int num_of_port, u32 *port, u32 mute)
|
||||
{
|
||||
int i, send_len, res;
|
||||
struct ps3av_pkt_av_video_mute av_video_mute;
|
||||
|
||||
if (num_of_port > PS3AV_MUTE_PORT_MAX)
|
||||
return -EINVAL;
|
||||
|
||||
memset(&av_video_mute, 0, sizeof(av_video_mute));
|
||||
for (i = 0; i < num_of_port; i++) {
|
||||
av_video_mute.mute[i].avport = port[i];
|
||||
av_video_mute.mute[i].mute = mute;
|
||||
}
|
||||
|
||||
send_len = sizeof(av_video_mute.send_hdr) +
|
||||
sizeof(struct ps3av_av_mute) * num_of_port;
|
||||
res = ps3av_do_pkt(PS3AV_CID_AV_VIDEO_MUTE, send_len,
|
||||
sizeof(av_video_mute), &av_video_mute.send_hdr);
|
||||
if (res < 0)
|
||||
return res;
|
||||
|
||||
res = get_status(&av_video_mute);
|
||||
if (res)
|
||||
printk(KERN_ERR "PS3AV_CID_AV_VIDEO_MUTE: failed %x\n", res);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
int ps3av_cmd_av_video_disable_sig(u32 port)
|
||||
{
|
||||
int res;
|
||||
struct ps3av_pkt_av_video_disable_sig av_video_sig;
|
||||
|
||||
memset(&av_video_sig, 0, sizeof(av_video_sig));
|
||||
av_video_sig.avport = port;
|
||||
|
||||
res = ps3av_do_pkt(PS3AV_CID_AV_VIDEO_DISABLE_SIG,
|
||||
sizeof(av_video_sig), sizeof(av_video_sig),
|
||||
&av_video_sig.send_hdr);
|
||||
if (res < 0)
|
||||
return res;
|
||||
|
||||
res = get_status(&av_video_sig);
|
||||
if (res)
|
||||
printk(KERN_ERR
|
||||
"PS3AV_CID_AV_VIDEO_DISABLE_SIG: failed %x port:%x\n",
|
||||
res, port);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
int ps3av_cmd_av_tv_mute(u32 avport, u32 mute)
|
||||
{
|
||||
int res;
|
||||
struct ps3av_pkt_av_tv_mute tv_mute;
|
||||
|
||||
memset(&tv_mute, 0, sizeof(tv_mute));
|
||||
tv_mute.avport = avport;
|
||||
tv_mute.mute = mute;
|
||||
|
||||
res = ps3av_do_pkt(PS3AV_CID_AV_TV_MUTE, sizeof(tv_mute),
|
||||
sizeof(tv_mute), &tv_mute.send_hdr);
|
||||
if (res < 0)
|
||||
return res;
|
||||
|
||||
res = get_status(&tv_mute);
|
||||
if (res)
|
||||
printk(KERN_ERR "PS3AV_CID_AV_TV_MUTE: failed %x port:%x\n",
|
||||
res, avport);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
int ps3av_cmd_enable_event(void)
|
||||
{
|
||||
int res;
|
||||
struct ps3av_pkt_av_event av_event;
|
||||
|
||||
memset(&av_event, 0, sizeof(av_event));
|
||||
av_event.event_bit = PS3AV_CMD_EVENT_BIT_UNPLUGGED |
|
||||
PS3AV_CMD_EVENT_BIT_PLUGGED | PS3AV_CMD_EVENT_BIT_HDCP_DONE;
|
||||
|
||||
res = ps3av_do_pkt(PS3AV_CID_AV_ENABLE_EVENT, sizeof(av_event),
|
||||
sizeof(av_event), &av_event.send_hdr);
|
||||
if (res < 0)
|
||||
return res;
|
||||
|
||||
res = get_status(&av_event);
|
||||
if (res)
|
||||
printk(KERN_ERR "PS3AV_CID_AV_ENABLE_EVENT: failed %x\n", res);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
int ps3av_cmd_av_hdmi_mode(u8 mode)
|
||||
{
|
||||
int res;
|
||||
struct ps3av_pkt_av_hdmi_mode hdmi_mode;
|
||||
|
||||
memset(&hdmi_mode, 0, sizeof(hdmi_mode));
|
||||
hdmi_mode.mode = mode;
|
||||
|
||||
res = ps3av_do_pkt(PS3AV_CID_AV_HDMI_MODE, sizeof(hdmi_mode),
|
||||
sizeof(hdmi_mode), &hdmi_mode.send_hdr);
|
||||
if (res < 0)
|
||||
return res;
|
||||
|
||||
res = get_status(&hdmi_mode);
|
||||
if (res && res != PS3AV_STATUS_UNSUPPORTED_HDMI_MODE)
|
||||
printk(KERN_ERR "PS3AV_CID_AV_HDMI_MODE: failed %x\n", res);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
u32 ps3av_cmd_set_av_video_cs(void *p, u32 avport, int video_vid, int cs_out,
|
||||
int aspect, u32 id)
|
||||
{
|
||||
struct ps3av_pkt_av_video_cs *av_video_cs;
|
||||
|
||||
av_video_cs = (struct ps3av_pkt_av_video_cs *)p;
|
||||
if (video_vid == -1)
|
||||
video_vid = PS3AV_CMD_VIDEO_VID_720P_60HZ;
|
||||
if (cs_out == -1)
|
||||
cs_out = PS3AV_CMD_VIDEO_CS_YUV444_8;
|
||||
if (aspect == -1)
|
||||
aspect = 0;
|
||||
|
||||
memset(av_video_cs, 0, sizeof(*av_video_cs));
|
||||
ps3av_set_hdr(PS3AV_CID_AV_VIDEO_CS, sizeof(*av_video_cs),
|
||||
&av_video_cs->send_hdr);
|
||||
av_video_cs->avport = avport;
|
||||
/* should be same as video_mode.resolution */
|
||||
av_video_cs->av_vid = ps3av_vid_video2av(video_vid);
|
||||
av_video_cs->av_cs_out = ps3av_cs_video2av(cs_out);
|
||||
/* should be same as video_mode.video_cs_out */
|
||||
av_video_cs->av_cs_in = ps3av_cs_video2av(PS3AV_CMD_VIDEO_CS_RGB_8);
|
||||
av_video_cs->bitlen_out = ps3av_cs_video2av_bitlen(cs_out);
|
||||
if ((id & PS3AV_MODE_WHITE) && ps3av_hdmi_range())
|
||||
av_video_cs->super_white = PS3AV_CMD_AV_SUPER_WHITE_ON;
|
||||
else /* default off */
|
||||
av_video_cs->super_white = PS3AV_CMD_AV_SUPER_WHITE_OFF;
|
||||
av_video_cs->aspect = aspect;
|
||||
if (id & PS3AV_MODE_DITHER) {
|
||||
av_video_cs->dither = PS3AV_CMD_AV_DITHER_ON
|
||||
| PS3AV_CMD_AV_DITHER_8BIT;
|
||||
} else {
|
||||
/* default off */
|
||||
av_video_cs->dither = PS3AV_CMD_AV_DITHER_OFF;
|
||||
}
|
||||
|
||||
return sizeof(*av_video_cs);
|
||||
}
|
||||
|
||||
u32 ps3av_cmd_set_video_mode(void *p, u32 head, int video_vid, int video_fmt,
|
||||
u32 id)
|
||||
{
|
||||
struct ps3av_pkt_video_mode *video_mode;
|
||||
u32 x, y;
|
||||
|
||||
video_mode = (struct ps3av_pkt_video_mode *)p;
|
||||
if (video_vid == -1)
|
||||
video_vid = PS3AV_CMD_VIDEO_VID_720P_60HZ;
|
||||
if (video_fmt == -1)
|
||||
video_fmt = PS3AV_CMD_VIDEO_FMT_X8R8G8B8;
|
||||
|
||||
if (ps3av_video_mode2res(id, &x, &y))
|
||||
return 0;
|
||||
|
||||
/* video mode */
|
||||
memset(video_mode, 0, sizeof(*video_mode));
|
||||
ps3av_set_hdr(PS3AV_CID_VIDEO_MODE, sizeof(*video_mode),
|
||||
&video_mode->send_hdr);
|
||||
video_mode->video_head = head;
|
||||
if (video_vid == PS3AV_CMD_VIDEO_VID_480I
|
||||
&& head == PS3AV_CMD_VIDEO_HEAD_B)
|
||||
video_mode->video_vid = PS3AV_CMD_VIDEO_VID_480I_A;
|
||||
else
|
||||
video_mode->video_vid = video_vid;
|
||||
video_mode->width = (u16) x;
|
||||
video_mode->height = (u16) y;
|
||||
video_mode->pitch = video_mode->width * 4; /* line_length */
|
||||
video_mode->video_out_format = PS3AV_CMD_VIDEO_OUT_FORMAT_RGB_12BIT;
|
||||
video_mode->video_format = ps3av_video_fmt_table[video_fmt].format;
|
||||
if ((id & PS3AV_MODE_COLOR) && ps3av_hdmi_range())
|
||||
video_mode->video_cl_cnv = PS3AV_CMD_VIDEO_CL_CNV_DISABLE_LUT;
|
||||
else /* default enable */
|
||||
video_mode->video_cl_cnv = PS3AV_CMD_VIDEO_CL_CNV_ENABLE_LUT;
|
||||
video_mode->video_order = ps3av_video_fmt_table[video_fmt].order;
|
||||
|
||||
pr_debug("%s: video_mode:vid:%x width:%d height:%d pitch:%d out_format:%d format:%x order:%x\n",
|
||||
__func__, video_vid, video_mode->width, video_mode->height,
|
||||
video_mode->pitch, video_mode->video_out_format,
|
||||
video_mode->video_format, video_mode->video_order);
|
||||
return sizeof(*video_mode);
|
||||
}
|
||||
|
||||
int ps3av_cmd_video_format_black(u32 head, u32 video_fmt, u32 mute)
|
||||
{
|
||||
int res;
|
||||
struct ps3av_pkt_video_format video_format;
|
||||
|
||||
memset(&video_format, 0, sizeof(video_format));
|
||||
video_format.video_head = head;
|
||||
if (mute != PS3AV_CMD_MUTE_OFF)
|
||||
video_format.video_format = PS3AV_CMD_VIDEO_FORMAT_BLACK;
|
||||
else
|
||||
video_format.video_format =
|
||||
ps3av_video_fmt_table[video_fmt].format;
|
||||
video_format.video_order = ps3av_video_fmt_table[video_fmt].order;
|
||||
|
||||
res = ps3av_do_pkt(PS3AV_CID_VIDEO_FORMAT, sizeof(video_format),
|
||||
sizeof(video_format), &video_format.send_hdr);
|
||||
if (res < 0)
|
||||
return res;
|
||||
|
||||
res = get_status(&video_format);
|
||||
if (res)
|
||||
printk(KERN_ERR "PS3AV_CID_VIDEO_FORMAT: failed %x\n", res);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
int ps3av_cmd_av_audio_mute(int num_of_port, u32 *port, u32 mute)
|
||||
{
|
||||
int i, res;
|
||||
struct ps3av_pkt_av_audio_mute av_audio_mute;
|
||||
|
||||
if (num_of_port > PS3AV_MUTE_PORT_MAX)
|
||||
return -EINVAL;
|
||||
|
||||
/* audio mute */
|
||||
memset(&av_audio_mute, 0, sizeof(av_audio_mute));
|
||||
for (i = 0; i < num_of_port; i++) {
|
||||
av_audio_mute.mute[i].avport = port[i];
|
||||
av_audio_mute.mute[i].mute = mute;
|
||||
}
|
||||
|
||||
res = ps3av_do_pkt(PS3AV_CID_AV_AUDIO_MUTE,
|
||||
sizeof(av_audio_mute.send_hdr) +
|
||||
sizeof(struct ps3av_av_mute) * num_of_port,
|
||||
sizeof(av_audio_mute), &av_audio_mute.send_hdr);
|
||||
if (res < 0)
|
||||
return res;
|
||||
|
||||
res = get_status(&av_audio_mute);
|
||||
if (res)
|
||||
printk(KERN_ERR "PS3AV_CID_AV_AUDIO_MUTE: failed %x\n", res);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
static const struct {
|
||||
u32 fs;
|
||||
u8 mclk;
|
||||
} ps3av_cnv_mclk_table[] = {
|
||||
{ PS3AV_CMD_AUDIO_FS_44K, PS3AV_CMD_AV_MCLK_512 },
|
||||
{ PS3AV_CMD_AUDIO_FS_48K, PS3AV_CMD_AV_MCLK_512 },
|
||||
{ PS3AV_CMD_AUDIO_FS_88K, PS3AV_CMD_AV_MCLK_256 },
|
||||
{ PS3AV_CMD_AUDIO_FS_96K, PS3AV_CMD_AV_MCLK_256 },
|
||||
{ PS3AV_CMD_AUDIO_FS_176K, PS3AV_CMD_AV_MCLK_128 },
|
||||
{ PS3AV_CMD_AUDIO_FS_192K, PS3AV_CMD_AV_MCLK_128 }
|
||||
};
|
||||
|
||||
static u8 ps3av_cnv_mclk(u32 fs)
|
||||
{
|
||||
unsigned int i;
|
||||
|
||||
for (i = 0; i < ARRAY_SIZE(ps3av_cnv_mclk_table); i++)
|
||||
if (ps3av_cnv_mclk_table[i].fs == fs)
|
||||
return ps3av_cnv_mclk_table[i].mclk;
|
||||
|
||||
printk(KERN_ERR "%s failed, fs:%x\n", __func__, fs);
|
||||
return 0;
|
||||
}
|
||||
|
||||
#define BASE PS3AV_CMD_AUDIO_FS_44K
|
||||
|
||||
static const u32 ps3av_ns_table[][5] = {
|
||||
/* D1, D2, D3, D4, D5 */
|
||||
[PS3AV_CMD_AUDIO_FS_44K-BASE] = { 6272, 6272, 17836, 17836, 8918 },
|
||||
[PS3AV_CMD_AUDIO_FS_48K-BASE] = { 6144, 6144, 11648, 11648, 5824 },
|
||||
[PS3AV_CMD_AUDIO_FS_88K-BASE] = { 12544, 12544, 35672, 35672, 17836 },
|
||||
[PS3AV_CMD_AUDIO_FS_96K-BASE] = { 12288, 12288, 23296, 23296, 11648 },
|
||||
[PS3AV_CMD_AUDIO_FS_176K-BASE] = { 25088, 25088, 71344, 71344, 35672 },
|
||||
[PS3AV_CMD_AUDIO_FS_192K-BASE] = { 24576, 24576, 46592, 46592, 23296 }
|
||||
};
|
||||
|
||||
static void ps3av_cnv_ns(u8 *ns, u32 fs, u32 video_vid)
|
||||
{
|
||||
u32 av_vid, ns_val;
|
||||
int d;
|
||||
|
||||
d = ns_val = 0;
|
||||
av_vid = ps3av_vid_video2av(video_vid);
|
||||
switch (av_vid) {
|
||||
case PS3AV_CMD_AV_VID_480I:
|
||||
case PS3AV_CMD_AV_VID_576I:
|
||||
d = 0;
|
||||
break;
|
||||
case PS3AV_CMD_AV_VID_480P:
|
||||
case PS3AV_CMD_AV_VID_576P:
|
||||
d = 1;
|
||||
break;
|
||||
case PS3AV_CMD_AV_VID_1080I_60HZ:
|
||||
case PS3AV_CMD_AV_VID_1080I_50HZ:
|
||||
d = 2;
|
||||
break;
|
||||
case PS3AV_CMD_AV_VID_720P_60HZ:
|
||||
case PS3AV_CMD_AV_VID_720P_50HZ:
|
||||
d = 3;
|
||||
break;
|
||||
case PS3AV_CMD_AV_VID_1080P_60HZ:
|
||||
case PS3AV_CMD_AV_VID_1080P_50HZ:
|
||||
case PS3AV_CMD_AV_VID_WXGA:
|
||||
case PS3AV_CMD_AV_VID_SXGA:
|
||||
case PS3AV_CMD_AV_VID_WUXGA:
|
||||
d = 4;
|
||||
break;
|
||||
default:
|
||||
printk(KERN_ERR "%s failed, vid:%x\n", __func__, video_vid);
|
||||
break;
|
||||
}
|
||||
|
||||
if (fs < PS3AV_CMD_AUDIO_FS_44K || fs > PS3AV_CMD_AUDIO_FS_192K)
|
||||
printk(KERN_ERR "%s failed, fs:%x\n", __func__, fs);
|
||||
else
|
||||
ns_val = ps3av_ns_table[PS3AV_CMD_AUDIO_FS_44K-BASE][d];
|
||||
|
||||
*ns++ = ns_val & 0x000000FF;
|
||||
*ns++ = (ns_val & 0x0000FF00) >> 8;
|
||||
*ns = (ns_val & 0x00FF0000) >> 16;
|
||||
}
|
||||
|
||||
#undef BASE
|
||||
|
||||
static u8 ps3av_cnv_enable(u32 source, const u8 *enable)
|
||||
{
|
||||
u8 ret = 0;
|
||||
|
||||
if (source == PS3AV_CMD_AUDIO_SOURCE_SPDIF) {
|
||||
ret = 0x03;
|
||||
} else if (source == PS3AV_CMD_AUDIO_SOURCE_SERIAL) {
|
||||
ret = ((enable[0] << 4) + (enable[1] << 5) + (enable[2] << 6) +
|
||||
(enable[3] << 7)) | 0x01;
|
||||
} else
|
||||
printk(KERN_ERR "%s failed, source:%x\n", __func__, source);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static u8 ps3av_cnv_fifomap(const u8 *map)
|
||||
{
|
||||
u8 ret = 0;
|
||||
|
||||
ret = map[0] + (map[1] << 2) + (map[2] << 4) + (map[3] << 6);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static u8 ps3av_cnv_inputlen(u32 word_bits)
|
||||
{
|
||||
u8 ret = 0;
|
||||
|
||||
switch (word_bits) {
|
||||
case PS3AV_CMD_AUDIO_WORD_BITS_16:
|
||||
ret = PS3AV_CMD_AV_INPUTLEN_16;
|
||||
break;
|
||||
case PS3AV_CMD_AUDIO_WORD_BITS_20:
|
||||
ret = PS3AV_CMD_AV_INPUTLEN_20;
|
||||
break;
|
||||
case PS3AV_CMD_AUDIO_WORD_BITS_24:
|
||||
ret = PS3AV_CMD_AV_INPUTLEN_24;
|
||||
break;
|
||||
default:
|
||||
printk(KERN_ERR "%s failed, word_bits:%x\n", __func__,
|
||||
word_bits);
|
||||
break;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static u8 ps3av_cnv_layout(u32 num_of_ch)
|
||||
{
|
||||
if (num_of_ch > PS3AV_CMD_AUDIO_NUM_OF_CH_8) {
|
||||
printk(KERN_ERR "%s failed, num_of_ch:%x\n", __func__,
|
||||
num_of_ch);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return num_of_ch == PS3AV_CMD_AUDIO_NUM_OF_CH_2 ? 0x0 : 0x1;
|
||||
}
|
||||
|
||||
static void ps3av_cnv_info(struct ps3av_audio_info_frame *info,
|
||||
const struct ps3av_pkt_audio_mode *mode)
|
||||
{
|
||||
info->pb1.cc = mode->audio_num_of_ch + 1; /* CH2:0x01 --- CH8:0x07 */
|
||||
info->pb1.ct = 0;
|
||||
info->pb2.sf = 0;
|
||||
info->pb2.ss = 0;
|
||||
|
||||
info->pb3 = 0; /* check mode->audio_format ?? */
|
||||
info->pb4 = mode->audio_layout;
|
||||
info->pb5.dm = mode->audio_downmix;
|
||||
info->pb5.lsv = mode->audio_downmix_level;
|
||||
}
|
||||
|
||||
static void ps3av_cnv_chstat(u8 *chstat, const u8 *cs_info)
|
||||
{
|
||||
memcpy(chstat, cs_info, 5);
|
||||
}
|
||||
|
||||
u32 ps3av_cmd_set_av_audio_param(void *p, u32 port,
|
||||
const struct ps3av_pkt_audio_mode *audio_mode,
|
||||
u32 video_vid)
|
||||
{
|
||||
struct ps3av_pkt_av_audio_param *param;
|
||||
|
||||
param = (struct ps3av_pkt_av_audio_param *)p;
|
||||
|
||||
memset(param, 0, sizeof(*param));
|
||||
ps3av_set_hdr(PS3AV_CID_AV_AUDIO_PARAM, sizeof(*param),
|
||||
¶m->send_hdr);
|
||||
|
||||
param->avport = port;
|
||||
param->mclk = ps3av_cnv_mclk(audio_mode->audio_fs) | 0x80;
|
||||
ps3av_cnv_ns(param->ns, audio_mode->audio_fs, video_vid);
|
||||
param->enable = ps3av_cnv_enable(audio_mode->audio_source,
|
||||
audio_mode->audio_enable);
|
||||
param->swaplr = 0x09;
|
||||
param->fifomap = ps3av_cnv_fifomap(audio_mode->audio_map);
|
||||
param->inputctrl = 0x49;
|
||||
param->inputlen = ps3av_cnv_inputlen(audio_mode->audio_word_bits);
|
||||
param->layout = ps3av_cnv_layout(audio_mode->audio_num_of_ch);
|
||||
ps3av_cnv_info(¶m->info, audio_mode);
|
||||
ps3av_cnv_chstat(param->chstat, audio_mode->audio_cs_info);
|
||||
|
||||
return sizeof(*param);
|
||||
}
|
||||
|
||||
/* default cs val */
|
||||
u8 ps3av_mode_cs_info[] = {
|
||||
0x00, 0x09, 0x00, 0x02, 0x01, 0x00, 0x00, 0x00
|
||||
};
|
||||
EXPORT_SYMBOL_GPL(ps3av_mode_cs_info);
|
||||
|
||||
#define CS_44 0x00
|
||||
#define CS_48 0x02
|
||||
#define CS_88 0x08
|
||||
#define CS_96 0x0a
|
||||
#define CS_176 0x0c
|
||||
#define CS_192 0x0e
|
||||
#define CS_MASK 0x0f
|
||||
#define CS_BIT 0x40
|
||||
|
||||
void ps3av_cmd_set_audio_mode(struct ps3av_pkt_audio_mode *audio, u32 avport,
|
||||
u32 ch, u32 fs, u32 word_bits, u32 format,
|
||||
u32 source)
|
||||
{
|
||||
int spdif_through;
|
||||
int i;
|
||||
|
||||
if (!(ch | fs | format | word_bits | source)) {
|
||||
ch = PS3AV_CMD_AUDIO_NUM_OF_CH_2;
|
||||
fs = PS3AV_CMD_AUDIO_FS_48K;
|
||||
word_bits = PS3AV_CMD_AUDIO_WORD_BITS_16;
|
||||
format = PS3AV_CMD_AUDIO_FORMAT_PCM;
|
||||
source = PS3AV_CMD_AUDIO_SOURCE_SERIAL;
|
||||
}
|
||||
|
||||
/* audio mode */
|
||||
memset(audio, 0, sizeof(*audio));
|
||||
ps3av_set_hdr(PS3AV_CID_AUDIO_MODE, sizeof(*audio), &audio->send_hdr);
|
||||
|
||||
audio->avport = (u8) avport;
|
||||
audio->mask = 0x0FFF; /* XXX set all */
|
||||
audio->audio_num_of_ch = ch;
|
||||
audio->audio_fs = fs;
|
||||
audio->audio_word_bits = word_bits;
|
||||
audio->audio_format = format;
|
||||
audio->audio_source = source;
|
||||
|
||||
switch (ch) {
|
||||
case PS3AV_CMD_AUDIO_NUM_OF_CH_8:
|
||||
audio->audio_enable[3] = 1;
|
||||
/* fall through */
|
||||
case PS3AV_CMD_AUDIO_NUM_OF_CH_6:
|
||||
audio->audio_enable[2] = 1;
|
||||
audio->audio_enable[1] = 1;
|
||||
/* fall through */
|
||||
case PS3AV_CMD_AUDIO_NUM_OF_CH_2:
|
||||
default:
|
||||
audio->audio_enable[0] = 1;
|
||||
}
|
||||
|
||||
/* audio swap L/R */
|
||||
for (i = 0; i < 4; i++)
|
||||
audio->audio_swap[i] = PS3AV_CMD_AUDIO_SWAP_0; /* no swap */
|
||||
|
||||
/* audio serial input mapping */
|
||||
audio->audio_map[0] = PS3AV_CMD_AUDIO_MAP_OUTPUT_0;
|
||||
audio->audio_map[1] = PS3AV_CMD_AUDIO_MAP_OUTPUT_1;
|
||||
audio->audio_map[2] = PS3AV_CMD_AUDIO_MAP_OUTPUT_2;
|
||||
audio->audio_map[3] = PS3AV_CMD_AUDIO_MAP_OUTPUT_3;
|
||||
|
||||
/* audio speaker layout */
|
||||
if (avport == PS3AV_CMD_AVPORT_HDMI_0 ||
|
||||
avport == PS3AV_CMD_AVPORT_HDMI_1) {
|
||||
switch (ch) {
|
||||
case PS3AV_CMD_AUDIO_NUM_OF_CH_8:
|
||||
audio->audio_layout = PS3AV_CMD_AUDIO_LAYOUT_8CH;
|
||||
break;
|
||||
case PS3AV_CMD_AUDIO_NUM_OF_CH_6:
|
||||
audio->audio_layout = PS3AV_CMD_AUDIO_LAYOUT_6CH;
|
||||
break;
|
||||
case PS3AV_CMD_AUDIO_NUM_OF_CH_2:
|
||||
default:
|
||||
audio->audio_layout = PS3AV_CMD_AUDIO_LAYOUT_2CH;
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
audio->audio_layout = PS3AV_CMD_AUDIO_LAYOUT_2CH;
|
||||
}
|
||||
|
||||
/* audio downmix permission */
|
||||
audio->audio_downmix = PS3AV_CMD_AUDIO_DOWNMIX_PERMITTED;
|
||||
/* audio downmix level shift (0:0dB to 15:15dB) */
|
||||
audio->audio_downmix_level = 0; /* 0dB */
|
||||
|
||||
/* set ch status */
|
||||
for (i = 0; i < 8; i++)
|
||||
audio->audio_cs_info[i] = ps3av_mode_cs_info[i];
|
||||
|
||||
switch (fs) {
|
||||
case PS3AV_CMD_AUDIO_FS_44K:
|
||||
audio->audio_cs_info[3] &= ~CS_MASK;
|
||||
audio->audio_cs_info[3] |= CS_44;
|
||||
break;
|
||||
case PS3AV_CMD_AUDIO_FS_88K:
|
||||
audio->audio_cs_info[3] &= ~CS_MASK;
|
||||
audio->audio_cs_info[3] |= CS_88;
|
||||
break;
|
||||
case PS3AV_CMD_AUDIO_FS_96K:
|
||||
audio->audio_cs_info[3] &= ~CS_MASK;
|
||||
audio->audio_cs_info[3] |= CS_96;
|
||||
break;
|
||||
case PS3AV_CMD_AUDIO_FS_176K:
|
||||
audio->audio_cs_info[3] &= ~CS_MASK;
|
||||
audio->audio_cs_info[3] |= CS_176;
|
||||
break;
|
||||
case PS3AV_CMD_AUDIO_FS_192K:
|
||||
audio->audio_cs_info[3] &= ~CS_MASK;
|
||||
audio->audio_cs_info[3] |= CS_192;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
/* non-audio bit */
|
||||
spdif_through = audio->audio_cs_info[0] & 0x02;
|
||||
|
||||
/* pass through setting */
|
||||
if (spdif_through &&
|
||||
(avport == PS3AV_CMD_AVPORT_SPDIF_0 ||
|
||||
avport == PS3AV_CMD_AVPORT_SPDIF_1 ||
|
||||
avport == PS3AV_CMD_AVPORT_HDMI_0 ||
|
||||
avport == PS3AV_CMD_AVPORT_HDMI_1)) {
|
||||
audio->audio_word_bits = PS3AV_CMD_AUDIO_WORD_BITS_16;
|
||||
audio->audio_format = PS3AV_CMD_AUDIO_FORMAT_BITSTREAM;
|
||||
}
|
||||
}
|
||||
|
||||
int ps3av_cmd_audio_mode(struct ps3av_pkt_audio_mode *audio_mode)
|
||||
{
|
||||
int res;
|
||||
|
||||
res = ps3av_do_pkt(PS3AV_CID_AUDIO_MODE, sizeof(*audio_mode),
|
||||
sizeof(*audio_mode), &audio_mode->send_hdr);
|
||||
if (res < 0)
|
||||
return res;
|
||||
|
||||
res = get_status(audio_mode);
|
||||
if (res)
|
||||
printk(KERN_ERR "PS3AV_CID_AUDIO_MODE: failed %x\n", res);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
int ps3av_cmd_audio_mute(int num_of_port, u32 *port, u32 mute)
|
||||
{
|
||||
int i, res;
|
||||
struct ps3av_pkt_audio_mute audio_mute;
|
||||
|
||||
if (num_of_port > PS3AV_OPT_PORT_MAX)
|
||||
return -EINVAL;
|
||||
|
||||
/* audio mute */
|
||||
memset(&audio_mute, 0, sizeof(audio_mute));
|
||||
for (i = 0; i < num_of_port; i++) {
|
||||
audio_mute.mute[i].avport = port[i];
|
||||
audio_mute.mute[i].mute = mute;
|
||||
}
|
||||
|
||||
res = ps3av_do_pkt(PS3AV_CID_AUDIO_MUTE,
|
||||
sizeof(audio_mute.send_hdr) +
|
||||
sizeof(struct ps3av_audio_mute) * num_of_port,
|
||||
sizeof(audio_mute), &audio_mute.send_hdr);
|
||||
if (res < 0)
|
||||
return res;
|
||||
|
||||
res = get_status(&audio_mute);
|
||||
if (res)
|
||||
printk(KERN_ERR "PS3AV_CID_AUDIO_MUTE: failed %x\n", res);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
int ps3av_cmd_audio_active(int active, u32 port)
|
||||
{
|
||||
int res;
|
||||
struct ps3av_pkt_audio_active audio_active;
|
||||
u32 cid;
|
||||
|
||||
/* audio active */
|
||||
memset(&audio_active, 0, sizeof(audio_active));
|
||||
audio_active.audio_port = port;
|
||||
cid = active ? PS3AV_CID_AUDIO_ACTIVE : PS3AV_CID_AUDIO_INACTIVE;
|
||||
|
||||
res = ps3av_do_pkt(cid, sizeof(audio_active), sizeof(audio_active),
|
||||
&audio_active.send_hdr);
|
||||
if (res < 0)
|
||||
return res;
|
||||
|
||||
res = get_status(&audio_active);
|
||||
if (res)
|
||||
printk(KERN_ERR "PS3AV_CID_AUDIO_ACTIVE:%x failed %x\n", cid,
|
||||
res);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
int ps3av_cmd_avb_param(struct ps3av_pkt_avb_param *avb, u32 send_len)
|
||||
{
|
||||
int res;
|
||||
|
||||
mutex_lock(&ps3_gpu_mutex);
|
||||
|
||||
/* avb packet */
|
||||
res = ps3av_do_pkt(PS3AV_CID_AVB_PARAM, send_len, sizeof(*avb),
|
||||
&avb->send_hdr);
|
||||
if (res < 0)
|
||||
goto out;
|
||||
|
||||
res = get_status(avb);
|
||||
if (res)
|
||||
pr_debug("%s: PS3AV_CID_AVB_PARAM: failed %x\n", __func__,
|
||||
res);
|
||||
|
||||
out:
|
||||
mutex_unlock(&ps3_gpu_mutex);
|
||||
return res;
|
||||
}
|
||||
|
||||
int ps3av_cmd_av_get_hw_conf(struct ps3av_pkt_av_get_hw_conf *hw_conf)
|
||||
{
|
||||
int res;
|
||||
|
||||
memset(hw_conf, 0, sizeof(*hw_conf));
|
||||
|
||||
res = ps3av_do_pkt(PS3AV_CID_AV_GET_HW_CONF, sizeof(hw_conf->send_hdr),
|
||||
sizeof(*hw_conf), &hw_conf->send_hdr);
|
||||
if (res < 0)
|
||||
return res;
|
||||
|
||||
res = get_status(hw_conf);
|
||||
if (res)
|
||||
printk(KERN_ERR "PS3AV_CID_AV_GET_HW_CONF: failed %x\n", res);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
int ps3av_cmd_video_get_monitor_info(struct ps3av_pkt_av_get_monitor_info *info,
|
||||
u32 avport)
|
||||
{
|
||||
int res;
|
||||
|
||||
memset(info, 0, sizeof(*info));
|
||||
info->avport = avport;
|
||||
|
||||
res = ps3av_do_pkt(PS3AV_CID_AV_GET_MONITOR_INFO,
|
||||
sizeof(info->send_hdr) + sizeof(info->avport) +
|
||||
sizeof(info->reserved),
|
||||
sizeof(*info), &info->send_hdr);
|
||||
if (res < 0)
|
||||
return res;
|
||||
|
||||
res = get_status(info);
|
||||
if (res)
|
||||
printk(KERN_ERR "PS3AV_CID_AV_GET_MONITOR_INFO: failed %x\n",
|
||||
res);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
#define PS3AV_AV_LAYOUT_0 (PS3AV_CMD_AV_LAYOUT_32 \
|
||||
| PS3AV_CMD_AV_LAYOUT_44 \
|
||||
| PS3AV_CMD_AV_LAYOUT_48)
|
||||
|
||||
#define PS3AV_AV_LAYOUT_1 (PS3AV_AV_LAYOUT_0 \
|
||||
| PS3AV_CMD_AV_LAYOUT_88 \
|
||||
| PS3AV_CMD_AV_LAYOUT_96 \
|
||||
| PS3AV_CMD_AV_LAYOUT_176 \
|
||||
| PS3AV_CMD_AV_LAYOUT_192)
|
||||
|
362
drivers/ps3/ps3stor_lib.c
Normal file
362
drivers/ps3/ps3stor_lib.c
Normal file
|
@ -0,0 +1,362 @@
|
|||
/*
|
||||
* PS3 Storage Library
|
||||
*
|
||||
* Copyright (C) 2007 Sony Computer Entertainment Inc.
|
||||
* Copyright 2007 Sony Corp.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published
|
||||
* by the Free Software Foundation; version 2 of the License.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
#include <linux/dma-mapping.h>
|
||||
#include <linux/module.h>
|
||||
|
||||
#include <asm/lv1call.h>
|
||||
#include <asm/ps3stor.h>
|
||||
|
||||
/*
|
||||
* A workaround for flash memory I/O errors when the internal hard disk
|
||||
* has not been formatted for OtherOS use. Delay disk close until flash
|
||||
* memory is closed.
|
||||
*/
|
||||
|
||||
static struct ps3_flash_workaround {
|
||||
int flash_open;
|
||||
int disk_open;
|
||||
struct ps3_system_bus_device *disk_sbd;
|
||||
} ps3_flash_workaround;
|
||||
|
||||
static int ps3stor_open_hv_device(struct ps3_system_bus_device *sbd)
|
||||
{
|
||||
int error = ps3_open_hv_device(sbd);
|
||||
|
||||
if (error)
|
||||
return error;
|
||||
|
||||
if (sbd->match_id == PS3_MATCH_ID_STOR_FLASH)
|
||||
ps3_flash_workaround.flash_open = 1;
|
||||
|
||||
if (sbd->match_id == PS3_MATCH_ID_STOR_DISK)
|
||||
ps3_flash_workaround.disk_open = 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int ps3stor_close_hv_device(struct ps3_system_bus_device *sbd)
|
||||
{
|
||||
int error;
|
||||
|
||||
if (sbd->match_id == PS3_MATCH_ID_STOR_DISK
|
||||
&& ps3_flash_workaround.disk_open
|
||||
&& ps3_flash_workaround.flash_open) {
|
||||
ps3_flash_workaround.disk_sbd = sbd;
|
||||
return 0;
|
||||
}
|
||||
|
||||
error = ps3_close_hv_device(sbd);
|
||||
|
||||
if (error)
|
||||
return error;
|
||||
|
||||
if (sbd->match_id == PS3_MATCH_ID_STOR_DISK)
|
||||
ps3_flash_workaround.disk_open = 0;
|
||||
|
||||
if (sbd->match_id == PS3_MATCH_ID_STOR_FLASH) {
|
||||
ps3_flash_workaround.flash_open = 0;
|
||||
|
||||
if (ps3_flash_workaround.disk_sbd) {
|
||||
ps3_close_hv_device(ps3_flash_workaround.disk_sbd);
|
||||
ps3_flash_workaround.disk_open = 0;
|
||||
ps3_flash_workaround.disk_sbd = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int ps3stor_probe_access(struct ps3_storage_device *dev)
|
||||
{
|
||||
int res, error;
|
||||
unsigned int i;
|
||||
unsigned long n;
|
||||
|
||||
if (dev->sbd.match_id == PS3_MATCH_ID_STOR_ROM) {
|
||||
/* special case: CD-ROM is assumed always accessible */
|
||||
dev->accessible_regions = 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
error = -EPERM;
|
||||
for (i = 0; i < dev->num_regions; i++) {
|
||||
dev_dbg(&dev->sbd.core,
|
||||
"%s:%u: checking accessibility of region %u\n",
|
||||
__func__, __LINE__, i);
|
||||
|
||||
dev->region_idx = i;
|
||||
res = ps3stor_read_write_sectors(dev, dev->bounce_lpar, 0, 1,
|
||||
0);
|
||||
if (res) {
|
||||
dev_dbg(&dev->sbd.core, "%s:%u: read failed, "
|
||||
"region %u is not accessible\n", __func__,
|
||||
__LINE__, i);
|
||||
continue;
|
||||
}
|
||||
|
||||
dev_dbg(&dev->sbd.core, "%s:%u: region %u is accessible\n",
|
||||
__func__, __LINE__, i);
|
||||
set_bit(i, &dev->accessible_regions);
|
||||
|
||||
/* We can access at least one region */
|
||||
error = 0;
|
||||
}
|
||||
if (error)
|
||||
return error;
|
||||
|
||||
n = hweight_long(dev->accessible_regions);
|
||||
if (n > 1)
|
||||
dev_info(&dev->sbd.core,
|
||||
"%s:%u: %lu accessible regions found. Only the first "
|
||||
"one will be used\n",
|
||||
__func__, __LINE__, n);
|
||||
dev->region_idx = __ffs(dev->accessible_regions);
|
||||
dev_info(&dev->sbd.core,
|
||||
"First accessible region has index %u start %llu size %llu\n",
|
||||
dev->region_idx, dev->regions[dev->region_idx].start,
|
||||
dev->regions[dev->region_idx].size);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* ps3stor_setup - Setup a storage device before use
|
||||
* @dev: Pointer to a struct ps3_storage_device
|
||||
* @handler: Pointer to an interrupt handler
|
||||
*
|
||||
* Returns 0 for success, or an error code
|
||||
*/
|
||||
int ps3stor_setup(struct ps3_storage_device *dev, irq_handler_t handler)
|
||||
{
|
||||
int error, res, alignment;
|
||||
enum ps3_dma_page_size page_size;
|
||||
|
||||
error = ps3stor_open_hv_device(&dev->sbd);
|
||||
if (error) {
|
||||
dev_err(&dev->sbd.core,
|
||||
"%s:%u: ps3_open_hv_device failed %d\n", __func__,
|
||||
__LINE__, error);
|
||||
goto fail;
|
||||
}
|
||||
|
||||
error = ps3_sb_event_receive_port_setup(&dev->sbd, PS3_BINDING_CPU_ANY,
|
||||
&dev->irq);
|
||||
if (error) {
|
||||
dev_err(&dev->sbd.core,
|
||||
"%s:%u: ps3_sb_event_receive_port_setup failed %d\n",
|
||||
__func__, __LINE__, error);
|
||||
goto fail_close_device;
|
||||
}
|
||||
|
||||
error = request_irq(dev->irq, handler, 0,
|
||||
dev->sbd.core.driver->name, dev);
|
||||
if (error) {
|
||||
dev_err(&dev->sbd.core, "%s:%u: request_irq failed %d\n",
|
||||
__func__, __LINE__, error);
|
||||
goto fail_sb_event_receive_port_destroy;
|
||||
}
|
||||
|
||||
alignment = min(__ffs(dev->bounce_size),
|
||||
__ffs((unsigned long)dev->bounce_buf));
|
||||
if (alignment < 12) {
|
||||
dev_err(&dev->sbd.core,
|
||||
"%s:%u: bounce buffer not aligned (%lx at 0x%p)\n",
|
||||
__func__, __LINE__, dev->bounce_size, dev->bounce_buf);
|
||||
error = -EINVAL;
|
||||
goto fail_free_irq;
|
||||
} else if (alignment < 16)
|
||||
page_size = PS3_DMA_4K;
|
||||
else
|
||||
page_size = PS3_DMA_64K;
|
||||
dev->sbd.d_region = &dev->dma_region;
|
||||
ps3_dma_region_init(&dev->sbd, &dev->dma_region, page_size,
|
||||
PS3_DMA_OTHER, dev->bounce_buf, dev->bounce_size);
|
||||
res = ps3_dma_region_create(&dev->dma_region);
|
||||
if (res) {
|
||||
dev_err(&dev->sbd.core, "%s:%u: cannot create DMA region\n",
|
||||
__func__, __LINE__);
|
||||
error = -ENOMEM;
|
||||
goto fail_free_irq;
|
||||
}
|
||||
|
||||
dev->bounce_lpar = ps3_mm_phys_to_lpar(__pa(dev->bounce_buf));
|
||||
dev->bounce_dma = dma_map_single(&dev->sbd.core, dev->bounce_buf,
|
||||
dev->bounce_size, DMA_BIDIRECTIONAL);
|
||||
if (!dev->bounce_dma) {
|
||||
dev_err(&dev->sbd.core, "%s:%u: map DMA region failed\n",
|
||||
__func__, __LINE__);
|
||||
error = -ENODEV;
|
||||
goto fail_free_dma;
|
||||
}
|
||||
|
||||
error = ps3stor_probe_access(dev);
|
||||
if (error) {
|
||||
dev_err(&dev->sbd.core, "%s:%u: No accessible regions found\n",
|
||||
__func__, __LINE__);
|
||||
goto fail_unmap_dma;
|
||||
}
|
||||
return 0;
|
||||
|
||||
fail_unmap_dma:
|
||||
dma_unmap_single(&dev->sbd.core, dev->bounce_dma, dev->bounce_size,
|
||||
DMA_BIDIRECTIONAL);
|
||||
fail_free_dma:
|
||||
ps3_dma_region_free(&dev->dma_region);
|
||||
fail_free_irq:
|
||||
free_irq(dev->irq, dev);
|
||||
fail_sb_event_receive_port_destroy:
|
||||
ps3_sb_event_receive_port_destroy(&dev->sbd, dev->irq);
|
||||
fail_close_device:
|
||||
ps3stor_close_hv_device(&dev->sbd);
|
||||
fail:
|
||||
return error;
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(ps3stor_setup);
|
||||
|
||||
|
||||
/**
|
||||
* ps3stor_teardown - Tear down a storage device after use
|
||||
* @dev: Pointer to a struct ps3_storage_device
|
||||
*/
|
||||
void ps3stor_teardown(struct ps3_storage_device *dev)
|
||||
{
|
||||
int error;
|
||||
|
||||
dma_unmap_single(&dev->sbd.core, dev->bounce_dma, dev->bounce_size,
|
||||
DMA_BIDIRECTIONAL);
|
||||
ps3_dma_region_free(&dev->dma_region);
|
||||
|
||||
free_irq(dev->irq, dev);
|
||||
|
||||
error = ps3_sb_event_receive_port_destroy(&dev->sbd, dev->irq);
|
||||
if (error)
|
||||
dev_err(&dev->sbd.core,
|
||||
"%s:%u: destroy event receive port failed %d\n",
|
||||
__func__, __LINE__, error);
|
||||
|
||||
error = ps3stor_close_hv_device(&dev->sbd);
|
||||
if (error)
|
||||
dev_err(&dev->sbd.core,
|
||||
"%s:%u: ps3_close_hv_device failed %d\n", __func__,
|
||||
__LINE__, error);
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(ps3stor_teardown);
|
||||
|
||||
|
||||
/**
|
||||
* ps3stor_read_write_sectors - read/write from/to a storage device
|
||||
* @dev: Pointer to a struct ps3_storage_device
|
||||
* @lpar: HV logical partition address
|
||||
* @start_sector: First sector to read/write
|
||||
* @sectors: Number of sectors to read/write
|
||||
* @write: Flag indicating write (non-zero) or read (zero)
|
||||
*
|
||||
* Returns 0 for success, -1 in case of failure to submit the command, or
|
||||
* an LV1 status value in case of other errors
|
||||
*/
|
||||
u64 ps3stor_read_write_sectors(struct ps3_storage_device *dev, u64 lpar,
|
||||
u64 start_sector, u64 sectors, int write)
|
||||
{
|
||||
unsigned int region_id = dev->regions[dev->region_idx].id;
|
||||
const char *op = write ? "write" : "read";
|
||||
int res;
|
||||
|
||||
dev_dbg(&dev->sbd.core, "%s:%u: %s %llu sectors starting at %llu\n",
|
||||
__func__, __LINE__, op, sectors, start_sector);
|
||||
|
||||
init_completion(&dev->done);
|
||||
res = write ? lv1_storage_write(dev->sbd.dev_id, region_id,
|
||||
start_sector, sectors, 0, lpar,
|
||||
&dev->tag)
|
||||
: lv1_storage_read(dev->sbd.dev_id, region_id,
|
||||
start_sector, sectors, 0, lpar,
|
||||
&dev->tag);
|
||||
if (res) {
|
||||
dev_dbg(&dev->sbd.core, "%s:%u: %s failed %d\n", __func__,
|
||||
__LINE__, op, res);
|
||||
return -1;
|
||||
}
|
||||
|
||||
wait_for_completion(&dev->done);
|
||||
if (dev->lv1_status) {
|
||||
dev_dbg(&dev->sbd.core, "%s:%u: %s failed 0x%llx\n", __func__,
|
||||
__LINE__, op, dev->lv1_status);
|
||||
return dev->lv1_status;
|
||||
}
|
||||
|
||||
dev_dbg(&dev->sbd.core, "%s:%u: %s completed\n", __func__, __LINE__,
|
||||
op);
|
||||
|
||||
return 0;
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(ps3stor_read_write_sectors);
|
||||
|
||||
|
||||
/**
|
||||
* ps3stor_send_command - send a device command to a storage device
|
||||
* @dev: Pointer to a struct ps3_storage_device
|
||||
* @cmd: Command number
|
||||
* @arg1: First command argument
|
||||
* @arg2: Second command argument
|
||||
* @arg3: Third command argument
|
||||
* @arg4: Fourth command argument
|
||||
*
|
||||
* Returns 0 for success, -1 in case of failure to submit the command, or
|
||||
* an LV1 status value in case of other errors
|
||||
*/
|
||||
u64 ps3stor_send_command(struct ps3_storage_device *dev, u64 cmd, u64 arg1,
|
||||
u64 arg2, u64 arg3, u64 arg4)
|
||||
{
|
||||
int res;
|
||||
|
||||
dev_dbg(&dev->sbd.core, "%s:%u: send device command 0x%llx\n", __func__,
|
||||
__LINE__, cmd);
|
||||
|
||||
init_completion(&dev->done);
|
||||
|
||||
res = lv1_storage_send_device_command(dev->sbd.dev_id, cmd, arg1,
|
||||
arg2, arg3, arg4, &dev->tag);
|
||||
if (res) {
|
||||
dev_err(&dev->sbd.core,
|
||||
"%s:%u: send_device_command 0x%llx failed %d\n",
|
||||
__func__, __LINE__, cmd, res);
|
||||
return -1;
|
||||
}
|
||||
|
||||
wait_for_completion(&dev->done);
|
||||
if (dev->lv1_status) {
|
||||
dev_dbg(&dev->sbd.core, "%s:%u: command 0x%llx failed 0x%llx\n",
|
||||
__func__, __LINE__, cmd, dev->lv1_status);
|
||||
return dev->lv1_status;
|
||||
}
|
||||
|
||||
dev_dbg(&dev->sbd.core, "%s:%u: command 0x%llx completed\n", __func__,
|
||||
__LINE__, cmd);
|
||||
|
||||
return 0;
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(ps3stor_send_command);
|
||||
|
||||
|
||||
MODULE_LICENSE("GPL");
|
||||
MODULE_DESCRIPTION("PS3 Storage Bus Library");
|
||||
MODULE_AUTHOR("Sony Corporation");
|
73
drivers/ps3/sys-manager-core.c
Normal file
73
drivers/ps3/sys-manager-core.c
Normal file
|
@ -0,0 +1,73 @@
|
|||
/*
|
||||
* PS3 System Manager core.
|
||||
*
|
||||
* Copyright (C) 2007 Sony Computer Entertainment Inc.
|
||||
* Copyright 2007 Sony Corp.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; version 2 of the License.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#include <linux/kernel.h>
|
||||
#include <linux/export.h>
|
||||
#include <asm/lv1call.h>
|
||||
#include <asm/ps3.h>
|
||||
|
||||
/**
|
||||
* Staticly linked routines that allow late binding of a loaded sys-manager
|
||||
* module.
|
||||
*/
|
||||
|
||||
static struct ps3_sys_manager_ops ps3_sys_manager_ops;
|
||||
|
||||
/**
|
||||
* ps3_register_sys_manager_ops - Bind ps3_sys_manager_ops to a module.
|
||||
* @ops: struct ps3_sys_manager_ops.
|
||||
*
|
||||
* To be called from ps3_sys_manager_probe() and ps3_sys_manager_remove() to
|
||||
* register call back ops for power control. Copies data to the static
|
||||
* variable ps3_sys_manager_ops.
|
||||
*/
|
||||
|
||||
void ps3_sys_manager_register_ops(const struct ps3_sys_manager_ops *ops)
|
||||
{
|
||||
BUG_ON(!ops);
|
||||
BUG_ON(!ops->dev);
|
||||
ps3_sys_manager_ops = ops ? *ops : ps3_sys_manager_ops;
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(ps3_sys_manager_register_ops);
|
||||
|
||||
void ps3_sys_manager_power_off(void)
|
||||
{
|
||||
if (ps3_sys_manager_ops.power_off)
|
||||
ps3_sys_manager_ops.power_off(ps3_sys_manager_ops.dev);
|
||||
|
||||
ps3_sys_manager_halt();
|
||||
}
|
||||
|
||||
void ps3_sys_manager_restart(void)
|
||||
{
|
||||
if (ps3_sys_manager_ops.restart)
|
||||
ps3_sys_manager_ops.restart(ps3_sys_manager_ops.dev);
|
||||
|
||||
ps3_sys_manager_halt();
|
||||
}
|
||||
|
||||
void ps3_sys_manager_halt(void)
|
||||
{
|
||||
pr_emerg("System Halted, OK to turn off power\n");
|
||||
local_irq_disable();
|
||||
while (1)
|
||||
lv1_pause(1);
|
||||
}
|
||||
|
85
drivers/ps3/vuart.h
Normal file
85
drivers/ps3/vuart.h
Normal file
|
@ -0,0 +1,85 @@
|
|||
/*
|
||||
* PS3 virtual uart
|
||||
*
|
||||
* Copyright (C) 2006 Sony Computer Entertainment Inc.
|
||||
* Copyright 2006 Sony Corp.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; version 2 of the License.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#if !defined(_PS3_VUART_H)
|
||||
#define _PS3_VUART_H
|
||||
|
||||
#include <asm/ps3.h>
|
||||
|
||||
struct ps3_vuart_stats {
|
||||
unsigned long bytes_written;
|
||||
unsigned long bytes_read;
|
||||
unsigned long tx_interrupts;
|
||||
unsigned long rx_interrupts;
|
||||
unsigned long disconnect_interrupts;
|
||||
};
|
||||
|
||||
struct ps3_vuart_work {
|
||||
struct work_struct work;
|
||||
unsigned long trigger;
|
||||
struct ps3_system_bus_device *dev; /* to convert work to device */
|
||||
};
|
||||
|
||||
/**
|
||||
* struct ps3_vuart_port_driver - a driver for a device on a vuart port
|
||||
*/
|
||||
|
||||
struct ps3_vuart_port_driver {
|
||||
struct ps3_system_bus_driver core;
|
||||
int (*probe)(struct ps3_system_bus_device *);
|
||||
int (*remove)(struct ps3_system_bus_device *);
|
||||
void (*shutdown)(struct ps3_system_bus_device *);
|
||||
void (*work)(struct ps3_system_bus_device *);
|
||||
/* int (*tx_event)(struct ps3_system_bus_device *dev); */
|
||||
/* int (*rx_event)(struct ps3_system_bus_device *dev); */
|
||||
/* int (*disconnect_event)(struct ps3_system_bus_device *dev); */
|
||||
/* int (*suspend)(struct ps3_system_bus_device *, pm_message_t); */
|
||||
/* int (*resume)(struct ps3_system_bus_device *); */
|
||||
};
|
||||
|
||||
int ps3_vuart_port_driver_register(struct ps3_vuart_port_driver *drv);
|
||||
void ps3_vuart_port_driver_unregister(struct ps3_vuart_port_driver *drv);
|
||||
|
||||
static inline struct ps3_vuart_port_driver *
|
||||
ps3_system_bus_dev_to_vuart_drv(struct ps3_system_bus_device *_dev)
|
||||
{
|
||||
struct ps3_system_bus_driver *sbd =
|
||||
ps3_system_bus_dev_to_system_bus_drv(_dev);
|
||||
BUG_ON(!sbd);
|
||||
return container_of(sbd, struct ps3_vuart_port_driver, core);
|
||||
}
|
||||
static inline struct ps3_system_bus_device *ps3_vuart_work_to_system_bus_dev(
|
||||
struct work_struct *_work)
|
||||
{
|
||||
struct ps3_vuart_work *vw = container_of(_work, struct ps3_vuart_work,
|
||||
work);
|
||||
return vw->dev;
|
||||
}
|
||||
|
||||
int ps3_vuart_write(struct ps3_system_bus_device *dev, const void *buf,
|
||||
unsigned int bytes);
|
||||
int ps3_vuart_read(struct ps3_system_bus_device *dev, void *buf,
|
||||
unsigned int bytes);
|
||||
int ps3_vuart_read_async(struct ps3_system_bus_device *dev, unsigned int bytes);
|
||||
void ps3_vuart_cancel_async(struct ps3_system_bus_device *dev);
|
||||
void ps3_vuart_clear_rx_bytes(struct ps3_system_bus_device *dev,
|
||||
unsigned int bytes);
|
||||
|
||||
#endif
|
Loading…
Add table
Add a link
Reference in a new issue