blob: 66657722f50fc49a4a3eb5f79138db9f65048a8b [file] [log] [blame]
Sagar Dharia46a2bb52017-12-11 23:42:58 +00001// SPDX-License-Identifier: GPL-2.0
2/*
3 * Copyright (c) 2011-2017, The Linux Foundation
4 */
5
6#ifndef _DRIVERS_SLIMBUS_H
7#define _DRIVERS_SLIMBUS_H
8#include <linux/module.h>
9#include <linux/device.h>
10#include <linux/mutex.h>
11#include <linux/slimbus.h>
12
13/* Standard values per SLIMbus spec needed by controllers and devices */
14#define SLIM_MAX_CLK_GEAR 10
15#define SLIM_MIN_CLK_GEAR 1
16
17/* Manager's logical address is set to 0xFF per spec */
18#define SLIM_LA_MANAGER 0xFF
19
20/**
21 * struct slim_framer - Represents SLIMbus framer.
22 * Every controller may have multiple framers. There is 1 active framer device
23 * responsible for clocking the bus.
24 * Manager is responsible for framer hand-over.
25 * @dev: Driver model representation of the device.
26 * @e_addr: Enumeration address of the framer.
27 * @rootfreq: Root Frequency at which the framer can run. This is maximum
28 * frequency ('clock gear 10') at which the bus can operate.
29 * @superfreq: Superframes per root frequency. Every frame is 6144 bits.
30 */
31struct slim_framer {
32 struct device dev;
33 struct slim_eaddr e_addr;
34 int rootfreq;
35 int superfreq;
36};
37
38#define to_slim_framer(d) container_of(d, struct slim_framer, dev)
39
40/**
41 * struct slim_controller - Controls every instance of SLIMbus
42 * (similar to 'master' on SPI)
43 * @dev: Device interface to this driver
44 * @id: Board-specific number identifier for this controller/bus
45 * @name: Name for this controller
46 * @min_cg: Minimum clock gear supported by this controller (default value: 1)
47 * @max_cg: Maximum clock gear supported by this controller (default value: 10)
48 * @clkgear: Current clock gear in which this bus is running
49 * @laddr_ida: logical address id allocator
50 * @a_framer: Active framer which is clocking the bus managed by this controller
51 * @lock: Mutex protecting controller data structures
52 * @devices: Slim device list
53 * @tid_idr: tid id allocator
54 * @txn_lock: Lock to protect table of transactions
55 * @set_laddr: Setup logical address at laddr for the slave with elemental
56 * address e_addr. Drivers implementing controller will be expected to
57 * send unicast message to this device with its logical address.
58 * @get_laddr: It is possible that controller needs to set fixed logical
59 * address table and get_laddr can be used in that case so that controller
60 * can do this assignment. Use case is when the master is on the remote
61 * processor side, who is resposible for allocating laddr.
62 *
63 * 'Manager device' is responsible for device management, bandwidth
64 * allocation, channel setup, and port associations per channel.
65 * Device management means Logical address assignment/removal based on
66 * enumeration (report-present, report-absent) of a device.
67 * Bandwidth allocation is done dynamically by the manager based on active
68 * channels on the bus, message-bandwidth requests made by SLIMbus devices.
69 * Based on current bandwidth usage, manager chooses a frequency to run
70 * the bus at (in steps of 'clock-gear', 1 through 10, each clock gear
71 * representing twice the frequency than the previous gear).
72 * Manager is also responsible for entering (and exiting) low-power-mode
73 * (known as 'clock pause').
74 * Manager can do handover of framer if there are multiple framers on the
75 * bus and a certain usecase warrants using certain framer to avoid keeping
76 * previous framer being powered-on.
77 *
78 * Controller here performs duties of the manager device, and 'interface
79 * device'. Interface device is responsible for monitoring the bus and
80 * reporting information such as loss-of-synchronization, data
81 * slot-collision.
82 */
83struct slim_controller {
84 struct device *dev;
85 unsigned int id;
86 char name[SLIMBUS_NAME_SIZE];
87 int min_cg;
88 int max_cg;
89 int clkgear;
90 struct ida laddr_ida;
91 struct slim_framer *a_framer;
92 struct mutex lock;
93 struct list_head devices;
94 struct idr tid_idr;
95 spinlock_t txn_lock;
96 int (*set_laddr)(struct slim_controller *ctrl,
97 struct slim_eaddr *ea, u8 laddr);
98 int (*get_laddr)(struct slim_controller *ctrl,
99 struct slim_eaddr *ea, u8 *laddr);
100};
101
102int slim_device_report_present(struct slim_controller *ctrl,
103 struct slim_eaddr *e_addr, u8 *laddr);
104void slim_report_absent(struct slim_device *sbdev);
105int slim_register_controller(struct slim_controller *ctrl);
106int slim_unregister_controller(struct slim_controller *ctrl);
107
108#endif /* _LINUX_SLIMBUS_H */