1*4882a593Smuzhiyun // SPDX-License-Identifier: GPL-2.0
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun * Driver for Intel MSIC
4*4882a593Smuzhiyun *
5*4882a593Smuzhiyun * Copyright (C) 2011, Intel Corporation
6*4882a593Smuzhiyun * Author: Mika Westerberg <mika.westerberg@linux.intel.com>
7*4882a593Smuzhiyun */
8*4882a593Smuzhiyun
9*4882a593Smuzhiyun #include <linux/err.h>
10*4882a593Smuzhiyun #include <linux/gpio.h>
11*4882a593Smuzhiyun #include <linux/io.h>
12*4882a593Smuzhiyun #include <linux/init.h>
13*4882a593Smuzhiyun #include <linux/mfd/core.h>
14*4882a593Smuzhiyun #include <linux/mfd/intel_msic.h>
15*4882a593Smuzhiyun #include <linux/platform_device.h>
16*4882a593Smuzhiyun #include <linux/slab.h>
17*4882a593Smuzhiyun
18*4882a593Smuzhiyun #include <asm/intel_scu_ipc.h>
19*4882a593Smuzhiyun
20*4882a593Smuzhiyun #define MSIC_VENDOR(id) ((id >> 6) & 3)
21*4882a593Smuzhiyun #define MSIC_VERSION(id) (id & 0x3f)
22*4882a593Smuzhiyun #define MSIC_MAJOR(id) ('A' + ((id >> 3) & 7))
23*4882a593Smuzhiyun #define MSIC_MINOR(id) (id & 7)
24*4882a593Smuzhiyun
25*4882a593Smuzhiyun /*
26*4882a593Smuzhiyun * MSIC interrupt tree is readable from SRAM at INTEL_MSIC_IRQ_PHYS_BASE.
27*4882a593Smuzhiyun * Since IRQ block starts from address 0x002 we need to subtract that from
28*4882a593Smuzhiyun * the actual IRQ status register address.
29*4882a593Smuzhiyun */
30*4882a593Smuzhiyun #define MSIC_IRQ_STATUS(x) (INTEL_MSIC_IRQ_PHYS_BASE + ((x) - 2))
31*4882a593Smuzhiyun #define MSIC_IRQ_STATUS_ACCDET MSIC_IRQ_STATUS(INTEL_MSIC_ACCDET)
32*4882a593Smuzhiyun
33*4882a593Smuzhiyun /*
34*4882a593Smuzhiyun * The SCU hardware has limitation of 16 bytes per read/write buffer on
35*4882a593Smuzhiyun * Medfield.
36*4882a593Smuzhiyun */
37*4882a593Smuzhiyun #define SCU_IPC_RWBUF_LIMIT 16
38*4882a593Smuzhiyun
39*4882a593Smuzhiyun /**
40*4882a593Smuzhiyun * struct intel_msic - an MSIC MFD instance
41*4882a593Smuzhiyun * @pdev: pointer to the platform device
42*4882a593Smuzhiyun * @vendor: vendor ID
43*4882a593Smuzhiyun * @version: chip version
44*4882a593Smuzhiyun * @irq_base: base address of the mapped MSIC SRAM interrupt tree
45*4882a593Smuzhiyun */
46*4882a593Smuzhiyun struct intel_msic {
47*4882a593Smuzhiyun struct platform_device *pdev;
48*4882a593Smuzhiyun unsigned vendor;
49*4882a593Smuzhiyun unsigned version;
50*4882a593Smuzhiyun void __iomem *irq_base;
51*4882a593Smuzhiyun };
52*4882a593Smuzhiyun
53*4882a593Smuzhiyun static struct resource msic_touch_resources[] = {
54*4882a593Smuzhiyun DEFINE_RES_IRQ(0),
55*4882a593Smuzhiyun };
56*4882a593Smuzhiyun
57*4882a593Smuzhiyun static struct resource msic_adc_resources[] = {
58*4882a593Smuzhiyun DEFINE_RES_IRQ(0),
59*4882a593Smuzhiyun };
60*4882a593Smuzhiyun
61*4882a593Smuzhiyun static struct resource msic_battery_resources[] = {
62*4882a593Smuzhiyun DEFINE_RES_IRQ(0),
63*4882a593Smuzhiyun };
64*4882a593Smuzhiyun
65*4882a593Smuzhiyun static struct resource msic_gpio_resources[] = {
66*4882a593Smuzhiyun DEFINE_RES_IRQ(0),
67*4882a593Smuzhiyun };
68*4882a593Smuzhiyun
69*4882a593Smuzhiyun static struct resource msic_audio_resources[] = {
70*4882a593Smuzhiyun DEFINE_RES_IRQ_NAMED(0, "IRQ"),
71*4882a593Smuzhiyun /*
72*4882a593Smuzhiyun * We will pass IRQ_BASE to the driver now but this can be removed
73*4882a593Smuzhiyun * when/if the driver starts to use intel_msic_irq_read().
74*4882a593Smuzhiyun */
75*4882a593Smuzhiyun DEFINE_RES_MEM_NAMED(MSIC_IRQ_STATUS_ACCDET, 1, "IRQ_BASE"),
76*4882a593Smuzhiyun };
77*4882a593Smuzhiyun
78*4882a593Smuzhiyun static struct resource msic_hdmi_resources[] = {
79*4882a593Smuzhiyun DEFINE_RES_IRQ(0),
80*4882a593Smuzhiyun };
81*4882a593Smuzhiyun
82*4882a593Smuzhiyun static struct resource msic_thermal_resources[] = {
83*4882a593Smuzhiyun DEFINE_RES_IRQ(0),
84*4882a593Smuzhiyun };
85*4882a593Smuzhiyun
86*4882a593Smuzhiyun static struct resource msic_power_btn_resources[] = {
87*4882a593Smuzhiyun DEFINE_RES_IRQ(0),
88*4882a593Smuzhiyun };
89*4882a593Smuzhiyun
90*4882a593Smuzhiyun static struct resource msic_ocd_resources[] = {
91*4882a593Smuzhiyun DEFINE_RES_IRQ(0),
92*4882a593Smuzhiyun };
93*4882a593Smuzhiyun
94*4882a593Smuzhiyun /*
95*4882a593Smuzhiyun * Devices that are part of the MSIC and are available via firmware
96*4882a593Smuzhiyun * populated SFI DEVS table.
97*4882a593Smuzhiyun */
98*4882a593Smuzhiyun static struct mfd_cell msic_devs[] = {
99*4882a593Smuzhiyun [INTEL_MSIC_BLOCK_TOUCH] = {
100*4882a593Smuzhiyun .name = "msic_touch",
101*4882a593Smuzhiyun .num_resources = ARRAY_SIZE(msic_touch_resources),
102*4882a593Smuzhiyun .resources = msic_touch_resources,
103*4882a593Smuzhiyun },
104*4882a593Smuzhiyun [INTEL_MSIC_BLOCK_ADC] = {
105*4882a593Smuzhiyun .name = "msic_adc",
106*4882a593Smuzhiyun .num_resources = ARRAY_SIZE(msic_adc_resources),
107*4882a593Smuzhiyun .resources = msic_adc_resources,
108*4882a593Smuzhiyun },
109*4882a593Smuzhiyun [INTEL_MSIC_BLOCK_BATTERY] = {
110*4882a593Smuzhiyun .name = "msic_battery",
111*4882a593Smuzhiyun .num_resources = ARRAY_SIZE(msic_battery_resources),
112*4882a593Smuzhiyun .resources = msic_battery_resources,
113*4882a593Smuzhiyun },
114*4882a593Smuzhiyun [INTEL_MSIC_BLOCK_GPIO] = {
115*4882a593Smuzhiyun .name = "msic_gpio",
116*4882a593Smuzhiyun .num_resources = ARRAY_SIZE(msic_gpio_resources),
117*4882a593Smuzhiyun .resources = msic_gpio_resources,
118*4882a593Smuzhiyun },
119*4882a593Smuzhiyun [INTEL_MSIC_BLOCK_AUDIO] = {
120*4882a593Smuzhiyun .name = "msic_audio",
121*4882a593Smuzhiyun .num_resources = ARRAY_SIZE(msic_audio_resources),
122*4882a593Smuzhiyun .resources = msic_audio_resources,
123*4882a593Smuzhiyun },
124*4882a593Smuzhiyun [INTEL_MSIC_BLOCK_HDMI] = {
125*4882a593Smuzhiyun .name = "msic_hdmi",
126*4882a593Smuzhiyun .num_resources = ARRAY_SIZE(msic_hdmi_resources),
127*4882a593Smuzhiyun .resources = msic_hdmi_resources,
128*4882a593Smuzhiyun },
129*4882a593Smuzhiyun [INTEL_MSIC_BLOCK_THERMAL] = {
130*4882a593Smuzhiyun .name = "msic_thermal",
131*4882a593Smuzhiyun .num_resources = ARRAY_SIZE(msic_thermal_resources),
132*4882a593Smuzhiyun .resources = msic_thermal_resources,
133*4882a593Smuzhiyun },
134*4882a593Smuzhiyun [INTEL_MSIC_BLOCK_POWER_BTN] = {
135*4882a593Smuzhiyun .name = "msic_power_btn",
136*4882a593Smuzhiyun .num_resources = ARRAY_SIZE(msic_power_btn_resources),
137*4882a593Smuzhiyun .resources = msic_power_btn_resources,
138*4882a593Smuzhiyun },
139*4882a593Smuzhiyun [INTEL_MSIC_BLOCK_OCD] = {
140*4882a593Smuzhiyun .name = "msic_ocd",
141*4882a593Smuzhiyun .num_resources = ARRAY_SIZE(msic_ocd_resources),
142*4882a593Smuzhiyun .resources = msic_ocd_resources,
143*4882a593Smuzhiyun },
144*4882a593Smuzhiyun };
145*4882a593Smuzhiyun
146*4882a593Smuzhiyun /*
147*4882a593Smuzhiyun * Other MSIC related devices which are not directly available via SFI DEVS
148*4882a593Smuzhiyun * table. These can be pseudo devices, regulators etc. which are needed for
149*4882a593Smuzhiyun * different purposes.
150*4882a593Smuzhiyun *
151*4882a593Smuzhiyun * These devices appear only after the MSIC driver itself is initialized so
152*4882a593Smuzhiyun * we can guarantee that the SCU IPC interface is ready.
153*4882a593Smuzhiyun */
154*4882a593Smuzhiyun static const struct mfd_cell msic_other_devs[] = {
155*4882a593Smuzhiyun /* Audio codec in the MSIC */
156*4882a593Smuzhiyun {
157*4882a593Smuzhiyun .id = -1,
158*4882a593Smuzhiyun .name = "sn95031",
159*4882a593Smuzhiyun },
160*4882a593Smuzhiyun };
161*4882a593Smuzhiyun
162*4882a593Smuzhiyun /**
163*4882a593Smuzhiyun * intel_msic_reg_read - read a single MSIC register
164*4882a593Smuzhiyun * @reg: register to read
165*4882a593Smuzhiyun * @val: register value is placed here
166*4882a593Smuzhiyun *
167*4882a593Smuzhiyun * Read a single register from MSIC. Returns %0 on success and negative
168*4882a593Smuzhiyun * errno in case of failure.
169*4882a593Smuzhiyun *
170*4882a593Smuzhiyun * Function may sleep.
171*4882a593Smuzhiyun */
intel_msic_reg_read(unsigned short reg,u8 * val)172*4882a593Smuzhiyun int intel_msic_reg_read(unsigned short reg, u8 *val)
173*4882a593Smuzhiyun {
174*4882a593Smuzhiyun return intel_scu_ipc_ioread8(reg, val);
175*4882a593Smuzhiyun }
176*4882a593Smuzhiyun EXPORT_SYMBOL_GPL(intel_msic_reg_read);
177*4882a593Smuzhiyun
178*4882a593Smuzhiyun /**
179*4882a593Smuzhiyun * intel_msic_reg_write - write a single MSIC register
180*4882a593Smuzhiyun * @reg: register to write
181*4882a593Smuzhiyun * @val: value to write to that register
182*4882a593Smuzhiyun *
183*4882a593Smuzhiyun * Write a single MSIC register. Returns 0 on success and negative
184*4882a593Smuzhiyun * errno in case of failure.
185*4882a593Smuzhiyun *
186*4882a593Smuzhiyun * Function may sleep.
187*4882a593Smuzhiyun */
intel_msic_reg_write(unsigned short reg,u8 val)188*4882a593Smuzhiyun int intel_msic_reg_write(unsigned short reg, u8 val)
189*4882a593Smuzhiyun {
190*4882a593Smuzhiyun return intel_scu_ipc_iowrite8(reg, val);
191*4882a593Smuzhiyun }
192*4882a593Smuzhiyun EXPORT_SYMBOL_GPL(intel_msic_reg_write);
193*4882a593Smuzhiyun
194*4882a593Smuzhiyun /**
195*4882a593Smuzhiyun * intel_msic_reg_update - update a single MSIC register
196*4882a593Smuzhiyun * @reg: register to update
197*4882a593Smuzhiyun * @val: value to write to the register
198*4882a593Smuzhiyun * @mask: specifies which of the bits are updated (%0 = don't update,
199*4882a593Smuzhiyun * %1 = update)
200*4882a593Smuzhiyun *
201*4882a593Smuzhiyun * Perform an update to a register @reg. @mask is used to specify which
202*4882a593Smuzhiyun * bits are updated. Returns %0 in case of success and negative errno in
203*4882a593Smuzhiyun * case of failure.
204*4882a593Smuzhiyun *
205*4882a593Smuzhiyun * Function may sleep.
206*4882a593Smuzhiyun */
intel_msic_reg_update(unsigned short reg,u8 val,u8 mask)207*4882a593Smuzhiyun int intel_msic_reg_update(unsigned short reg, u8 val, u8 mask)
208*4882a593Smuzhiyun {
209*4882a593Smuzhiyun return intel_scu_ipc_update_register(reg, val, mask);
210*4882a593Smuzhiyun }
211*4882a593Smuzhiyun EXPORT_SYMBOL_GPL(intel_msic_reg_update);
212*4882a593Smuzhiyun
213*4882a593Smuzhiyun /**
214*4882a593Smuzhiyun * intel_msic_bulk_read - read an array of registers
215*4882a593Smuzhiyun * @reg: array of register addresses to read
216*4882a593Smuzhiyun * @buf: array where the read values are placed
217*4882a593Smuzhiyun * @count: number of registers to read
218*4882a593Smuzhiyun *
219*4882a593Smuzhiyun * Function reads @count registers from the MSIC using addresses passed in
220*4882a593Smuzhiyun * @reg. Read values are placed in @buf. Reads are performed atomically
221*4882a593Smuzhiyun * wrt. MSIC.
222*4882a593Smuzhiyun *
223*4882a593Smuzhiyun * Returns %0 in case of success and negative errno in case of failure.
224*4882a593Smuzhiyun *
225*4882a593Smuzhiyun * Function may sleep.
226*4882a593Smuzhiyun */
intel_msic_bulk_read(unsigned short * reg,u8 * buf,size_t count)227*4882a593Smuzhiyun int intel_msic_bulk_read(unsigned short *reg, u8 *buf, size_t count)
228*4882a593Smuzhiyun {
229*4882a593Smuzhiyun if (WARN_ON(count > SCU_IPC_RWBUF_LIMIT))
230*4882a593Smuzhiyun return -EINVAL;
231*4882a593Smuzhiyun
232*4882a593Smuzhiyun return intel_scu_ipc_readv(reg, buf, count);
233*4882a593Smuzhiyun }
234*4882a593Smuzhiyun EXPORT_SYMBOL_GPL(intel_msic_bulk_read);
235*4882a593Smuzhiyun
236*4882a593Smuzhiyun /**
237*4882a593Smuzhiyun * intel_msic_bulk_write - write an array of values to the MSIC registers
238*4882a593Smuzhiyun * @reg: array of registers to write
239*4882a593Smuzhiyun * @buf: values to write to each register
240*4882a593Smuzhiyun * @count: number of registers to write
241*4882a593Smuzhiyun *
242*4882a593Smuzhiyun * Function writes @count registers in @buf to MSIC. Writes are performed
243*4882a593Smuzhiyun * atomically wrt MSIC. Returns %0 in case of success and negative errno in
244*4882a593Smuzhiyun * case of failure.
245*4882a593Smuzhiyun *
246*4882a593Smuzhiyun * Function may sleep.
247*4882a593Smuzhiyun */
intel_msic_bulk_write(unsigned short * reg,u8 * buf,size_t count)248*4882a593Smuzhiyun int intel_msic_bulk_write(unsigned short *reg, u8 *buf, size_t count)
249*4882a593Smuzhiyun {
250*4882a593Smuzhiyun if (WARN_ON(count > SCU_IPC_RWBUF_LIMIT))
251*4882a593Smuzhiyun return -EINVAL;
252*4882a593Smuzhiyun
253*4882a593Smuzhiyun return intel_scu_ipc_writev(reg, buf, count);
254*4882a593Smuzhiyun }
255*4882a593Smuzhiyun EXPORT_SYMBOL_GPL(intel_msic_bulk_write);
256*4882a593Smuzhiyun
257*4882a593Smuzhiyun /**
258*4882a593Smuzhiyun * intel_msic_irq_read - read a register from an MSIC interrupt tree
259*4882a593Smuzhiyun * @msic: MSIC instance
260*4882a593Smuzhiyun * @reg: interrupt register (between %INTEL_MSIC_IRQLVL1 and
261*4882a593Smuzhiyun * %INTEL_MSIC_RESETIRQ2)
262*4882a593Smuzhiyun * @val: value of the register is placed here
263*4882a593Smuzhiyun *
264*4882a593Smuzhiyun * This function can be used by an MSIC subdevice interrupt handler to read
265*4882a593Smuzhiyun * a register value from the MSIC interrupt tree. In this way subdevice
266*4882a593Smuzhiyun * drivers don't have to map in the interrupt tree themselves but can just
267*4882a593Smuzhiyun * call this function instead.
268*4882a593Smuzhiyun *
269*4882a593Smuzhiyun * Function doesn't sleep and is callable from interrupt context.
270*4882a593Smuzhiyun *
271*4882a593Smuzhiyun * Returns %-EINVAL if @reg is outside of the allowed register region.
272*4882a593Smuzhiyun */
intel_msic_irq_read(struct intel_msic * msic,unsigned short reg,u8 * val)273*4882a593Smuzhiyun int intel_msic_irq_read(struct intel_msic *msic, unsigned short reg, u8 *val)
274*4882a593Smuzhiyun {
275*4882a593Smuzhiyun if (WARN_ON(reg < INTEL_MSIC_IRQLVL1 || reg > INTEL_MSIC_RESETIRQ2))
276*4882a593Smuzhiyun return -EINVAL;
277*4882a593Smuzhiyun
278*4882a593Smuzhiyun *val = readb(msic->irq_base + (reg - INTEL_MSIC_IRQLVL1));
279*4882a593Smuzhiyun return 0;
280*4882a593Smuzhiyun }
281*4882a593Smuzhiyun EXPORT_SYMBOL_GPL(intel_msic_irq_read);
282*4882a593Smuzhiyun
intel_msic_init_devices(struct intel_msic * msic)283*4882a593Smuzhiyun static int intel_msic_init_devices(struct intel_msic *msic)
284*4882a593Smuzhiyun {
285*4882a593Smuzhiyun struct platform_device *pdev = msic->pdev;
286*4882a593Smuzhiyun struct intel_msic_platform_data *pdata = dev_get_platdata(&pdev->dev);
287*4882a593Smuzhiyun int ret, i;
288*4882a593Smuzhiyun
289*4882a593Smuzhiyun if (pdata->gpio) {
290*4882a593Smuzhiyun struct mfd_cell *cell = &msic_devs[INTEL_MSIC_BLOCK_GPIO];
291*4882a593Smuzhiyun
292*4882a593Smuzhiyun cell->platform_data = pdata->gpio;
293*4882a593Smuzhiyun cell->pdata_size = sizeof(*pdata->gpio);
294*4882a593Smuzhiyun }
295*4882a593Smuzhiyun
296*4882a593Smuzhiyun if (pdata->ocd) {
297*4882a593Smuzhiyun unsigned gpio = pdata->ocd->gpio;
298*4882a593Smuzhiyun
299*4882a593Smuzhiyun ret = devm_gpio_request_one(&pdev->dev, gpio,
300*4882a593Smuzhiyun GPIOF_IN, "ocd_gpio");
301*4882a593Smuzhiyun if (ret) {
302*4882a593Smuzhiyun dev_err(&pdev->dev, "failed to register OCD GPIO\n");
303*4882a593Smuzhiyun return ret;
304*4882a593Smuzhiyun }
305*4882a593Smuzhiyun
306*4882a593Smuzhiyun ret = gpio_to_irq(gpio);
307*4882a593Smuzhiyun if (ret < 0) {
308*4882a593Smuzhiyun dev_err(&pdev->dev, "no IRQ number for OCD GPIO\n");
309*4882a593Smuzhiyun return ret;
310*4882a593Smuzhiyun }
311*4882a593Smuzhiyun
312*4882a593Smuzhiyun /* Update the IRQ number for the OCD */
313*4882a593Smuzhiyun pdata->irq[INTEL_MSIC_BLOCK_OCD] = ret;
314*4882a593Smuzhiyun }
315*4882a593Smuzhiyun
316*4882a593Smuzhiyun for (i = 0; i < ARRAY_SIZE(msic_devs); i++) {
317*4882a593Smuzhiyun if (!pdata->irq[i])
318*4882a593Smuzhiyun continue;
319*4882a593Smuzhiyun
320*4882a593Smuzhiyun ret = mfd_add_devices(&pdev->dev, -1, &msic_devs[i], 1, NULL,
321*4882a593Smuzhiyun pdata->irq[i], NULL);
322*4882a593Smuzhiyun if (ret)
323*4882a593Smuzhiyun goto fail;
324*4882a593Smuzhiyun }
325*4882a593Smuzhiyun
326*4882a593Smuzhiyun ret = mfd_add_devices(&pdev->dev, 0, msic_other_devs,
327*4882a593Smuzhiyun ARRAY_SIZE(msic_other_devs), NULL, 0, NULL);
328*4882a593Smuzhiyun if (ret)
329*4882a593Smuzhiyun goto fail;
330*4882a593Smuzhiyun
331*4882a593Smuzhiyun return 0;
332*4882a593Smuzhiyun
333*4882a593Smuzhiyun fail:
334*4882a593Smuzhiyun mfd_remove_devices(&pdev->dev);
335*4882a593Smuzhiyun
336*4882a593Smuzhiyun return ret;
337*4882a593Smuzhiyun }
338*4882a593Smuzhiyun
intel_msic_remove_devices(struct intel_msic * msic)339*4882a593Smuzhiyun static void intel_msic_remove_devices(struct intel_msic *msic)
340*4882a593Smuzhiyun {
341*4882a593Smuzhiyun struct platform_device *pdev = msic->pdev;
342*4882a593Smuzhiyun
343*4882a593Smuzhiyun mfd_remove_devices(&pdev->dev);
344*4882a593Smuzhiyun }
345*4882a593Smuzhiyun
intel_msic_probe(struct platform_device * pdev)346*4882a593Smuzhiyun static int intel_msic_probe(struct platform_device *pdev)
347*4882a593Smuzhiyun {
348*4882a593Smuzhiyun struct intel_msic_platform_data *pdata = dev_get_platdata(&pdev->dev);
349*4882a593Smuzhiyun struct intel_msic *msic;
350*4882a593Smuzhiyun struct resource *res;
351*4882a593Smuzhiyun u8 id0, id1;
352*4882a593Smuzhiyun int ret;
353*4882a593Smuzhiyun
354*4882a593Smuzhiyun if (!pdata) {
355*4882a593Smuzhiyun dev_err(&pdev->dev, "no platform data passed\n");
356*4882a593Smuzhiyun return -EINVAL;
357*4882a593Smuzhiyun }
358*4882a593Smuzhiyun
359*4882a593Smuzhiyun /* First validate that we have an MSIC in place */
360*4882a593Smuzhiyun ret = intel_scu_ipc_ioread8(INTEL_MSIC_ID0, &id0);
361*4882a593Smuzhiyun if (ret) {
362*4882a593Smuzhiyun dev_err(&pdev->dev, "failed to identify the MSIC chip (ID0)\n");
363*4882a593Smuzhiyun return -ENXIO;
364*4882a593Smuzhiyun }
365*4882a593Smuzhiyun
366*4882a593Smuzhiyun ret = intel_scu_ipc_ioread8(INTEL_MSIC_ID1, &id1);
367*4882a593Smuzhiyun if (ret) {
368*4882a593Smuzhiyun dev_err(&pdev->dev, "failed to identify the MSIC chip (ID1)\n");
369*4882a593Smuzhiyun return -ENXIO;
370*4882a593Smuzhiyun }
371*4882a593Smuzhiyun
372*4882a593Smuzhiyun if (MSIC_VENDOR(id0) != MSIC_VENDOR(id1)) {
373*4882a593Smuzhiyun dev_err(&pdev->dev, "invalid vendor ID: %x, %x\n", id0, id1);
374*4882a593Smuzhiyun return -ENXIO;
375*4882a593Smuzhiyun }
376*4882a593Smuzhiyun
377*4882a593Smuzhiyun msic = devm_kzalloc(&pdev->dev, sizeof(*msic), GFP_KERNEL);
378*4882a593Smuzhiyun if (!msic)
379*4882a593Smuzhiyun return -ENOMEM;
380*4882a593Smuzhiyun
381*4882a593Smuzhiyun msic->vendor = MSIC_VENDOR(id0);
382*4882a593Smuzhiyun msic->version = MSIC_VERSION(id0);
383*4882a593Smuzhiyun msic->pdev = pdev;
384*4882a593Smuzhiyun
385*4882a593Smuzhiyun /*
386*4882a593Smuzhiyun * Map in the MSIC interrupt tree area in SRAM. This is exposed to
387*4882a593Smuzhiyun * the clients via intel_msic_irq_read().
388*4882a593Smuzhiyun */
389*4882a593Smuzhiyun res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
390*4882a593Smuzhiyun msic->irq_base = devm_ioremap_resource(&pdev->dev, res);
391*4882a593Smuzhiyun if (IS_ERR(msic->irq_base))
392*4882a593Smuzhiyun return PTR_ERR(msic->irq_base);
393*4882a593Smuzhiyun
394*4882a593Smuzhiyun platform_set_drvdata(pdev, msic);
395*4882a593Smuzhiyun
396*4882a593Smuzhiyun ret = intel_msic_init_devices(msic);
397*4882a593Smuzhiyun if (ret) {
398*4882a593Smuzhiyun dev_err(&pdev->dev, "failed to initialize MSIC devices\n");
399*4882a593Smuzhiyun return ret;
400*4882a593Smuzhiyun }
401*4882a593Smuzhiyun
402*4882a593Smuzhiyun dev_info(&pdev->dev, "Intel MSIC version %c%d (vendor %#x)\n",
403*4882a593Smuzhiyun MSIC_MAJOR(msic->version), MSIC_MINOR(msic->version),
404*4882a593Smuzhiyun msic->vendor);
405*4882a593Smuzhiyun
406*4882a593Smuzhiyun return 0;
407*4882a593Smuzhiyun }
408*4882a593Smuzhiyun
intel_msic_remove(struct platform_device * pdev)409*4882a593Smuzhiyun static int intel_msic_remove(struct platform_device *pdev)
410*4882a593Smuzhiyun {
411*4882a593Smuzhiyun struct intel_msic *msic = platform_get_drvdata(pdev);
412*4882a593Smuzhiyun
413*4882a593Smuzhiyun intel_msic_remove_devices(msic);
414*4882a593Smuzhiyun
415*4882a593Smuzhiyun return 0;
416*4882a593Smuzhiyun }
417*4882a593Smuzhiyun
418*4882a593Smuzhiyun static struct platform_driver intel_msic_driver = {
419*4882a593Smuzhiyun .probe = intel_msic_probe,
420*4882a593Smuzhiyun .remove = intel_msic_remove,
421*4882a593Smuzhiyun .driver = {
422*4882a593Smuzhiyun .name = "intel_msic",
423*4882a593Smuzhiyun },
424*4882a593Smuzhiyun };
425*4882a593Smuzhiyun builtin_platform_driver(intel_msic_driver);
426